@ivuorinen/eslint-config 1.5.17 → 2.0.1

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/README.md CHANGED
@@ -26,24 +26,50 @@ npm install @ivuorinen/eslint-config --save-dev
26
26
  yarn add @ivuorinen/eslint-config --dev
27
27
  ```
28
28
 
29
- After installing it, a _`eslint.config.mjs`_ file will be created automatically in the project's root folder with the following configuration:
30
-
31
- ```json
32
- {
33
- "extends": ["@ivuorinen"]
34
- }
29
+ This package is a [flat config][flat-config-link] for ESLint 10, which no longer reads `.eslintrc*` files. Create an
30
+ _`eslint.config.mjs`_ in the project's root folder:
31
+
32
+ ```js
33
+ import ivuorinenConfig from '@ivuorinen/eslint-config'
34
+
35
+ export default [
36
+ ...ivuorinenConfig,
37
+
38
+ // your modifications
39
+ {
40
+ rules: {
41
+ // "no-unused-vars": "warn"
42
+ }
43
+ }
44
+ ]
35
45
  ```
36
46
 
47
+ With npm, a `postinstall` script writes exactly this file when the project has no ESLint config yet (npm 11 warns
48
+ that the script is not covered by `allowScripts`). Yarn 4 does not run dependency install scripts, so no file is
49
+ written. pnpm refuses unapproved install scripts and fails the install until you allow this package with
50
+ `pnpm approve-builds` (or list it in `onlyBuiltDependencies`). In both cases create the file by hand as above.
51
+
37
52
  ## Available Configurations
38
53
 
39
54
  ### Jest
40
55
 
41
- Adds specific rules for the [`Jest`][jest-link] testing framework.
56
+ Adds specific rules for the [`Jest`][jest-link] testing framework. Every element is scoped to test files
57
+ (`**/*.{test,spec}.{js,mjs,cjs}` and `**/__tests__/**`), so it can be spread next to the base config:
58
+
59
+ ```js
60
+ import ivuorinenConfig from '@ivuorinen/eslint-config'
61
+ import ivuorinenJest from '@ivuorinen/eslint-config/jest'
62
+
63
+ export default [...ivuorinenConfig, ...ivuorinenJest]
64
+ ```
65
+
66
+ To use a different test-file pattern, override `files` on each element:
42
67
 
