Skip to content

Check if your transactions are being closed at every code path

License

Notifications You must be signed in to change notification settings

luanraithz/eslint-plugin-sequelize-closed-transaction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Eslint plugin sequelize closed transaction

Check if your transactions are closed at every path

npm install --saved-dev eslint-plugin-sequelize-transaction

Most of the code here is from rules of hooks source code

Valid code examples ✅

async function simple() {
  const transaction = await sequelize.transaction();
  if (false) {
    await transaction.rollback()
    return
  }
  await transaction.rollback()
}`,
async function withTryAndFinally() {
  const transaction = await sequelize.transaction();
  try {
    return 1
  } catch (err) {
    console.error()
  } finally {
    await transaction.rollback()
  }
}
async function nested() {
  const transaction = await sequelize.transaction();
  {
    {
      {
        await transaction.rollback()
      }
    }
  }
}
async function ifElse() {
  const transaction = await sequelize.transaction();
  if (123) {
    await transaction.rollback()
    return bla
  } else {
    await transaction.rollback()
  }
}
const obj = {
  property: async () => {
    const transaction = await sequelize.transaction();
    if (123) {
      await transaction.rollback()
      return bla
    } else {
      await transaction.rollback()
    }
  }
}

Example of invalid code

async function nestedStatements() {
  let transaction = await sequelize.transaction();
  if (3 > 2) {
    if (4 > 2) {
      return 1
    }
    await transaction.rollback()
  }
  await transaction.rollback()
}
async function noNesting() {
  const transaction = await sequelize.transaction();

  return await 1
}
const obj = {
  func: async function () {
    const transaction = await sequelize.transaction();

    return await 1
  }
}
const obj = {
  arrow: async () => {
    const transaction = await sequelize.transaction();

    return await 1
  }
}

About

Check if your transactions are being closed at every code path

Topics

Resources

License

Stars

Watchers

Forks