Skip to content

Commit 6e8ec0d

Browse files
authored
Merge pull request #61 from khawkins/eslint_9
Updates to support ESLint 9.x
2 parents b7a0dde + 2d88c0c commit 6e8ec0d

File tree

106 files changed

+1031
-912
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+1031
-912
lines changed

.eslintrc

Lines changed: 0 additions & 28 deletions
This file was deleted.

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yarn format && yarn lint && yarn test

README.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,35 @@ $ npm install --save-dev @salesforce/eslint-plugin-lwc-graph-analyzer
2424

2525
## Configuration
2626

27-
Here's an example snippet of a `.eslintrc.json` configuration file, that will configure the `eslint-plugin-lwc-graph-analyzer` plugin. Extending the `plugin:@salesforce/lwc-graph-analyzer/recommended` ESLint configuration will enable static analysis on all `.js` and `.html` files used in your Lightning web components.
27+
ESLint version-specific configuration examples are provided below. Here are some additional considerations for configuring the plugin.
28+
29+
- In an SFDX project, you would most commonly add your configuration at the root of your LWC "tree"—which by default resides at `force-app/main/default/lwc/`—since the plugin's analysis applies specifically to Lightning web components.
30+
- Extending the appropriate `recommended` config based on your ESLint version will enable static analysis on all `.js` and `.html` files used in your Lightning web components.
31+
32+
### ESLint >= 9
33+
34+
The default configurations are now in the flat config format supported by ESLint 9 and beyond. Here's how to include the `recommended` config in your flat config:
35+
36+
```javascript
37+
// eslint.config.mjs
38+
import js from '@eslint/js';
39+
import lwcGraphAnalyzerPlugin from '@salesforce/eslint-plugin-lwc-graph-analyzer';
40+
41+
export default [
42+
{ plugins: { '@salesforce/lwc-graph-analyzer': lwcGraphAnalyzerPlugin } },
43+
js.configs.recommended,
44+
lwcGraphAnalyzerPlugin.configs.recommended
45+
];
46+
```
47+
48+
### ESLint < 9
49+
50+
Configurations for legacy ESLint have moved to `-legacy` extensions. Here's an `.eslintrc.json` configuration file that will configure the `eslint-plugin-lwc-graph-analyzer` plugin with the `recommended-legacy` config:
2851

2952
```json
3053
{
31-
"extends": ["eslint:recommended", "plugin:@salesforce/lwc-graph-analyzer/recommended"]
54+
"extends": ["eslint:recommended", "plugin:@salesforce/lwc-graph-analyzer/recommended-legacy"]
3255
}
3356
```
3457

35-
In an SFDX project, you would most commonly add this configuration at the root of your LWC "tree"—which by default resides at `force-app/main/default/lwc/`—since the plugin's analysis applies specifically to Lightning web components.
36-
3758
**Note:** If you have a `.eslintignore` configuration in your project, do _not_ add an entry to ignore HTML files. This will cause the plugin to skip linting on LWC bundles that include HTML templates. There are a number of Komaci-based static analysis rules that apply specifically to the HTML template of a Lightning web component bundle.

