Skip to content

Commit ae64314

Browse files
feat!: add support for eslint v9, drop support for eslint v8 & v7 @W-18423706 (#44)
* feat!: add support for eslint v9, drop support for eslint v8 & v7 @W-18423706 BREAKING CHANGE: dropping support for ESLint v7 and v8. The only supported option is ESLint v9 * feat: make config flat * fix: update rules to new context apis * fix: fix rule tester script to use right module type * docs: update readme * fix: update lock file * fix: update image used for ci * fix: address PR comments * fix: address PR comments to renable all recommended rules from base config * fix: formatting to add trailing commas
1 parent f602246 commit ae64314

25 files changed

+2743
-793
lines changed

.circleci/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version: 2.1
22

3-
supported-eslint-versions: &supported-eslint-versions ["local", "7"]
3+
supported-eslint-versions: &supported-eslint-versions ["local"]
44

55
jobs:
66
build:
@@ -12,7 +12,7 @@ jobs:
1212
frozen in the package-lock.json is used.
1313
default: "local"
1414
docker:
15-
- image: circleci/node
15+
- image: cimg/node:18.18.0
1616
steps:
1717
- checkout
1818

@@ -47,4 +47,4 @@ workflows:
4747
- build:
4848
matrix:
4949
parameters:
50-
eslint-version: *supported-eslint-versions
50+
eslint-version: *supported-eslint-versions

.eslintrc.js

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

README.md

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@ npm install --save-dev @salesforce/eslint-plugin-aura
1313

1414
## Usage
1515

16+
> [!IMPORTANT]
17+
> Starting with v3.0.0, `@salesforce/eslint-plugin-aura` only supports `eslint@v9`. Use `@salesforce/eslint-plugin-aura@v2.x` for older versions of ESLint.
18+
1619
Add this plugin to your ESLint configuration and extend your desired configuration. See
17-
[ESLint documentation](http://eslint.org/docs/user-guide/configuring#configuring-plugins) for details.
18-
19-
Example:
20-
21-
```json
22-
{
23-
"plugins": ["@salesforce/eslint-plugin-aura"],
24-
"extends": [
25-
"plugin:@salesforce/eslint-plugin-aura/recommended",
26-
"plugin:@salesforce/eslint-plugin-aura/locker"
27-
]
28-
}
20+
[ESLint documentation](https://eslint.org/docs/latest/use/configure/plugins) for details.
21+
22+
Example `eslint.config.js`:
23+
24+
```js
25+
const eslintAura = require('@salesforce/eslint-plugin-aura');
26+
module.exports = [
27+
...eslintAura.configs.recommended,
28+
...eslintAura.configs.locker,
29+
];
2930
```
3031

3132
## Rules
@@ -52,7 +53,7 @@ Example:
5253

5354
This package exposes 2 configurations for your usage.
5455

55-
### `@salesforce/eslint-plugin-aura/recommended` configuration
56+
### Recommended configuration
5657

5758
**Goal:**
5859
Prevent common pitfalls with Lightning component development, and enforce other Salesforce platform restrictions.
@@ -63,7 +64,36 @@ Prevent common pitfalls with Lightning component development, and enforce other
6364
- Proper usage of the `$A` global, via the [`aura-api`](https://github.com/forcedotcom/eslint-plugin-aura/blob/master/docs/rules/aura-api.md) rule.
6465
- Browser compatibility rules for [Salesforce supported browsers](https://help.salesforce.com/articleView?id=sf.getstart_browsers_sfx.htm&type=5).
6566

66-
### `@salesforce/eslint-plugin-aura/locker` configuration
67+
**Usage**
68+
69+
```js
70+
// eslint.config.js
71+
const eslintPluginAura = require('@salesforce/eslint-plugin-aura');
72+
73+
module.exports = [...eslintPluginAura.configs.recommended];
74+
```
75+
76+
#### Migration to ESLint v9
77+
78+
The recommended configurations extend ESLint's `js/recommended` [predefined configuration](https://eslint.org/docs/latest/use/configure/configuration-files#using-predefined-configurations) (previously known as `eslint:recommended`). ESLint v9 has added 4 new rules to the recommended config, you can read about that [here](https://eslint.org/docs/latest/use/migrate-to-9.0.0#eslint-recommended). You can opt to turn these off for backwards compatibility.
79+
80+
```js
81+
// eslint.config.js
82+
const eslintAura = require('@salesforce/eslint-plugin-aura');
83+
module.exports = [
84+
...eslintAura.configs.recommended,
85+
{
86+
rules: {
87+
'no-empty-static-block': 'off',
88+
'no-constant-binary-expression': 'off',
89+
'no-new-native-non-constructor': 'off',
90+
'no-unused-private-class-members': 'off',
91+
},
92+
},
93+
];
94+
```
95+
96+
### Lightning Locker configuration
6797

6898
**Goal:**
6999
Prevent [Lightning Locker](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/security_code.htm) violations.
@@ -73,3 +103,12 @@ Prevent [Lightning Locker](https://developer.salesforce.com/docs/atlas.en-us.lig
73103
- `@salesforce/eslint-plugin-aura/recommended` rules.
74104
- Proper usage of `document` and `window` via the [`secure-document`](https://github.com/forcedotcom/eslint-plugin-aura/blob/master/docs/rules/secure-document.md) and [`secure-window`](https://github.com/forcedotcom/eslint-plugin-aura/blob/master/docs/rules/secure-window.md) rules, respectively.
75105
- Proper usage of Javascript intrinsic APIs via the [`ecma-intrinsics`](https://github.com/forcedotcom/eslint-plugin-aura/blob/master/docs/rules/ecma-intrinsics.md) rule.
106+
107+
**Usage**
108+
109+
```js
110+
// eslint.config.js
111+
const eslintPluginAura = require('@salesforce/eslint-plugin-aura');
112+
113+
module.exports = [...eslintPluginAura.configs.locker];
114+
```

eslint.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
3+
const globals = require('globals');
4+
const js = require('@eslint/js');
5+
6+
module.exports = [
7+
js.configs.recommended,
8+
{
9+
languageOptions: {
10+
ecmaVersion: 2018,
11+
globals: {
12+
...globals.mocha,
13+
...globals.node,
14+
},
15+
sourceType: 'commonjs',
16+
},
17+
18+
rules: {
19+
strict: ['error'],
20+
},
21+
},
22+
];

lib/configs/locker.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
'use strict';
2+
const recommended = require('./recommended');
23

3-
module.exports = {
4-
extends: [require.resolve('./recommended')],
4+
module.exports = [
5+
...recommended,
6+
{
7+
rules: {
8+
'no-array-constructor': 'error', // help with instanceof
59

6-
rules: {
7-
'no-array-constructor': 'error', // help with instanceof
8-
9-
// Locker specific rules
10-
'@salesforce/aura/ecma-intrinsics': 'error',
11-
'@salesforce/aura/secure-document': 'error',
12-
'@salesforce/aura/secure-window': 'error',
10+
// Locker specific rules
11+
'@salesforce/aura/ecma-intrinsics': 'error',
12+
'@salesforce/aura/secure-document': 'error',
13+
'@salesforce/aura/secure-window': 'error',
14+
},
1315
},
14-
};
16+
];

lib/configs/recommended.js

Lines changed: 99 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,107 @@
11
'use strict';
2+
const eslintJs = require('@eslint/js');
3+
const globals = require('globals');
24

3-
module.exports = {
4-
extends: ['eslint:recommended', 'plugin:compat/recommended'],
5-
6-
plugins: ['compat', '@salesforce/eslint-plugin-aura'],
7-
8-
env: {
9-
browser: true,
10-
},
11-
12-
parserOptions: {
13-
ecmaVersion: 5,
14-
},
15-
16-
globals: {
17-
$A: true,
18-
AuraContext: true,
19-
AuraSerializationService: true,
20-
AuraExpressionService: true,
21-
AuraEventService: true,
22-
AuraLocalizationService: true,
23-
AuraStorageService: true,
24-
AuraStyleService: true,
25-
MetricsService: true,
26-
AuraDevToolService: true,
27-
Component: true,
28-
CKEDITOR: true,
29-
FORCE: true,
30-
moment: true,
31-
exports: true,
32-
iScroll: true,
33-
Promise: true,
34-
},
35-
36-
rules: {
37-
// Possible errors
38-
// https://eslint.org/docs/rules/#possible-errors
39-
'no-console': 'error',
5+
const auraGlobals = {
6+
$A: true,
7+
AuraContext: true,
8+
AuraSerializationService: true,
9+
AuraExpressionService: true,
10+
AuraEventService: true,
11+
AuraLocalizationService: true,
12+
AuraStorageService: true,
13+
AuraStyleService: true,
14+
MetricsService: true,
15+
AuraDevToolService: true,
16+
Component: true,
17+
CKEDITOR: true,
18+
FORCE: true,
19+
moment: true,
20+
exports: true,
21+
iScroll: true,
22+
Promise: true,
23+
};
4024

41-
// Best practices
42-
// https://eslint.org/docs/rules/#best-practices
43-
'array-callback-return': 'error',
44-
'consistent-return': 'error',
45-
'default-case': 'error',
46-
'dot-notation': ['error', { allowKeywords: true }],
47-
eqeqeq: ['error', 'smart'],
48-
'guard-for-in': 'error',
49-
'no-alert': 'error',
50-
'no-caller': 'error',
51-
'no-else-return': 'error',
52-
'no-empty-function': [
53-
'error',
54-
{
55-
allow: ['arrowFunctions', 'functions', 'methods'],
25+
module.exports = [
26+
eslintJs.configs.recommended,
27+
{
28+
languageOptions: {
29+
ecmaVersion: 5,
30+
// https://eslint.org/docs/latest/use/migrate-to-9.0.0#-flatruletester-is-now-ruletester
31+
// New default sourceType is 'module', override to 'script' for backward compatibility
32+
sourceType: 'script',
33+
globals: {
34+
...globals.browser,
35+
...auraGlobals,
5636
},
57-
],
58-
'no-eval': 'error',
59-
'no-extend-native': 'error',
60-
'no-extra-bind': 'error',
61-
'no-floating-decimal': 'error',
62-
'no-implied-eval': 'error',
63-
'no-iterator': 'error',
64-
'no-labels': 'error',
65-
'no-loop-func': 'error',
66-
'no-multi-str': 'error',
67-
'no-new': 'error',
68-
'no-new-func': 'error',
69-
'no-new-object': 'error',
70-
'no-new-wrappers': 'error',
71-
'no-octal-escape': 'error',
72-
'no-proto': 'error',
73-
'no-return-assign': 'error',
74-
'no-return-await': 'error',
75-
'no-script-url': 'error',
76-
'no-self-compare': 'error',
77-
'no-sequences': 'error',
78-
'no-throw-literal': 'error',
79-
'no-useless-concat': 'error',
80-
'no-useless-escape': 'error',
81-
'no-useless-return': 'error',
82-
'no-unused-expressions': 'error',
83-
'no-void': 'error',
84-
'no-with': 'error',
85-
radix: 'error',
86-
'vars-on-top': 'error',
87-
'wrap-iife': ['error', 'any'],
37+
},
38+
rules: {
39+
// Possible errors
40+
// https://eslint.org/docs/rules/#possible-errors
41+
'no-console': 'error',
8842

89-
// Variables
90-
// https://eslint.org/docs/rules/#variables
91-
'no-label-var': 'error',
92-
'no-shadow': 'error',
93-
'no-shadow-restricted-names': 'error',
94-
'no-undef-init': 'error',
95-
'no-unused-vars': ['error', { vars: 'all', args: 'after-used' }],
96-
'no-use-before-define': ['error', { functions: false }],
43+
// Best practices
44+
// https://eslint.org/docs/rules/#best-practices
45+
'array-callback-return': 'error',
46+
'consistent-return': 'error',
47+
'default-case': 'error',
48+
'dot-notation': ['error', { allowKeywords: true }],
49+
eqeqeq: ['error', 'smart'],
50+
'guard-for-in': 'error',
51+
'no-alert': 'error',
52+
'no-caller': 'error',
53+
'no-else-return': 'error',
54+
'no-empty-function': [
55+
'error',
56+
{
57+
allow: ['arrowFunctions', 'functions', 'methods'],
58+
},
59+
],
60+
'no-eval': 'error',
61+
'no-extend-native': 'error',
62+
'no-extra-bind': 'error',
63+
'no-floating-decimal': 'error',
64+
'no-implied-eval': 'error',
65+
'no-iterator': 'error',
66+
'no-labels': 'error',
67+
'no-loop-func': 'error',
68+
'no-multi-str': 'error',
69+
'no-new': 'error',
70+
'no-new-func': 'error',
71+
'no-new-object': 'error',
72+
'no-new-wrappers': 'error',
73+
'no-octal-escape': 'error',
74+
'no-proto': 'error',
75+
'no-return-assign': 'error',
76+
'no-return-await': 'error',
77+
'no-script-url': 'error',
78+
'no-self-compare': 'error',
79+
'no-sequences': 'error',
80+
'no-throw-literal': 'error',
81+
'no-useless-concat': 'error',
82+
'no-useless-escape': 'error',
83+
'no-useless-return': 'error',
84+
'no-unused-expressions': 'error',
85+
'no-void': 'error',
86+
'no-with': 'error',
87+
radix: 'error',
88+
'vars-on-top': 'error',
89+
'wrap-iife': ['error', 'any'],
9790

98-
// Aura specific rules
99-
'@salesforce/aura/aura-api': 'error',
100-
'@salesforce/aura/getevt-markup-prefix': 'error',
101-
'@salesforce/aura/no-deprecated-aura-error': 'error',
102-
'@salesforce/aura/no-deprecated-component-creation': 'error',
103-
},
91+
// Variables
92+
// https://eslint.org/docs/rules/#variables
93+
'no-label-var': 'error',
94+
'no-shadow': 'error',
95+
'no-shadow-restricted-names': 'error',
96+
'no-undef-init': 'error',
97+
'no-unused-vars': ['error', { vars: 'all', args: 'after-used' }],
98+
'no-use-before-define': ['error', { functions: false }],
10499

105-
// Configuration for compat eslint plugin:
106-
// https://github.com/amilajack/eslint-plugin-compat#adding-polyfills
107-
settings: {
108-
// https://help.salesforce.com/articleView?id=getstart_browsers_sfx.htm&type=5
109-
targets:
110-
'last 1 version, last 1 firefox version, last 1 edge version, ie 11, not safari < 12',
111-
polyfills: ['Promise'],
100+
// Aura specific rules
101+
'@salesforce/aura/aura-api': 'error',
102+
'@salesforce/aura/getevt-markup-prefix': 'error',
103+
'@salesforce/aura/no-deprecated-aura-error': 'error',
104+
'@salesforce/aura/no-deprecated-component-creation': 'error',
105+
},
112106
},
113-
};
107+
];

0 commit comments

Comments
 (0)