43
- ```json
44
- {
45
- "extends": ["@ivuorinen/eslint-config/jest"]
46
- }
68
+ ```js
69
+ export default [
70
+ ...ivuorinenConfig,
71
+ ...ivuorinenJest.map(config => ({ ...config, files: ['test/**/*.js'] }))
72
+ ]
47
73
  ```
48
74
 
49
75
  ## Documentations
@@ -52,7 +78,7 @@ Read the [ESLint docs][eslint-docs-link] for more information.
52
78
 
53
79
  ## Contributing
54
80
 
55
- If you are interested in helping contribute, please take a look at our [contribution guidelines][contributing-link] and open an [issue][issue-link] or [pull request][pull-request-link].
81
+ If you are interested in helping contribute, please open an [issue][issue-link] or [pull request][pull-request-link].
56
82
 
57
83
  ## Changelog
58
84
 
@@ -65,7 +91,7 @@ Distributed under the MIT License. See [LICENSE][license-link] for more informat
65
91
  [changelog-link]: https://github.com/ivuorinen/base-configs-eslint/releases
66
92
  [eslint-docs-link]: https://eslint.org
67
93
  [eslint-link]: https://github.com/eslint/eslint
68
- [contributing-link]: https://github.com/ivuorinen/.github/blob/main/CONTRIBUTING.md
94
+ [flat-config-link]: https://eslint.org/docs/latest/use/configure/configuration-files
69
95
  [issue-link]: https://github.com/ivuorinen/base-configs-eslint/issues
70
96
  [license-badge]: https://img.shields.io/github/license/ivuorinen/base-configs-eslint?style=flat-square&labelColor=292a44&color=663399
71
97
  [license-link]: ./LICENSE.md
package/index.cjs CHANGED
@@ -33,9 +33,9 @@ module.exports = [
33
33
  ...globals.es2021,
34
34
  ...globals.node,
35
35
  },
36
- parserOptions: {
37
- ecmaVersion: 12,
38
- },
36
+ // No ecmaVersion override: flat config defaults to "latest". Pinning an
37
+ // older version turns newer syntax (class private fields, top-level
38
+ // await) into a fatal parse error, which runs no rules on the file.
39
39
  },
40
40
  },
41
41
  pluginJs.configs.recommended,
package/jest.cjs CHANGED
@@ -2,27 +2,25 @@
2
2
 
3
3
  const jest = require("eslint-plugin-jest");
4
4
 
5
+ // Every element is scoped to test files. eslint-plugin-jest's flat configs
6
+ // carry no `files` of their own, so spreading them unscoped would apply Jest
7
+ // globals and rules to production code, where a stray `describe(` or `expect(`
8
+ // should still be reported by no-undef.
9
+ const files = ["**/*.{test,spec}.{js,mjs,cjs}", "**/__tests__/**/*.{js,mjs,cjs}"];
10
+
5
11
  /**
6
12
  * eslint configuration for jest.
7
13
  * @type { import('eslint').Linter.Config[] } config
8
14
  */
9
15
  module.exports = [
10
16
  {
11
- files: ["**/*.{js,mjs,cjs}"],
17
+ files,
12
18
  languageOptions: {
13
19
  globals: {
14
20
  ...jest.globals,
15
21
  },
16
22
  },
17
23
  },
18
- jest.configs["flat/recommended"],
19
- jest.configs["flat/style"],
20
- {
21
- rules: {
22
- ...jest.configs["flat/recommended"].rules,
23
- },
24
- plugins: {
25
- jest,
26
- },
27
- },
24
+ { ...jest.configs["flat/recommended"], files },
25
+ { ...jest.configs["flat/style"], files },
28
26
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ivuorinen/eslint-config",
3
- "version": "1.5.17",
3
+ "version": "2.0.1",
4
4
  "description": "ivuorinen's shareable configuration for ESLint.",
5
5
  "author": {
6
6
  "name": "Ismo Vuorinen",
@@ -10,7 +10,7 @@
10
10
  "url": "https://github.com/ivuorinen/base-configs-eslint/issues"
11
11
  },
12
12
  "engines": {
13
- "node": "^20.9.0 || >=21.1.0"
13
+ "node": "^20.19.0 || ^22.13.0 || >=24"
14
14
  },
15
15
  "type": "module",
16
16
  "main": "index.cjs",
@@ -49,7 +49,6 @@
49
49
  },
50
50
  "scripts": {
51
51
  "postinstall": "node scripts/postinstall.cjs",
52
- "semantic-release": "semantic-release --ci",
53
52
  "test": "vitest run",
54
53
  "test:watch": "vitest"
55
54
  },
@@ -60,14 +59,13 @@
60
59
  "eslint-config-eslint": "^14.0.0",
61
60
  "eslint-config-prettier": "^10.1.8",
62
61
  "eslint-plugin-jest": "^29.15.1",
63
- "globals": "^17.4.0",
64
- "typescript": ">=4.2.0"
62
+ "globals": "^17.4.0"
65
63
  },
66
64
  "devDependencies": {
67
- "@ivuorinen/semantic-release-config": "^2.0.0",
65
+ "@ivuorinen/semantic-release-config": "^3.0.0",
68
66
  "vitest": "^4.1.2"
69
67
  },
70
- "packageManager": "yarn@4.18.0",
68
+ "packageManager": "yarn@4.18.1",
71
69
  "resolutions": {
72
70
  "brace-expansion": "^5.0.5",
73
71
  "picomatch": "^4.0.4",
@@ -6,7 +6,14 @@ const fs = require("node:fs");
6
6
  const path = require("node:path");
7
7
  const process = require("node:process");
8
8
  const checkConfig = require("@ivuorinen/config-checker");
9
- const foundConfig = checkConfig("eslint");
9
+
10
+ // This runs on every consumer install, and a non-zero exit fails that whole
11
+ // install. The starter config is a convenience, so every step below degrades to
12
+ // a message instead of throwing.
13
+
14
+ // INIT_CWD is an npm/yarn convention, not a guarantee.
15
+ const cwd = process.env.INIT_CWD || process.cwd();
16
+ const foundConfig = checkConfig("eslint", cwd);
10
17
 
11
18
  if (foundConfig.length > 0) {
12
19
  console.log("eslint-config: Found existing eslint config file, skipping creation.");
@@ -15,7 +22,7 @@ if (foundConfig.length > 0) {
15
22
  process.exit(0);
16
23
  }
17
24
 
18
- const filePath = path.join(process.env.INIT_CWD, "eslint.config.mjs");
25
+ const filePath = path.join(cwd, "eslint.config.mjs");
19
26
  const fileConfig = `import ivuorinenConfig from '@ivuorinen/eslint-config';
20
27
 
21
28
  export default [
@@ -30,6 +37,13 @@ export default [
30
37
  ];
31
38
  `;
32
39
 
33
- if (!fs.existsSync(filePath)) {
34
- fs.writeFileSync(filePath, fileConfig);
40
+ // "wx" makes "does it exist?" and "write it" one atomic step, so a concurrent
41
+ // install cannot create the file in between and have it overwritten.
42
+ try {
43
+ fs.writeFileSync(filePath, fileConfig, { flag: "wx" });
44
+ } catch (error) {
45
+ if (error.code !== "EEXIST") {
46
+ console.log(`eslint-config: could not write ${filePath} (${error.code || error.message}).`);
47
+ console.log("eslint-config: create it manually and spread @ivuorinen/eslint-config into its export.");
48
+ }
35
49
  }