Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-zhang-at-salesforce committed May 7, 2024
1 parent f332d96 commit 99f37b5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"internalConsoleOptions": "neverOpen"
}
]
}
}
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
module.exports = {
displayName: 'Unit Tests',
setupFilesAfterEnv: ['jest-extended', 'jest-chain'],
preset: "ts-jest",
preset: 'ts-jest',
testMatch: [
'<rootDir>/test/plugin.ts',
'<rootDir>/test/lib/rules/**/*.ts',
Expand Down
24 changes: 11 additions & 13 deletions lib/rules/enforce-foo-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const ruleEnforceFoorBar: TSESLint.RuleModule<MessageIds> = {
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: []
Expand All @@ -19,17 +20,14 @@ const ruleEnforceFoorBar: TSESLint.RuleModule<MessageIds> = {
// 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',
Expand All @@ -45,6 +43,6 @@ const ruleEnforceFoorBar: TSESLint.RuleModule<MessageIds> = {
}
}
})
}
};

export default ruleEnforceFoorBar;
export default ruleEnforceFoorBar;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
10 changes: 5 additions & 5 deletions test/lib/rules/enforce-foo-bar.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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' }]
}
],
});
]
});
30 changes: 15 additions & 15 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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. */
}
}
}

0 comments on commit 99f37b5

Please sign in to comment.