From eeafcc939bff02b4ca033187425217c5e2ca2cf5 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sat, 9 Sep 2023 06:38:56 +1200 Subject: [PATCH] chore: enforce curly braces (#1429) * chore: enforce curly braces * refactor: apply eslint fixes --- .eslintrc.js | 1 + src/rules/expect-expect.ts | 4 +++- src/rules/no-test-return-statement.ts | 12 +++++++++--- src/rules/no-untyped-mock-factory.ts | 4 +++- src/rules/prefer-spy-on.ts | 8 ++++++-- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index a7b0157f7..0087df020 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -84,6 +84,7 @@ module.exports = { 'prefer-rest-params': 'error', 'prefer-const': ['error', { destructuring: 'all' }], 'no-var': 'error', + curly: 'error', }, overrides: [ { diff --git a/src/rules/expect-expect.ts b/src/rules/expect-expect.ts index 5a6b416b0..d79e6879a 100644 --- a/src/rules/expect-expect.ts +++ b/src/rules/expect-expect.ts @@ -28,7 +28,9 @@ function matchesAssertFunctionName( `^${p .split('.') .map(x => { - if (x === '**') return '[a-z\\d\\.]*'; + if (x === '**') { + return '[a-z\\d\\.]*'; + } return x.replace(/\*/gu, '[a-z\\d]*'); }) diff --git a/src/rules/no-test-return-statement.ts b/src/rules/no-test-return-statement.ts index 1406b5586..9e179ee05 100644 --- a/src/rules/no-test-return-statement.ts +++ b/src/rules/no-test-return-statement.ts @@ -47,7 +47,9 @@ export default createRule({ t => t.type === AST_NODE_TYPES.ReturnStatement, ); - if (!returnStmt) return; + if (!returnStmt) { + return; + } context.report({ messageId: 'noReturnValue', node: returnStmt }); }, @@ -58,13 +60,17 @@ export default createRule({ context, ); - if (testCallExpressions.length === 0) return; + if (testCallExpressions.length === 0) { + return; + } const returnStmt = node.body.body.find( t => t.type === AST_NODE_TYPES.ReturnStatement, ); - if (!returnStmt) return; + if (!returnStmt) { + return; + } context.report({ messageId: 'noReturnValue', node: returnStmt }); }, diff --git a/src/rules/no-untyped-mock-factory.ts b/src/rules/no-untyped-mock-factory.ts index 1d9767833..a3abe55cc 100644 --- a/src/rules/no-untyped-mock-factory.ts +++ b/src/rules/no-untyped-mock-factory.ts @@ -70,7 +70,9 @@ export default createRule({ data: { moduleName: moduleName?.raw ?? './module-name' }, node, fix(fixer) { - if (!moduleName) return []; + if (!moduleName) { + return []; + } return [ fixer.insertTextAfter( diff --git a/src/rules/prefer-spy-on.ts b/src/rules/prefer-spy-on.ts index c67322259..545938edd 100644 --- a/src/rules/prefer-spy-on.ts +++ b/src/rules/prefer-spy-on.ts @@ -85,11 +85,15 @@ export default createRule({ AssignmentExpression(node) { const { left, right } = node; - if (left.type !== AST_NODE_TYPES.MemberExpression) return; + if (left.type !== AST_NODE_TYPES.MemberExpression) { + return; + } const jestFnCall = getJestFnCall(right); - if (!jestFnCall) return; + if (!jestFnCall) { + return; + } context.report({ node,