@pplancq/eslint-config 3.0.1 → 4.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/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ ## @pplancq/eslint-config [4.0.1](https://github.com/pplancq/dev-tools/compare/@pplancq/eslint-config@4.0.0...@pplancq/eslint-config@4.0.1) (2024-11-11)
2
+
3
+ ### Bug Fixes
4
+
5
+ * **deps:** update dependency eslint-plugin-jest to ^28.9.0 ([db2bb8d](https://github.com/pplancq/dev-tools/commit/db2bb8d283207659cf3db7f8636f70aef5dcfd0c))
6
+
7
+ ## @pplancq/eslint-config [4.0.0](https://github.com/pplancq/dev-tools/compare/@pplancq/eslint-config@3.0.1...@pplancq/eslint-config@4.0.0) (2024-11-08)
8
+
9
+ ### ⚠ BREAKING CHANGES
10
+
11
+ * **eslint-config:** this version support only eslint v9 with new flat configuration.\ Please refer to the Migration Guide for detailed instructions: [Migration Guide](./MIGRATION.md#migration-guide-pplancqeslint-config-v3-to-v4)
12
+
13
+ ### Features
14
+
15
+ * **eslint-config:** make factory for define eslint flat config ([4f5e261](https://github.com/pplancq/dev-tools/commit/4f5e26169d3258b2b0f0de982ae664e69317a6ee))
16
+ * **eslint-config:** migrate rule to flat config ([40fc36e](https://github.com/pplancq/dev-tools/commit/40fc36e6aac55baa634a55c4dd499c7ce4058dc1))
17
+ * **eslint-config:** update eslint v8 to v9 ([5cf5721](https://github.com/pplancq/dev-tools/commit/5cf57215c74172fd0f611c8425522d927752026e))
18
+ * **eslint-config:** update script to set default config ([16215da](https://github.com/pplancq/dev-tools/commit/16215da3e7c9cebc078f31cf5cc1b2006ee65634))
19
+
20
+ ### Bug Fixes
21
+
22
+ * **deps:** update dependency eslint-plugin-jsx-a11y to ^6.10.1 ([69f02a2](https://github.com/pplancq/dev-tools/commit/69f02a2f3cbf00ee75168b48345458c9effbeaf1))
23
+ * **deps:** update dependency eslint-plugin-jsx-a11y to ^6.10.2 ([cd2bf08](https://github.com/pplancq/dev-tools/commit/cd2bf08034f8bca2d62d6a1d5d366a9d424e9ab9))
24
+ * **deps:** update dependency eslint-plugin-react to ^7.37.2 ([c57c4a6](https://github.com/pplancq/dev-tools/commit/c57c4a6cc78bd0d8fa627f015acc6bc92dea59d1))
25
+ * **deps:** update dependency eslint-plugin-testing-library to ^6.4.0 ([94274e0](https://github.com/pplancq/dev-tools/commit/94274e08effe5bbf59f37f4213b21cb0bb293690))
26
+
1
27
  ## @pplancq/eslint-config [3.0.1](https://github.com/pplancq/dev-tools/compare/@pplancq/eslint-config@3.0.0...@pplancq/eslint-config@3.0.1) (2024-10-15)
2
28
 
3
29
  ### Bug Fixes
package/MIGRATION.md ADDED
@@ -0,0 +1,52 @@
1
+ # Migration Guide v3 to v4
2
+
3
+ This guide will help you migrate from version 3 to version 4 of the `@pplancq/eslint-config` package, which now supports ESLint 9 and the new flat configuration.
4
+
5
+ ## Steps to Migrate
6
+
7
+ ### 1. Update ESLint and Install the New Configuration
8
+
9
+ First, update ESLint to version 9 and install the new version of the configuration package:
10
+
11
+ ```shell
12
+ npm install --save-dev eslint@9 @pplancq/eslint-config@4
13
+ ```
14
+
15
+ ### 2. Remove Legacy Configuration
16
+
17
+ Remove the legacy ESLint configuration from your `package.json` or `.eslintrc` file. For example, if you have the following in your `package.json`:
18
+
19
+ ```json
20
+ {
21
+ "eslintConfig": {
22
+ "extends": ["@pplancq/eslint-config/react"]
23
+ }
24
+ }
25
+ ```
26
+
27
+ Remove this section entirely.
28
+
29
+ ### 3. Create New Configuration File
30
+
31
+ Create a new `eslint.config.mjs` file in the root of your project:
32
+
33
+ ```javascript
34
+ // eslint.config.mjs
35
+ import { defineConfig } from '@pplancq/eslint-config';
36
+
37
+ export default defineConfig({
38
+ enableReact: true,
39
+ });
40
+ ```
41
+
42
+ ### 4. Adjust Configuration Options
43
+
44
+ Review and adjust the configuration options as needed. For detailed information on all available options, please refer to the [README](./README.md).
45
+
46
+ ### Configuration Equivalents
47
+
48
+ - `@pplancq/eslint-config/node` is equivalent to `defineConfig()`.
49
+ - To use `@pplancq/eslint-config/react`, set the `enableReact` option to `true`.
50
+ - To use `@pplancq/eslint-config/vitest`, set the `enableVitest` option to `true`.
51
+ - To use `@pplancq/eslint-config/jest`, set the `enableJest` option to `true`.
52
+ - To use `@pplancq/eslint-config/prettier`, set the `enablePrettier` option to `'on'`.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @pplancq/eslint-config
2
2
 
3
- This package has been designed to provide a simplified and customizable ESLint configuration for your React/Node.js applications. Whether you are a beginner or an experienced developer, this package will help you configure ESLint with strict rules to ensure better code structure. Based on Airbnb’s ESLint configuration, this package includes additional rules for TypeScript files and test files.
3
+ This package provides a simplified and customizable ESLint configuration for your React/Node.js applications. Whether you are a beginner or an experienced developer, this package helps you configure ESLint with strict rules to ensure better code structure. Based on Airbnb’s ESLint configuration, it includes additional rules for TypeScript files and test files.
4
4
 
5
5
  ## Getting Started
6
6
 
@@ -11,79 +11,55 @@ This package has been designed to provide a simplified and customizable ESLint c
11
11
  ### Installation
12
12
 
13
13
  ```shell
14
- npm install --save-dev eslint@8 @pplancq/eslint-config
14
+ npm install --save-dev eslint@9 @pplancq/eslint-config
15
15
  ```
16
16
 
17
- ## ESLint Configuration
17
+ ## Usage
18
18
 
19
- Use the following command to enable the default configuration:
19
+ ### Automatic Configuration
20
+
21
+ To enable the default configuration automatically, use the following command:
20
22
 
21
23
  ```shell
22
24
  npx init-eslint-config
23
25
  ```
24
26
 
25
- ### @pplancq/eslint-config/react
26
-
27
- To use, add the following to your `package.json`:
28
-
29
- ```json
30
- {
31
- "eslintConfig": { "extends": ["@pplancq/eslint-config/react"] }
32
- }
33
- ```
34
-
35
- This configuration enables the rules for base, TypeScript, React, and Testing Library files.
27
+ ### Manual Configuration
36
28
 
37
- ### @pplancq/eslint-config/node
29
+ Alternatively, you can create an `eslint.config.mjs` file in the root of your project:
38
30
 
39
- To use, add the following to your `package.json`:
31
+ ```javascript
32
+ // eslint.config.mjs
33
+ import { defineConfig } from '@pplancq/eslint-config';
40
34
 
41
- ```json
42
- {
43
- "eslintConfig": { "extends": ["@pplancq/eslint-config/node"] }
44
- }
35
+ export default defineConfig({
36
+ enableReact: true,
37
+ enableVitest: true,
38
+ });
45
39
  ```
46
40
 
47
- This configuration enables the rules for base and TypeScript files.
41
+ ### Options
48
42
 
49
- ### @pplancq/eslint-config/vitest
43
+ The following options can be passed to the `defineConfig` function. All options are optional. By default, this configuration includes rules for base, import, and TypeScript files.
50
44
 
51
- To use, add the following to your `package.json`:
45
+ | Option | Default | Description |
46
+ | -------------- | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
47
+ | tsFiles | ['**/*.ts?(x)'] | Patterns for TypeScript files |
48
+ | unitTestFiles | ['**/*.{test,spec,steps}.{js,jsx,ts,tsx}'] | Patterns for unit test files |
49
+ | enableReact | false | Enables rules for React and Testing Library files |
50
+ | enableVitest | false | Enables rules for Vitest files |
51
+ | enableJest | false | Enables rules for Jest files |
52
+ | enablePrettier | 'off' | 'off' disables Prettier rules<br/>'on' enables Prettier rules<br/>'disableStyleOnly' enables Prettier rules but disables the 'prettier/prettier' rule, not using Prettier CLI for formatting your code |
53
+ | extendConfig | [] | Extends the ESLint configuration |
52
54
 
53
- ```json
54
- {
55
- "eslintConfig": { "extends": ["@pplancq/eslint-config/vitest"] }
56
- }
57
- ```
58
-
59
- This configuration enables the rules for Vitest files.
60
-
61
- ### @pplancq/eslint-config/jest
55
+ ### Prettier Configuration
62
56
 
63
- To use, add the following to your `package.json`:
64
-
65
- ```json
66
- {
67
- "eslintConfig": { "extends": ["@pplancq/eslint-config/jest"] }
68
- }
69
- ```
70
-
71
- This configuration enables the rules for Jest files.
72
-
73
- ### @pplancq/eslint-config/prettier
74
-
75
- To use, add the following to your `package.json`:
76
-
77
- ```json
78
- {
79
- "eslintConfig": { "extends": ["@pplancq/eslint-config/prettier"] }
80
- }
81
- ```
82
-
83
- This configuration enables the rules for Prettier files.
84
-
85
- You will need to install the following packages:
57
+ If you set `enablePrettier: 'on'`, you will need to install the following packages:
86
58
 
87
59
  ```shell
88
60
  npm install --save-dev prettier eslint-plugin-prettier
89
61
  ```
62
+
63
+ ## Migration
64
+
65
+ If you are upgrading from version 3 to version 4 of `@pplancq/eslint-config`, please refer to the [Migration Guide](./MIGRATION.md#migration-guide-pplancqeslint-config-v3-to-v4) for detailed instructions.
package/bin/init.js CHANGED
@@ -1,11 +1,16 @@
1
1
  #!/usr/bin/env node
2
2
  const { writeFileSync } = require('fs');
3
3
 
4
- console.info('Add eslint config in .eslintrc.js');
4
+ console.info('Add eslint config in eslint.config.mjs');
5
5
 
6
6
  writeFileSync(
7
- '.eslintrc.js',
8
- "module.exports = { extends: ['@pplancq/eslint-config/react', '@pplancq/eslint-config/vitest'] };\n",
7
+ 'eslint.config.mjs',
8
+ "import { defineConfig } from '@pplancq/eslint-config';\n" +
9
+ '\n' +
10
+ 'export default defineConfig({\n' +
11
+ ' enableReact: true,\n' +
12
+ ' enableVitest: true,\n' +
13
+ '});\n',
9
14
  {
10
15
  encoding: 'utf-8',
11
16
  },
package/main.js ADDED
@@ -0,0 +1,67 @@
1
+ const { baseRules } = require('./rules/base');
2
+ const { importRules } = require('./rules/import');
3
+ const { reactJsxA11yRules } = require('./rules/react-jsx-a11y');
4
+ const { reactRules, reactTypescriptRules, reactTestRules } = require('./rules/react');
5
+ const { typescriptRules } = require('./rules/typescript');
6
+ const { prettierRules } = require('./rules/prettier');
7
+ const { vitestRules } = require('./rules/vitest');
8
+ const { jestRules } = require('./rules/jest');
9
+
10
+ /**
11
+ * define eslint flat config.
12
+ *
13
+ * @param {Object} options
14
+ * @param {string[]} [options.tsFiles=['**\/*.ts?(x)']]
15
+ * @param {string[]} [options.unitTestFiles=['**\/*.{test,spec,steps}.{js,jsx,ts,tsx}']]
16
+ * @param {boolean} [options.enableReact=false]
17
+ * @param {boolean} [options.enableVitest=false]
18
+ * @param {boolean} [options.enableJest=false]
19
+ * @param {'off' | 'on' | 'disableStyleOnly'} [options.enablePrettier='on']
20
+ * @param {Array<import('eslint').Linter.Config>} [options.extendConfig=[]]
21
+ *
22
+ * @returns {import('eslint').Linter.Config}
23
+ */
24
+ const defineConfig = ({
25
+ tsFiles = ['**/*.ts?(x)'],
26
+ unitTestFiles = ['**/*.{test,spec,steps}.{js,jsx,ts,tsx}'],
27
+ enableReact = false,
28
+ enableVitest = false,
29
+ enableJest = false,
30
+ enablePrettier = 'off',
31
+ extendConfig = [],
32
+ } = {}) => {
33
+ typescriptRules.files = tsFiles;
34
+ reactTypescriptRules.files = tsFiles;
35
+ reactTestRules.files = unitTestFiles;
36
+ vitestRules.files = unitTestFiles;
37
+ jestRules.files = unitTestFiles;
38
+
39
+ if (enablePrettier === 'disableStyleOnly') {
40
+ prettierRules.rules['prettier/prettier'] = 'off';
41
+ }
42
+
43
+ return [
44
+ importRules,
45
+ baseRules,
46
+ enableReact && reactJsxA11yRules,
47
+ typescriptRules,
48
+ enableReact && reactRules,
49
+ enableReact && reactTypescriptRules,
50
+ enableReact && reactTestRules,
51
+ enablePrettier !== 'off' && prettierRules,
52
+ enableVitest && vitestRules,
53
+ enableJest && jestRules,
54
+ {
55
+ files: ['eslint.config.*'],
56
+ rules: {
57
+ 'import/no-extraneous-dependencies': 'off',
58
+ 'import/no-default-export': 'off',
59
+ },
60
+ },
61
+ ...extendConfig,
62
+ ].filter(Boolean);
63
+ };
64
+
65
+ module.exports = {
66
+ defineConfig,
67
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pplancq/eslint-config",
3
- "version": "3.0.1",
3
+ "version": "4.0.1",
4
4
  "license": "MIT",
5
5
  "description": "pplancq eslint config",
6
6
  "author": "pplancq <paul.plancq@outlook.fr>",
@@ -12,13 +12,7 @@
12
12
  "bugs": {
13
13
  "url": "https://github.com/pplancq/dev-tools/issues"
14
14
  },
15
- "exports": {
16
- "./node": "./node.js",
17
- "./react": "./react.js",
18
- "./jest": "./jest.js",
19
- "./vitest": "./vitest.js",
20
- "./prettier": "./prettier.js"
21
- },
15
+ "main": "main.js",
22
16
  "bin": {
23
17
  "init-eslint-config": "./bin/init.js"
24
18
  },
@@ -27,21 +21,22 @@
27
21
  "config"
28
22
  ],
29
23
  "dependencies": {
30
- "@typescript-eslint/eslint-plugin": "^8.8.1",
31
- "@typescript-eslint/parser": "^8.8.1",
24
+ "@typescript-eslint/eslint-plugin": "^8.13.0",
25
+ "@typescript-eslint/parser": "^8.13.0",
32
26
  "@vitest/eslint-plugin": "^1.1.7",
33
27
  "eslint-import-resolver-typescript": "^3.6.3",
34
28
  "eslint-plugin-import": "^2.31.0",
35
- "eslint-plugin-jest": "^28.8.3",
29
+ "eslint-plugin-jest": "^28.9.0",
36
30
  "eslint-plugin-jest-dom": "^5.4.0",
37
31
  "eslint-plugin-jest-extended": "^2.4.0",
38
- "eslint-plugin-jsx-a11y": "^6.10.0",
39
- "eslint-plugin-react": "^7.37.1",
40
- "eslint-plugin-react-hooks": "^4.6.2",
41
- "eslint-plugin-testing-library": "^6.3.0"
32
+ "eslint-plugin-jsx-a11y": "^6.10.2",
33
+ "eslint-plugin-react": "^7.37.2",
34
+ "eslint-plugin-react-hooks": "^5.0.0",
35
+ "eslint-plugin-testing-library": "^6.4.0",
36
+ "globals": "^15.12.0"
42
37
  },
43
38
  "peerDependencies": {
44
- "eslint": "^8.57.0",
39
+ "eslint": "^9.14.0",
45
40
  "eslint-plugin-prettier": "^5.0.1",
46
41
  "prettier": "^3.2.5"
47
42
  },
package/rules/base.js CHANGED
@@ -1,17 +1,20 @@
1
- module.exports = {
2
- extends: ['./import.js'],
3
- parserOptions: {
1
+ const globals = require('globals');
2
+
3
+ const baseRules = {
4
+ languageOptions: {
4
5
  ecmaVersion: 'latest',
5
6
  sourceType: 'module',
6
- ecmaFeatures: {
7
- generators: false,
8
- objectLiteralDuplicateProperties: false,
7
+ parserOptions: {
8
+ ecmaFeatures: {
9
+ generators: false,
10
+ objectLiteralDuplicateProperties: false,
11
+ },
12
+ },
13
+ globals: {
14
+ ...globals.browser,
15
+ ...globals.node,
16
+ ...globals.es2025,
9
17
  },
10
- },
11
- env: {
12
- browser: true,
13
- node: true,
14
- es6: true,
15
18
  },
16
19
  rules: {
17
20
  // eslint https://eslint.org
@@ -1453,3 +1456,7 @@ module.exports = {
1453
1456
  'yield-star-spacing': ['error', 'after'],
1454
1457
  },
1455
1458
  };
1459
+
1460
+ module.exports = {
1461
+ baseRules,
1462
+ };
package/rules/import.js CHANGED
@@ -1,11 +1,15 @@
1
- module.exports = {
2
- plugins: ['import'],
3
- parserOptions: {
1
+ const importPlugin = require('eslint-plugin-import');
2
+
3
+ const importRules = {
4
+ plugins: {
5
+ import: importPlugin,
6
+ },
7
+ languageOptions: {
4
8
  ecmaVersion: 'latest',
5
9
  sourceType: 'module',
6
- },
7
- env: {
8
- es6: true,
10
+ globals: {
11
+ es6: true,
12
+ },
9
13
  },
10
14
  rules: {
11
15
  // eslint-plugin-import https://github.com/import-js/eslint-plugin-import
@@ -272,3 +276,7 @@ module.exports = {
272
276
  },
273
277
  },
274
278
  };
279
+
280
+ module.exports = {
281
+ importRules,
282
+ };