eslint.config.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2025, salesforce.com, inc.
3+
* All rights reserved.
4+
* SPDX-License-Identifier: MIT
5+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6+
*/
7+
8+
const js = require('@eslint/js');
9+
const nodePlugin = require('eslint-plugin-n');
10+
const eslintPlugin = require('eslint-plugin-eslint-plugin');
11+
const tseslint = require('typescript-eslint');
12+
13+
module.exports = [
14+
{
15+
ignores: ['test/**/test.js', 'reports/**']
16+
},
17+
{
18+
...js.configs.recommended,
19+
...nodePlugin.configs['flat/recommended-script'],
20+
files: ['**/*.js'],
21+
languageOptions: {
22+
ecmaVersion: 'latest',
23+
sourceType: 'module',
24+
globals: {
25+
// jest globals
26+
jest: 'readonly',
27+
describe: 'readonly',
28+
it: 'readonly',
29+
expect: 'readonly',
30+
beforeEach: 'readonly',
31+
afterEach: 'readonly',
32+
beforeAll: 'readonly',
33+
afterAll: 'readonly'
34+
}
35+
},
36+
rules: {
37+
strict: ['error', 'global']
38+
}
39+
},
40+
...tseslint.configs.recommended.map((config) => ({
41+
...config,
42+
files: ['**/*.d.ts']
43+
})),
44+
{
45+
files: ['lib/rules/*.js'],
46+
plugins: {
47+
'eslint-plugin': eslintPlugin
48+
},
49+
...eslintPlugin.configs['flat/recommended'],
50+
rules: {
51+
'eslint-plugin/prefer-message-ids': 'off' // Messages come straight from Komaci.
52+
}
53+
}
54+
];

index.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

jest.config.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
66
*/
77

