From 99f37b5da5713994f0a7e9eceac4c26d0da38234 Mon Sep 17 00:00:00 2001 From: Ben Zhang Date: Tue, 7 May 2024 10:53:56 -0700 Subject: [PATCH] lint fix --- .vscode/launch.json | 2 +- jest.config.js | 2 +- lib/rules/enforce-foo-bar.ts | 24 +++++++++++------------- package.json | 4 ++-- test/lib/rules/enforce-foo-bar.ts | 10 +++++----- tsconfig.json | 30 +++++++++++++++--------------- 6 files changed, 35 insertions(+), 37 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index b37442a..fdbd9ae 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -17,4 +17,4 @@ "internalConsoleOptions": "neverOpen" } ] -} \ No newline at end of file +} diff --git a/jest.config.js b/jest.config.js index 9955943..628fa3f 100644 --- a/jest.config.js +++ b/jest.config.js @@ -10,7 +10,7 @@ module.exports = { displayName: 'Unit Tests', setupFilesAfterEnv: ['jest-extended', 'jest-chain'], - preset: "ts-jest", + preset: 'ts-jest', testMatch: [ '/test/plugin.ts', '/test/lib/rules/**/*.ts', diff --git a/lib/rules/enforce-foo-bar.ts b/lib/rules/enforce-foo-bar.ts index 79ff08b..213ecd5 100644 --- a/lib/rules/enforce-foo-bar.ts +++ b/lib/rules/enforce-foo-bar.ts @@ -7,7 +7,8 @@ const ruleEnforceFoorBar: TSESLint.RuleModule = { meta: { type: 'problem', messages: { - messageIdForFooMustBeBar: 'Value other than "bar" assigned to `const foo`. Unexpected value: {{ notBar }}.', + messageIdForFooMustBeBar: + 'Value other than "bar" assigned to `const foo`. Unexpected value: {{ notBar }}.' }, fixable: 'code', schema: [] @@ -19,17 +20,14 @@ const ruleEnforceFoorBar: TSESLint.RuleModule = { // Check if variable name is `foo` if (node.id.type === AST_NODE_TYPES.Identifier && node.id.name === 'foo') { // Check if value of variable is "bar" - if ( - node.init?.type === AST_NODE_TYPES.Literal && - node.init?.value !== 'bar' - ) { + if (node.init?.type === AST_NODE_TYPES.Literal && node.init?.value !== 'bar') { /* - * Report error to ESLint. Error message uses - * a message placeholder to include the incorrect value - * in the error message. - * Also includes a `fix(fixer)` function that replaces - * any values assigned to `const foo` with "bar". - */ + * Report error to ESLint. Error message uses + * a message placeholder to include the incorrect value + * in the error message. + * Also includes a `fix(fixer)` function that replaces + * any values assigned to `const foo` with "bar". + */ context.report({ node, messageId: 'messageIdForFooMustBeBar', @@ -45,6 +43,6 @@ const ruleEnforceFoorBar: TSESLint.RuleModule = { } } }) -} +}; -export default ruleEnforceFoorBar; \ No newline at end of file +export default ruleEnforceFoorBar; diff --git a/package.json b/package.json index a1501df..0eed90e 100644 --- a/package.json +++ b/package.json @@ -31,8 +31,8 @@ "url": "https://github.com/salesforce/eslint-plugin-lwc-mobile" }, "scripts": { - "format": "prettier --list-different \"**/*.js\"", - "format:fix": "prettier --write \"**/*.{js,json}\"", + "format": "prettier --list-different \"**/*.{ts,js}\"", + "format:fix": "prettier --write \"**/*.{ts,js,json}\"", "lint": "eslint lib test", "test": "jest --coverage" }, diff --git a/test/lib/rules/enforce-foo-bar.ts b/test/lib/rules/enforce-foo-bar.ts index ecbe15d..0b1b4de 100644 --- a/test/lib/rules/enforce-foo-bar.ts +++ b/test/lib/rules/enforce-foo-bar.ts @@ -1,6 +1,6 @@ -import { RuleTester } from "@typescript-eslint/rule-tester"; +import { RuleTester } from '@typescript-eslint/rule-tester'; -import ruleEnforceFoorBar from "../../../lib/rules/enforce-foo-bar"; +import ruleEnforceFoorBar from '../../../lib/rules/enforce-foo-bar'; const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser' @@ -16,7 +16,7 @@ ruleTester.run('@salesforce/lwc-mobile/enforce-foo-bar', ruleEnforceFoorBar, { { code: "const foo = 'baz';", output: 'const foo = "bar";', - errors: [{messageId: 'messageIdForFooMustBeBar'}] + errors: [{ messageId: 'messageIdForFooMustBeBar' }] } - ], -}); \ No newline at end of file + ] +}); diff --git a/tsconfig.json b/tsconfig.json index 055309f..5030918 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,18 +1,18 @@ { "compilerOptions": { - "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ - "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ - "module": "Node16", /* Specify what module code is generated. */ - "rootDir": "src", /* Specify the root folder within your source files. */ - "moduleResolution": "Node16", /* Specify how TypeScript looks up a file from a given module specifier. */ - "types": [], /* Specify type package names to be included without being referenced in a source file. */ - "outDir": "dist", /* Specify an output folder for all emitted files. */ - "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ - "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ - "strict": true, /* Enable all strict type-checking options. */ - "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ - "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ - "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ - "skipLibCheck": true /* Skip type checking all .d.ts files. */ + "composite": true /* Enable constraints that allow a TypeScript project to be used with project references. */, + "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, + "module": "Node16" /* Specify what module code is generated. */, + "rootDir": "src" /* Specify the root folder within your source files. */, + "moduleResolution": "Node16" /* Specify how TypeScript looks up a file from a given module specifier. */, + "types": [] /* Specify type package names to be included without being referenced in a source file. */, + "outDir": "dist" /* Specify an output folder for all emitted files. */, + "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */, + "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, + "strict": true /* Enable all strict type-checking options. */, + "noUnusedLocals": true /* Enable error reporting when local variables aren't read. */, + "noUnusedParameters": true /* Raise an error when a function parameter isn't read. */, + "noImplicitReturns": true /* Enable error reporting for codepaths that do not explicitly return in a function. */, + "skipLibCheck": true /* Skip type checking all .d.ts files. */ } - } \ No newline at end of file +}