Skip to content

Commit 1fb78a3

Browse files
feat: ESLint v9 (#151)
* feat!: update dependency to eslint v9 @W-17448473 (#141) * feat!: update dependency to eslint v9 @W-17448473 BREAKING CHANGE: dropping support for ESLint v7 and v8. The only supported option is ESLint v9 * 4.0.0-beta.1 * fix: specify correct peer dependency versions for @lwc/eslint-plugin-lwc and @salesforce/eslint-plugin-lightning * 4.0.0-beta.2 * fix: allow prerelease versions as peer dependencies * 4.0.0-beta.3 * chore: export ts configs @W-17448452 (#146) * 4.0.0-beta.4 * fix: add missing dependency (#147) globals was being pulled in as a transitive dependency * chore: update @lwc/eslint-plugin-lwc@3.0.0-beta.2 * 4.0.0-beta.5 --------- Co-authored-by: Ravi Jayaramappa <ravi.jayaramappa@salesforce.com>
1 parent 2a0e894 commit 1fb78a3

24 files changed

+957
-952
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
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
executors:
66
node:

.eslintrc

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

README.md

Lines changed: 65 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,70 +12,100 @@ Note that `@lwc/eslint-plugin-lwc`, `@salesforce/eslint-plugin-lightning`, `esli
1212

1313
## Usage
1414

15-
Add the appropriate [configuration](#Configurations) to the `extends` field in your configuration.
15+
> [!IMPORTANT]
16+
> Starting with v4.0.0, @salesforce/eslint-config-lwc only supports `eslint@v9`. Use `@salesforce/eslint-config-lwc@v3.x` for older versions of eslint.
17+
18+
This repo exports the configurations as an array of config objects. [Apply](https://eslint.org/docs/latest/use/configure/combine-configs#apply-a-config-array) the appropriate [configuration](#Configurations) into your configuration using the spread operator.
19+
20+
Example of `eslint.config.js`:
1621

17-
Example of `.eslintrc`:
22+
```js
23+
const lwcConfig = require('@salesforce/eslint-config-lwc');
1824

19-
```json
20-
{
21-
"extends": ["@salesforce/eslint-config-lwc/recommended"]
22-
}
25+
module.exports = [...lwcConfig.configs.recommended];
2326
```
2427

2528
For more details about configuration, please refer to the dedicated section in the ESLint documentation: https://eslint.org/docs/user-guide/configuring#using-a-shareable-configuration-package
2629

2730
### [Experimental] Usage with TypeScript
2831

29-
To enable working with TypeScript projects, install `@babel/preset-typescript` as a dependency, and extend any of the TypeScript-enabled [configurations](#configurations) (any config ending in `-ts`).
32+
To enable working with TypeScript projects, install `@babel/preset-typescript` as a dependency, and apply any of the TypeScript-enabled [configurations](#configurations) (any config ending in `Ts`).
3033

3134
Note that these configs use [@babel/eslint-parser](https://www.npmjs.com/package/@babel/eslint-parser), and compatibility with [@typescript-eslint/parser](https://npmjs.com/package/@typescript-eslint/parser) is not guaranteed.
3235

3336
> [!IMPORTANT]
3437
> While these configs are capable of parsing TypeScript files, not all rules support all TypeScript language features. For example, using type assertions (`variable as Type`) will break many rules.
3538
36-
Example `.eslintrc`:
39+
Example `eslint.config.js`:
3740

38-
```json
39-
{
40-
"extends": ["@salesforce/eslint-config-lwc/recommended-ts"]
41-
}
41+
```js
42+
const lwcConfig = require('@salesforce/eslint-config-lwc');
43+
44+
module.exports = [...lwcConfig.configs.recommendedTs];
4245
```
4346

4447
## Configurations
4548

46-
This package exposes multiple configurations for your usage. Each configuration listed below is available for both JavaScript projects and TypeScript projects (when using `-ts` suffix).
49+
This package exposes multiple configurations for your usage. Each configuration listed below is available for both JavaScript projects and TypeScript projects (when using `Ts` suffix).
4750

48-
### `@salesforce/eslint-config-lwc/base`
51+
### Base
4952

5053
**Goal:**
5154
Prevent common pitfalls with LWC, and enforce other Salesforce platform restrictions.
5255

5356
**Rules:**
5457
[_LWC specific rules_](https://github.com/salesforce/eslint-plugin-lwc/blob/master/README.md#lwc) only.
5558

56-
**TypeScript:** Use `@salesforce/eslint-config-lwc/base-ts` to use this config in TypeScript projects.
59+
**Usage:**
60+
61+
```js
62+
// eslint.config.js
63+
const lwcConfig = require('@salesforce/eslint-config-lwc');
64+
65+
module.exports = [...lwcConfig.configs.base];
66+
```
5767

58-
### `@salesforce/eslint-config-lwc/recommended`
68+
**TypeScript:** Use `configs.baseTs` to use this config in TypeScript projects.
69+
70+
### Recommended`@salesforce/eslint-config-lwc/recommended`
5971

6072
**Goal:**
6173
Prevent common Javascript pitfalls and enforce all best practices.
6274

6375
**Rules:**
64-
`@salesforce/eslint-config-lwc/base` rules + Most of the base [_Potential errors_](https://eslint.org/docs/rules/#possible-errors) rules + Some of the [_Best Practices_](https://eslint.org/docs/rules/#best-practices) rules + [_LWC Best Practices_](https://github.com/salesforce/eslint-plugin-lwc/blob/master/README.md#best-practices).
76+
Base rules + Most of the base [_Potential errors_](https://eslint.org/docs/rules/#possible-errors) rules + Some of the [_Best Practices_](https://eslint.org/docs/rules/#best-practices) rules + [_LWC Best Practices_](https://github.com/salesforce/eslint-plugin-lwc/blob/master/README.md#best-practices).
77+
78+
**Usage:**
79+
80+
```js
81+
// eslint.config.js
82+
const lwcConfig = require('@salesforce/eslint-config-lwc');
6583

66-
**TypeScript:** Use `@salesforce/eslint-config-lwc/recommended-ts` to use this config in TypeScript projects.
84+
module.exports = [...lwcConfig.configs.recommended];
85+
```
6786

68-
### `@salesforce/eslint-config-lwc/extended`
87+
**TypeScript:** Use `configs.recommendedTs` to use this config in TypeScript projects.
88+
89+
### Extended
6990

7091
**Goal:**
7192
Restrict usage of some Javascript language features known to be slow after the _COMPAT_ transformation. LWC runs in _COMPAT_ mode on older browsers (eg. IE11). To support new Javascript syntax and language features on older browser the LWC compiler transforms LWC modules. This linting configuration targets patterns known to be slow in _COMPAT_ mode.
7293

7394
**Rules:**
74-
`@salesforce/eslint-config-lwc/recommended` rules + restrict usage of some slow patterns in [_COMPAT_](https://github.com/salesforce/eslint-plugin-lwc/blob/master/README.md#compat-performance).
95+
Recommended rules + restrict usage of some slow patterns in [_COMPAT_](https://github.com/salesforce/eslint-plugin-lwc/blob/master/README.md#compat-performance).
96+
97+
**Usage:**
98+
99+
```js
100+
// eslint.config.js
101+
const lwcConfig = require('@salesforce/eslint-config-lwc');
75102

76-
**TypeScript:** Use `@salesforce/eslint-config-lwc/extended-ts` to use this config in TypeScript projects.
103+
module.exports = [...lwcConfig.configs.extended];
104+
```
77105

78-
### `@salesforce/eslint-config-lwc/i18n`
106+
**TypeScript:** Use `configs.extendedTs` to use this config in TypeScript projects.
107+
108+
### i18n `@salesforce/eslint-config-lwc/i18n`
79109

80110
**Goal:**
81111
Promote usage of `@salesforce/i18n-service` over 3rd parties, promote internationalization (I18N) best practices.
@@ -85,17 +115,18 @@ Promote usage of `@salesforce/i18n-service` over 3rd parties, promote internatio
85115

86116
**Usage:**
87117

88-
Add the `i18n` configuration to the `extends` field in your `.eslintrc` configuration file, for example:
118+
Add the `i18n` configuration to the `extends` field in your `eslint.config.js` configuration file, for example:
119+
120+
```js
121+
// eslint.config.js
122+
const lwcConfig = require('@salesforce/eslint-config-lwc');
89123

90-
```json
91-
{
92-
"extends": ["@salesforce/eslint-config-lwc/recommended", "@salesforce/eslint-config-lwc/i18n"]
93-
}
124+
module.exports = [...lwcConfig.configs.recommended, ...lwcConfig.configs.i18n];
94125
```
95126

96-
**TypeScript:** Use `@salesforce/eslint-config-lwc/i18n-ts` to use this config in TypeScript projects.
127+
**TypeScript:** Use `configs.i18nTs` to use this config in TypeScript projects.
97128

98-
### `@salesforce/eslint-config-lwc/ssr`
129+
### Ssr
99130

100131
**Goal:**
101132
Promote writing server-side-rendering friendly components. We only recommend using this configuration if your components are running in experiences supporting LWC server-side-rendering.
@@ -105,12 +136,11 @@ Promote writing server-side-rendering friendly components. We only recommend usi
105136

106137
**Usage:**
107138

108-
Add the `ssr` configuration to the `extends` field in your `.eslintrc` configuration file, for example:
139+
```js
140+
// eslint.config.js
141+
const lwcConfig = require('@salesforce/eslint-config-lwc');
109142

110-
```json
111-
{
112-
"extends": ["@salesforce/eslint-config-lwc/recommended", "@salesforce/eslint-config-lwc/ssr"]
113-
}
143+
module.exports = [...lwcConfig.configs.ssr];
114144
```
115145

116-
**TypeScript:** Use `@salesforce/eslint-config-lwc/ssr-ts` to use this config in TypeScript projects.
146+
**TypeScript:** Use `configs.ssrTs` to use this config in TypeScript projects.

base-ts.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66
*/
77
'use strict';
88

9-
module.exports = {
10-
extends: [
11-
require.resolve('./base'),
12-
// Must be second to override the default parser options
13-
require.resolve('./lib/typescript'),
14-
],
15-
};
9+
const base = require('./base');
10+
const tsLanguageOptions = require('./lib/typescript');
11+
12+
module.exports = [
13+
...base,
14+
// The following config will take effect as explained in
15+
// https://eslint.org/docs/latest/use/configure/configuration-files#cascading-configuration-objects
16+
{
17+
languageOptions: {
18+
...tsLanguageOptions,
19+
},
20+
},
21+
];

base.js

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
*/
77
'use strict';
88

9+
const eslintPluginLwc = require('@lwc/eslint-plugin-lwc');
10+
const languageOptions = require('./lib/defaults');
11+
912
const KNOWN_WIRE_ADAPTERS = [
1013
{
1114
module: 'lightning/**',
@@ -257,51 +260,53 @@ const WIRE_ADAPTERS_WITH_RESTRICTED_USE = [
257260
},
258261
];
259262

260-
module.exports = {
261-
extends: [require.resolve('./lib/defaults')],
263+
module.exports = [
264+
{
265+
languageOptions,
262266

263-
plugins: [
264-
'@lwc/eslint-plugin-lwc', // https://github.com/salesforce/eslint-plugin-lwc
265-
],
267+
plugins: {
268+
'@lwc/lwc': eslintPluginLwc, // https://github.com/salesforce/eslint-plugin-lwc
269+
},
266270

267-
rules: {
268-
// LWC lifecycle hooks validation
269-
'@lwc/lwc/no-deprecated': 'error',
271+
rules: {
272+
// LWC lifecycle hooks validation
273+
'@lwc/lwc/no-deprecated': 'error',
270274

271-
// LWC decorator validation
272-
'@lwc/lwc/valid-api': 'error',
273-
'@lwc/lwc/valid-track': 'error',
274-
'@lwc/lwc/valid-wire': 'error',
275+
// LWC decorator validation
276+
'@lwc/lwc/valid-api': 'error',
277+
'@lwc/lwc/valid-track': 'error',
278+
'@lwc/lwc/valid-wire': 'error',
275279

276-
// LWC wire adapters validation
277-
'@lwc/lwc/no-unknown-wire-adapters': [
278-
'error',
279-
{
280-
adapters: KNOWN_WIRE_ADAPTERS,
281-
},
282-
],
283-
'@lwc/lwc/no-unexpected-wire-adapter-usages': [
284-
'error',
285-
{
286-
adapters: WIRE_ADAPTERS_WITH_RESTRICTED_USE,
287-
},
288-
],
280+
// LWC wire adapters validation
281+
'@lwc/lwc/no-unknown-wire-adapters': [
282+
'error',
283+
{
284+
adapters: KNOWN_WIRE_ADAPTERS,
285+
},
286+
],
287+
'@lwc/lwc/no-unexpected-wire-adapter-usages': [
288+
'error',
289+
{
290+
adapters: WIRE_ADAPTERS_WITH_RESTRICTED_USE,
291+
},
292+
],
289293

290-
// LWC import validation
291-
'@lwc/lwc/no-disallowed-lwc-imports': 'error',
294+
// LWC import validation
295+
'@lwc/lwc/no-disallowed-lwc-imports': 'error',
292296

293-
// Disable any direct importing of LDS artifacts generated by the LWC compiler
294-
'no-restricted-imports': [
295-
'error',
296-
{
297-
patterns: [
298-
{
299-
group: ['@salesforce/lds', '@salesforce/lds/**'],
300-
message:
301-
'Please do not import from @salesforce/lds, these modules are ephemeral and could change at any time.',
302-
},
303-
],
304-
},
305-
],
306-
},
307-
};
297+
// Disable any direct importing of LDS artifacts generated by the LWC compiler
298+
'no-restricted-imports': [
299+
'error',
300+
{
301+
patterns: [
302+
{
303+
group: ['@salesforce/lds', '@salesforce/lds/**'],
304+
message:
305+
'Please do not import from @salesforce/lds, these modules are ephemeral and could change at any time.',
306+
},
307+
],
308+
},
309+
],
310+
},
311+
},
312+
];

eslint.config.js

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

extended-ts.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66
*/
77
'use strict';
88

9-
module.exports = {
10-
extends: [
11-
require.resolve('./extended'),
12-
// Must be second to override the default parser options
13-
require.resolve('./lib/typescript'),
14-
],
15-
};
9+
const tsLanguageOptions = require('./lib/typescript');
10+
const extended = require('./extended');
11+
12+
module.exports = [
13+
...extended,
14+
// The following config will take effect as explained in
15+
// https://eslint.org/docs/latest/use/configure/configuration-files#cascading-configuration-objects
16+
{
17+
languageOptions: {
18+
...tsLanguageOptions,
19+
},
20+
},
21+
];

extended.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
*/
77
'use strict';
88

9-
module.exports = {
10-
extends: [require.resolve('./recommended')],
9+
const recommended = require('./recommended');
1110

12-
rules: {
13-
// LWC COMPAT performance restrictions
14-
'@lwc/lwc/no-async-await': 'error',
15-
'@lwc/lwc/no-for-of': 'error',
16-
'@lwc/lwc/no-rest-parameter': 'error',
11+
module.exports = [
12+
...recommended,
13+
{
14+
rules: {
15+
// LWC COMPAT performance restrictions
16+
'@lwc/lwc/no-async-await': 'error',
17+
'@lwc/lwc/no-for-of': 'error',
18+
'@lwc/lwc/no-rest-parameter': 'error',
19+
},
1720
},
18-
};
21+
];

0 commit comments

Comments
 (0)