8-
'use strict';
9-
108
module.exports = {
119
displayName: 'Unit Tests',
1210
setupFilesAfterEnv: ['jest-extended', 'jest-chain'],

lib/configs/base-legacy.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2022, salesforce.com, inc.
3+
* All rights reserved.
4+
* SPDX-License-Identifier: MIT
5+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6+
*/
7+
8+
module.exports = {
9+
plugins: ['@salesforce/lwc-graph-analyzer'],
10+
parser: '@babel/eslint-parser',
11+
parserOptions: {
12+
ecmaVersion: 'latest',
13+
requireConfigFile: false,
14+
sourceType: 'module',
15+
babelOptions: {
16+
parserOpts: {
17+
plugins: [['decorators', { decoratorsBeforeExport: false }]]
18+
}
19+
}
20+
}
21+
};

lib/configs/base.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
66
*/
77

8-
'use strict';
8+
const bundleAnalyzer = require('../processor');
99

1010
module.exports = {
11-
plugins: ['@salesforce/lwc-graph-analyzer'],
12-
parser: '@babel/eslint-parser',
13-
parserOptions: {
14-
ecmaVersion: 'latest',
15-
requireConfigFile: false,
16-
sourceType: 'module',
17-
babelOptions: {
18-
parserOpts: {
19-
plugins: [['decorators', { decoratorsBeforeExport: false }]]
11+
files: ['*.html', '**/*.html', '*.js', '**/*.js'],
12+
processor: bundleAnalyzer,
13+
languageOptions: {
14+
parser: require('@babel/eslint-parser'),
15+
parserOptions: {
16+
ecmaVersion: 'latest',
17+
requireConfigFile: false,
18+
sourceType: 'module',
19+
babelOptions: {
20+
parserOpts: {
21+
plugins: [['decorators', { decoratorsBeforeExport: false }]]
22+
}
2023
}
2124
}
2225
}

lib/configs/recommended-legacy.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright (c) 2022, salesforce.com, inc.
3+
* All rights reserved.
4+
* SPDX-License-Identifier: MIT
5+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6+
*/
7+
8+
module.exports = {
9+
extends: ['./configs/base-legacy'],
10+
rules: {},
11+
overrides: [
12+
{
13+
files: ['*.html', '**/*.html', '*.js', '**/*.js'],
14+
processor: '@salesforce/lwc-graph-analyzer/bundleAnalyzer',
15+
rules: {
16+
'@salesforce/lwc-graph-analyzer/no-getter-contains-more-than-return-statement':
17+
'warn',
18+
'@salesforce/lwc-graph-analyzer/no-assignment-expression-assigns-value-to-member-variable':
19+
'warn',
20+
'@salesforce/lwc-graph-analyzer/no-wire-config-references-non-local-property-reactive-value':
21+
'warn',
22+
'@salesforce/lwc-graph-analyzer/no-private-wire-config-property': 'warn',
23+
'@salesforce/lwc-graph-analyzer/no-unresolved-parent-class-reference': 'warn',
24+
'@salesforce/lwc-graph-analyzer/no-class-refers-to-parent-class-from-unsupported-namespace':
25+
'warn',
26+
'@salesforce/lwc-graph-analyzer/no-reference-to-unsupported-namespace-reference':
27+
'warn',
28+
'@salesforce/lwc-graph-analyzer/no-wire-config-property-uses-getter-function-returning-inaccessible-import':
29+
'warn',
30+
'@salesforce/lwc-graph-analyzer/no-wire-config-property-uses-getter-function-returning-non-literal':
31+
'warn',
32+
'@salesforce/lwc-graph-analyzer/no-wire-config-property-circular-wire-dependency':
33+
'warn',
34+
'@salesforce/lwc-graph-analyzer/no-wire-configuration-property-using-output-of-non-primeable-wire':
35+
'warn',
36+
'@salesforce/lwc-graph-analyzer/no-missing-resource-cannot-prime-wire-adapter':
37+
'warn',
38+
'@salesforce/lwc-graph-analyzer/no-wire-config-property-uses-imported-artifact-from-unsupported-namespace':
39+
'warn',
40+
'@salesforce/lwc-graph-analyzer/no-wire-adapter-of-resource-cannot-be-primed':
41+
'warn',
42+
'@salesforce/lwc-graph-analyzer/no-unsupported-member-variable-in-member-expression':
43+
'warn',
44+
'@salesforce/lwc-graph-analyzer/no-multiple-template-files': 'warn',
45+
'@salesforce/lwc-graph-analyzer/no-assignment-expression-for-external-components':
46+
'warn',
47+
'@salesforce/lwc-graph-analyzer/no-tagged-template-expression-contains-unsupported-namespace':
48+
'warn',
49+
'@salesforce/lwc-graph-analyzer/no-expression-contains-module-level-variable-ref':
50+
'warn',
51+
'@salesforce/lwc-graph-analyzer/no-call-expression-references-unsupported-namespace':
52+
'warn',
53+
'@salesforce/lwc-graph-analyzer/no-eval-usage': 'warn',
54+
'@salesforce/lwc-graph-analyzer/no-reference-to-class-functions': 'warn',
55+
'@salesforce/lwc-graph-analyzer/no-reference-to-module-functions': 'warn',
56+
'@salesforce/lwc-graph-analyzer/no-functions-declared-within-getter-method': 'warn',
57+
'@salesforce/lwc-graph-analyzer/no-member-expression-reference-to-non-existent-member-variable':
58+
'warn',
59+
'@salesforce/lwc-graph-analyzer/no-member-expression-reference-to-unsupported-namespace-reference':
60+
'warn',
61+
'@salesforce/lwc-graph-analyzer/no-member-expression-contains-non-portable-identifier':
62+
'warn',
63+
'@salesforce/lwc-graph-analyzer/no-member-expression-reference-to-super-class':
64+
'warn',
65+
'@salesforce/lwc-graph-analyzer/no-member-expression-reference-to-unsupported-global':
66+
'warn',
67+
'@salesforce/lwc-graph-analyzer/no-composition-on-unanalyzable-getter-property':
68+
'warn',
69+
'@salesforce/lwc-graph-analyzer/no-composition-on-unanalyzable-property-from-unresolvable-wire':
70+
'warn',
71+
'@salesforce/lwc-graph-analyzer/no-composition-on-unanalyzable-property-missing':
72+
'warn',
73+
'@salesforce/lwc-graph-analyzer/no-composition-on-unanalyzable-property-non-public':
74+
'warn',
75+
'@salesforce/lwc-graph-analyzer/no-render-function-contains-more-than-return-statement':
76+
'warn',
77+
'@salesforce/lwc-graph-analyzer/no-render-function-return-statement-not-returning-imported-template':
78+
'warn',
79+
'@salesforce/lwc-graph-analyzer/no-render-function-return-statement': 'warn'
80+
}
81+
}
82+
]
83+
};

0 commit comments

Comments
 (0)