eslint-config-scratch 10.0.13 → 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/README.md +86 -113
- package/eslint.config.mjs +12 -3
- package/lib/eslint.mjs +307 -219
- package/lib/index.mjs +3 -3
- package/lib/legacy/{web.mjs → es6.mjs} +1 -0
- package/lib/legacy/index.mjs +1 -0
- package/lib/legacy/node.mjs +1 -0
- package/lib/legacy/react.mjs +1 -0
- package/lib/prettier.mjs +2 -8
- package/package.json +8 -13
- package/prettier.config.mjs +2 -2
- package/test/__snapshots__/eslint.test.mjs.snap +112 -0
- package/test/eslint.test.mjs +110 -0
- package/test/recommended/eslint.config.mjs +14 -0
- package/test/recommended/plain.bad.mjs +15 -0
- package/test/recommended/plain.bad.ts +17 -0
- package/test/recommended/plain.good.mjs +10 -0
- package/test/recommended/plain.good.ts +10 -0
- package/test/recommended/react.bad.jsx +14 -0
- package/test/recommended/react.good.jsx +12 -0
- package/test/recommended/tsconfig.json +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,39 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See
|
|
4
4
|
[Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [11.0.0](https://github.com/scratchfoundation/eslint-config-scratch/compare/v10.0.14...v11.0.0) (2025-05-05)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* be more careful about ext => rule mapping ([d010853](https://github.com/scratchfoundation/eslint-config-scratch/commit/d01085335cbe81df389a18e590120a3c5085ecfa))
|
|
12
|
+
* disable jsdoc/require-jsdoc ([7d7b277](https://github.com/scratchfoundation/eslint-config-scratch/commit/7d7b277676c772cafeb157b87d0f3205a81f7792))
|
|
13
|
+
* don't try to check types in JS ([329b4de](https://github.com/scratchfoundation/eslint-config-scratch/commit/329b4de61c81be7c2fddd965a08cb2b73017089a))
|
|
14
|
+
* fix linting for code blocks inside Markdown ([152673f](https://github.com/scratchfoundation/eslint-config-scratch/commit/152673ff3918a0f68e2401595c68f06c49eac711))
|
|
15
|
+
* re-enable jsdoc checks ([40c86c9](https://github.com/scratchfoundation/eslint-config-scratch/commit/40c86c94ca7d3dfa713d139fa28ef4b544b1b131))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
* refactor!: simplify and flatten configurations ([a7dda10](https://github.com/scratchfoundation/eslint-config-scratch/commit/a7dda101f27c3099f024f1eb53533ee3cc97194f))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
* better type help, esp. with makeEslintConfig ([497bd28](https://github.com/scratchfoundation/eslint-config-scratch/commit/497bd2880ba7640966e5f87fc3d4bd5b482eb303))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### BREAKING CHANGES
|
|
27
|
+
|
|
28
|
+
* Configurations are now returned as objects, like most
|
|
29
|
+
shared ESLint configurations. The `make*Config` functions are no more.
|
|
30
|
+
Also, everything is now exported through one file.
|
|
31
|
+
|
|
32
|
+
## [10.0.14](https://github.com/scratchfoundation/eslint-config-scratch/compare/v10.0.13...v10.0.14) (2025-05-03)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
### Bug Fixes
|
|
36
|
+
|
|
37
|
+
* **deps:** update dependency @babel/eslint-parser to v7.27.1 ([#230](https://github.com/scratchfoundation/eslint-config-scratch/issues/230)) ([cb5cbe2](https://github.com/scratchfoundation/eslint-config-scratch/commit/cb5cbe29e017a67ceb967b9ed716a1360a740d61))
|
|
38
|
+
|
|
6
39
|
## [10.0.13](https://github.com/scratchfoundation/eslint-config-scratch/compare/v10.0.12...v10.0.13) (2025-05-01)
|
|
7
40
|
|
|
8
41
|
|
package/README.md
CHANGED
|
@@ -12,26 +12,43 @@ Install the config along with its peer dependencies, `eslint` and `prettier`:
|
|
|
12
12
|
npm install -D eslint-config-scratch eslint@^9 prettier@^3
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
Add `eslint.config.mjs` to your project root
|
|
15
|
+
Add `eslint.config.mjs` to your project root.
|
|
16
|
+
|
|
17
|
+
For a TypeScript project, you can add `languageOptions` to enable type checking:
|
|
16
18
|
|
|
17
19
|
```js
|
|
18
20
|
// myProjectRoot/eslint.config.mjs
|
|
19
|
-
import {
|
|
21
|
+
import { eslintConfigScratch } from 'eslint-config-scratch'
|
|
22
|
+
|
|
23
|
+
export default eslintConfigScratch.config(eslintConfigScratch.recommended, {
|
|
24
|
+
languageOptions: {
|
|
25
|
+
parserOptions: {
|
|
26
|
+
projectService: true,
|
|
27
|
+
tsconfigRootDir: import.meta.dirname,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
```
|
|
20
32
|
|
|
21
|
-
|
|
22
|
-
export default makeEslintConfig({ globals: 'browser', tsconfigRootDir: import.meta.dirname })
|
|
33
|
+
For a JavaScript project, it might look like this:
|
|
23
34
|
|
|
24
|
-
|
|
25
|
-
|
|
35
|
+
```js
|
|
36
|
+
// myProjectRoot/eslint.config.mjs
|
|
37
|
+
import { eslintConfigScratch } from 'eslint-config-scratch'
|
|
38
|
+
|
|
39
|
+
export default eslintConfigScratch.recommended
|
|
26
40
|
```
|
|
27
41
|
|
|
42
|
+
The function `eslintConfigScratch.config` is a re-export of the `config` function from `typescript-eslint`, and helps
|
|
43
|
+
with merging and extending configurations.
|
|
44
|
+
|
|
28
45
|
Add `prettier.config.mjs` to your project root as well:
|
|
29
46
|
|
|
30
47
|
```js
|
|
31
48
|
// myProjectRoot/prettier.config.mjs
|
|
32
|
-
import {
|
|
49
|
+
import { prettierConfigScratch } from 'eslint-config-scratch'
|
|
33
50
|
|
|
34
|
-
export default
|
|
51
|
+
export default prettierConfigScratch.recommended
|
|
35
52
|
```
|
|
36
53
|
|
|
37
54
|
Finally, add scripts like these to your `package.json`:
|
|
@@ -45,134 +62,90 @@ Finally, add scripts like these to your `package.json`:
|
|
|
45
62
|
|
|
46
63
|
## Basic Configuration
|
|
47
64
|
|
|
48
|
-
The `
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
```mjs
|
|
52
|
-
// myProjectRoot/eslint.config.mjs
|
|
53
|
-
import { makeEslintConfig } from 'eslint-config-scratch'
|
|
54
|
-
|
|
55
|
-
export default makeEslintConfig({
|
|
56
|
-
// Optional: specify global variables available in your environment
|
|
57
|
-
globals: 'browser',
|
|
58
|
-
|
|
59
|
-
// Optional: enables rules that use type info, some of which work in JS too
|
|
60
|
-
tsconfigRootDir: import.meta.dirname,
|
|
61
|
-
})
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
If you have no `tsconfig.json` (or `jsconfig.json`) in your project, you can skip the `tsconfigRootDir` option. Rules
|
|
65
|
-
that require type information will be disabled or replaced with less strict alternatives that work without type info.
|
|
66
|
-
|
|
67
|
-
### Globals
|
|
68
|
-
|
|
69
|
-
The `globals` property is optional. If present, it can take several forms:
|
|
70
|
-
|
|
71
|
-
- a string, interpreted as a key in the `globals` object exported by the `globals` package.
|
|
72
|
-
- Examples: `'browser'`, `'node'`, `'es2021'`, `'jest'`, etc.
|
|
73
|
-
- an object, set up as described in the "Specifying Globals" section of the [ESLint documentation](https://eslint.org/docs/latest/use/configure/language-options#using-configuration-files)
|
|
74
|
-
- Example: `{ myGlobal: 'readonly', anotherGlobal: 'writable' }`
|
|
75
|
-
- an array of zero or more of any mixture of the above
|
|
76
|
-
|
|
77
|
-
```mjs
|
|
78
|
-
// myProjectRoot/eslint.config.mjs
|
|
79
|
-
import { makeEslintConfig } from 'eslint-config-scratch'
|
|
80
|
-
|
|
81
|
-
export default makeEslintConfig({
|
|
82
|
-
// Optional: enables rules that use type info, some of which work in JS too
|
|
83
|
-
tsconfigRootDir: import.meta.dirname,
|
|
84
|
-
|
|
85
|
-
// Optional: specify global variables available in your environment
|
|
86
|
-
// Warning: this is a very silly configuration
|
|
87
|
-
globals: [
|
|
88
|
-
'shared-node-browser',
|
|
89
|
-
{
|
|
90
|
-
fun: 'readonly',
|
|
91
|
-
thing: false,
|
|
92
|
-
},
|
|
93
|
-
'es2021',
|
|
94
|
-
{
|
|
95
|
-
whyNot: 'writable',
|
|
96
|
-
},
|
|
97
|
-
],
|
|
98
|
-
})
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
### Further Customization
|
|
102
|
-
|
|
103
|
-
The return value of the `makeEslintConfig` function is a standard ESLint configuration array. This means you can
|
|
104
|
-
customize your configuration further like this:
|
|
105
|
-
|
|
106
|
-
```mjs
|
|
107
|
-
// myProjectRoot/eslint.config.mjs
|
|
108
|
-
import { makeEslintConfig } from 'eslint-config-scratch'
|
|
109
|
-
|
|
110
|
-
export default [
|
|
111
|
-
...makeEslintConfig({
|
|
112
|
-
// Optional: enables rules that use type info, some of which work in JS too
|
|
113
|
-
tsconfigRootDir: import.meta.dirname,
|
|
114
|
-
|
|
115
|
-
// Optional: specify global variables available in your environment
|
|
116
|
-
globals: 'browser',
|
|
117
|
-
}),
|
|
118
|
-
// Add custom rules or overrides here
|
|
119
|
-
{
|
|
120
|
-
files: ['*.test.js'],
|
|
121
|
-
rules: {
|
|
122
|
-
'no-console': 'off', // Allow console logs in test files
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
]
|
|
126
|
-
```
|
|
65
|
+
The `eslintConfigScratch.config` is a re-export of the `config` function from `typescript-eslint`. Full documentation
|
|
66
|
+
is available here: <https://typescript-eslint.io/packages/typescript-eslint#config>.
|
|
127
67
|
|
|
128
|
-
|
|
129
|
-
`globals` configuration from above doesn't meet your needs:
|
|
68
|
+
The `config` function can be used to add or override rules, plugins, and other configuration options. For example:
|
|
130
69
|
|
|
131
|
-
```
|
|
70
|
+
```js
|
|
132
71
|
// myProjectRoot/eslint.config.mjs
|
|
133
|
-
import {
|
|
72
|
+
import { eslintConfigScratch } from 'eslint-config-scratch'
|
|
73
|
+
import { globalIgnores } from 'eslint/config'
|
|
134
74
|
import globals from 'globals'
|
|
135
75
|
|
|
136
|
-
export default
|
|
137
|
-
|
|
138
|
-
// Optional: enables rules that use type info, some of which work in JS too
|
|
139
|
-
tsconfigRootDir: import.meta.dirname,
|
|
140
|
-
}),
|
|
76
|
+
export default eslintConfigScratch.config(
|
|
77
|
+
eslintConfigScratch.recommended,
|
|
141
78
|
{
|
|
142
|
-
files: ['src/main/**.js'],
|
|
143
|
-
languageOptions: {
|
|
144
|
-
globals: globals.node,
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
files: ['src/renderer/**.js'],
|
|
149
79
|
languageOptions: {
|
|
150
80
|
globals: {
|
|
151
|
-
...globals.
|
|
81
|
+
...globals.node,
|
|
152
82
|
MY_CUSTOM_GLOBAL: 'readonly',
|
|
153
83
|
},
|
|
84
|
+
parserOptions: {
|
|
85
|
+
projectService: true,
|
|
86
|
+
tsconfigRootDir: import.meta.dirname,
|
|
87
|
+
},
|
|
154
88
|
},
|
|
155
89
|
},
|
|
156
|
-
|
|
90
|
+
// Ignore all files in the dist directory
|
|
91
|
+
globalIgnores(['dist/**/*']),
|
|
92
|
+
)
|
|
157
93
|
```
|
|
158
94
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
`
|
|
95
|
+
## Granular Configuration
|
|
96
|
+
|
|
97
|
+
The `eslintConfigScratch` object contains granular configurations as well:
|
|
98
|
+
|
|
99
|
+
- `recommendedTypeFree`: A configuration suitable for contexts without type information, such as a JavaScript project.
|
|
100
|
+
- `recommendedTypeChecked`: A configuration suitable for contexts with type information, such as a TypeScript project.
|
|
101
|
+
You must provide extra configuration to `parserOptions` to enable type checking. See here:
|
|
102
|
+
<https://typescript-eslint.io/getting-started/typed-linting/>
|
|
103
|
+
|
|
104
|
+
The `recommended` configuration is a combination of the two, and should be suitable for most projects. Features
|
|
105
|
+
requiring type information are enabled for TypeScript files, and features that don't require type information are
|
|
106
|
+
enabled for all files.
|
|
162
107
|
|
|
163
108
|
## Legacy Styles
|
|
164
109
|
|
|
165
110
|
Scratch used very different styling rules in `eslint-config-scratch@^9` and below. If you need to use those rules, you
|
|
166
|
-
can use
|
|
111
|
+
can use these legacy configurations:
|
|
167
112
|
|
|
168
|
-
- `
|
|
169
|
-
- `
|
|
170
|
-
- `
|
|
171
|
-
- `
|
|
113
|
+
- `eslintConfigScratch.legacy.base`: Legacy base configuration, not configured for any particular environment
|
|
114
|
+
- `eslintConfigScratch.legacy.es6`: Legacy rules for targeting Scratch's supported web browsers
|
|
115
|
+
- `eslintConfigScratch.legacy.node`: Legacy rules for targeting Node.js
|
|
116
|
+
- `eslintConfigScratch.legacy.react`: Legacy rules for targeting Scratch's supported web browsers with React
|
|
172
117
|
|
|
173
118
|
New projects should not use these rule sets. They may disappear in the future. Scratch did not use Prettier at this
|
|
174
119
|
time, so there is no legacy Prettier configuration.
|
|
175
120
|
|
|
121
|
+
Legacy Scratch projects usually `extend` more than one of these at a time, and potentially a different set per
|
|
122
|
+
subdirectory. To do that in this new flat configuration format:
|
|
123
|
+
|
|
124
|
+
```js
|
|
125
|
+
// scratch-gui/eslint.config.mjs
|
|
126
|
+
import { eslintConfigScratch } from 'eslint-config-scratch'
|
|
127
|
+
import { globalIgnores } from 'eslint/config'
|
|
128
|
+
import globals from 'globals'
|
|
129
|
+
|
|
130
|
+
export default eslintConfigScratch.config(
|
|
131
|
+
eslintConfigScratch.legacy.base,
|
|
132
|
+
eslintConfigScratch.legacy.es6,
|
|
133
|
+
{
|
|
134
|
+
files: ['src/**/*.js', 'src/**/*.jsx'],
|
|
135
|
+
extends: [eslintConfigScratch.legacy.react],
|
|
136
|
+
languageOptions: {
|
|
137
|
+
globals: globals.browser,
|
|
138
|
+
},
|
|
139
|
+
rules: {
|
|
140
|
+
// ...customized rules for `src/`...
|
|
141
|
+
},
|
|
142
|
+
// ...other settings for `src/`...
|
|
143
|
+
},
|
|
144
|
+
// ...settings for `test/`, etc...
|
|
145
|
+
globalIgnores(['dist/**/*']),
|
|
146
|
+
)
|
|
147
|
+
```
|
|
148
|
+
|
|
176
149
|
## Committing
|
|
177
150
|
|
|
178
151
|
This project uses [semantic release](https://github.com/semantic-release/semantic-release)
|
package/eslint.config.mjs
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { globalIgnores } from 'eslint/config'
|
|
2
|
+
import globals from 'globals'
|
|
3
|
+
import { eslintConfigScratch } from './lib/index.mjs'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
export default eslintConfigScratch.config(
|
|
6
|
+
eslintConfigScratch.recommended,
|
|
7
|
+
{
|
|
8
|
+
languageOptions: {
|
|
9
|
+
globals: globals.node,
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
globalIgnores(['test/**/*.bad.*']),
|
|
13
|
+
)
|