@r2d2bzh/eslint-config 2.1.3 → 3.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.
Files changed (3) hide show
  1. package/README.adoc +4 -1
  2. package/index.js +110 -71
  3. package/package.json +22 -12
package/README.adoc CHANGED
@@ -39,8 +39,11 @@ export default defineConfig([
39
39
  ]);
40
40
  ----
41
41
 
42
+ This configuration lints both JavaScript (`*.js`, `*.cjs`, `*.mjs`) and TypeScript (`*.ts`, `*.cts`, `*.mts`, `*.tsx`) files.
43
+
42
44
  WARNING: This package has peer dependencies that you need to install manually.
43
45
  This is to follow https://eslint.org/docs/developer-guide/shareable-configs#publishing-a-shareable-config[eslint recommendations].
46
+ For TypeScript support, `typescript` is an optional peer dependency that you only need to install in TypeScript projects.
44
47
 
45
48
  == Ensuring linting
46
49
 
@@ -53,7 +56,7 @@ To ensure that the eslint rules are followed, the current recommendation is to a
53
56
  ----
54
57
  {
55
58
  "eslint-staged": {
56
- "*.js": ["eslint"]
59
+ "*.{js,cjs,mjs,ts,cts,mts,tsx}": ["eslint"]
57
60
  },
58
61
  "husky": {
59
62
  "hooks": {
package/index.js CHANGED
@@ -1,18 +1,101 @@
1
1
  import { defineConfig, globalIgnores } from 'eslint/config';
2
2
  import js from '@eslint/js';
3
3
  import globals from 'globals';
4
+ import tseslint from 'typescript-eslint';
4
5
 
5
6
  import eslintPluginPrettier from 'eslint-plugin-prettier/recommended';
6
7
  import eslintPluginAva from 'eslint-plugin-ava';
7
- import eslintPluginImport from 'eslint-plugin-import';
8
+ import eslintPluginImportX, { flatConfigs as eslintPluginImportXConfigs } from 'eslint-plugin-import-x';
8
9
  import eslintPluginPromise from 'eslint-plugin-promise';
9
10
  import eslintPluginSecurity from 'eslint-plugin-security';
10
11
  import eslintPluginUnicorn from 'eslint-plugin-unicorn';
11
12
 
13
+ // tag::rules[]
14
+ const rules = {
15
+ ...eslintPluginAva.configs.recommended.rules,
16
+ ...eslintPluginImportXConfigs.recommended.rules,
17
+ ...eslintPluginPromise.configs.recommended.rules,
18
+ ...eslintPluginSecurity.configs.recommended.rules,
19
+ ...eslintPluginUnicorn.configs.recommended.rules,
20
+ // https://prettier.io/docs/en/integrating-with-linters.html#use-eslint-to-run-prettier
21
+ // https://github.com/prettier/eslint-plugin-prettier#options
22
+ 'prettier/prettier': [
23
+ 'error',
24
+ // https://prettier.io/docs/en/configuration.html#basic-configuration
25
+ {
26
+ // https://prettier.io/docs/en/options.html#quotes
27
+ singleQuote: true,
28
+ // https://prettier.io/docs/en/options.html#semicolons
29
+ semi: true,
30
+ // https://prettier.io/docs/en/options.html#tab-width
31
+ tabWidth: 2,
32
+ // https://prettier.io/docs/en/options.html#print-width
33
+ printWidth: 120,
34
+ },
35
+ ],
36
+ // https://eslint.org/docs/rules/no-unused-vars#ignorerestsiblings
37
+ 'no-unused-vars': ['error', { ignoreRestSiblings: true }],
38
+ // https://eslint.org/docs/rules/prefer-const
39
+ 'prefer-const': 'error',
40
+ // https://eslint.org/docs/rules/no-alert
41
+ 'no-alert': 'error',
42
+ // https://eslint.org/docs/rules/no-console
43
+ 'no-console': 'error',
44
+ // https://eslint.org/docs/rules/no-var
45
+ 'no-var': 'error',
46
+ // https://eslint.org/docs/rules/linebreak-style
47
+ 'linebreak-style': ['error', 'unix'],
48
+ // https://eslint.org/docs/rules/complexity
49
+ complexity: ['error', { max: 20 }],
50
+ // https://eslint.org/docs/rules/max-statements
51
+ 'max-statements': ['error', { max: 15 }],
52
+ // https://eslint.org/docs/rules/max-statements-per-line
53
+ 'max-statements-per-line': ['error', { max: 1 }],
54
+ // https://eslint.org/docs/rules/max-nested-callbacks
55
+ 'max-nested-callbacks': ['error', { max: 3 }],
56
+ // https://eslint.org/docs/rules/max-depth
57
+ 'max-depth': ['error', { max: 4 }],
58
+ // https://eslint.org/docs/rules/max-params
59
+ 'max-params': ['error', { max: 3 }],
60
+ // https://eslint.org/docs/rules/no-nested-ternary
61
+ 'no-nested-ternary': 'error',
62
+ // https://eslint.org/docs/rules/no-trailing-spaces
63
+ 'no-trailing-spaces': 'error',
64
+ // https://eslint.org/docs/rules/one-var
65
+ 'one-var': ['error', 'never'],
66
+ // https://github.com/avajs/eslint-plugin-ava/blob/main/docs/rules/prefer-power-assert.md
67
+ 'ava/prefer-power-assert': 'warn',
68
+ // https://github.com/import-js/eslint-plugin-import/issues/2703
69
+ 'import-x/no-unresolved': 'off',
70
+ 'unicorn/filename-case': [
71
+ 'error',
72
+ {
73
+ ignore: ['__tests__'],
74
+ multipleFileExtensions: false,
75
+ }
76
+ ],
77
+ // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v52.0.0/docs/rules/no-anonymous-default-export.md
78
+ 'unicorn/no-anonymous-default-export': 'off',
79
+ };
80
+ // end::rules[]
81
+
82
+ const plugins = {
83
+ ava: eslintPluginAva,
84
+ 'import-x': eslintPluginImportX,
85
+ promise: eslintPluginPromise,
86
+ security: eslintPluginSecurity,
87
+ unicorn: eslintPluginUnicorn,
88
+ js,
89
+ };
90
+
91
+ const settings = {
92
+ 'import-x/core-modules': ['ava'],
93
+ };
94
+
12
95
  export default defineConfig([
13
- globalIgnores(['**/node_modules', '**/coverage', '/__tests__']),
96
+ globalIgnores(['**/node_modules', '**/coverage', '/__tests__', '**/vendor.d.ts']),
14
97
  {
15
- files: ['**/*.js'],
98
+ files: ['**/*.js', '**/*.cjs', '**/*.mjs'],
16
99
  extends: ['js/recommended'],
17
100
  languageOptions: {
18
101
  ecmaVersion: 'latest',
@@ -21,78 +104,34 @@ export default defineConfig([
21
104
  ...globals.node,
22
105
  },
23
106
  },
24
- // tag::rules[]
107
+ rules,
108
+ plugins,
109
+ settings,
110
+ },
111
+ {
112
+ files: ['**/*.ts', '**/*.cts', '**/*.mts', '**/*.tsx'],
113
+ extends: ['js/recommended', tseslint.configs.recommended],
114
+ languageOptions: {
115
+ ecmaVersion: 'latest',
116
+ sourceType: 'module',
117
+ parser: tseslint.parser,
118
+ globals: {
119
+ ...globals.node,
120
+ },
121
+ },
122
+ // tag::ts-rules[]
25
123
  rules: {
26
- ...eslintPluginAva.configs.recommended.rules,
27
- ...eslintPluginImport.configs.recommended.rules,
28
- ...eslintPluginPromise.configs.recommended.rules,
29
- ...eslintPluginSecurity.configs.recommended.rules,
30
- ...eslintPluginUnicorn.configs.recommended.rules,
31
- // https://prettier.io/docs/en/integrating-with-linters.html#use-eslint-to-run-prettier
32
- // https://github.com/prettier/eslint-plugin-prettier#options
33
- 'prettier/prettier': [
34
- 'error',
35
- // https://prettier.io/docs/en/configuration.html#basic-configuration
36
- {
37
- // https://prettier.io/docs/en/options.html#quotes
38
- singleQuote: true,
39
- // https://prettier.io/docs/en/options.html#semicolons
40
- semi: true,
41
- // https://prettier.io/docs/en/options.html#tab-width
42
- tabWidth: 2,
43
- // https://prettier.io/docs/en/options.html#print-width
44
- printWidth: 120,
45
- },
46
- ],
47
- // https://eslint.org/docs/rules/no-unused-vars#ignorerestsiblings
48
- 'no-unused-vars': ['error', { ignoreRestSiblings: true }],
49
- // https://eslint.org/docs/rules/prefer-const
50
- 'prefer-const': 'error',
51
- // https://eslint.org/docs/rules/no-alert
52
- 'no-alert': 'error',
53
- // https://eslint.org/docs/rules/no-console
54
- 'no-console': 'error',
55
- // https://eslint.org/docs/rules/no-var
56
- 'no-var': 'error',
57
- // https://eslint.org/docs/rules/linebreak-style
58
- 'linebreak-style': ['error', 'unix'],
59
- // https://eslint.org/docs/rules/complexity
60
- complexity: ['error', { max: 20 }],
61
- // https://eslint.org/docs/rules/max-statements
62
- 'max-statements': ['error', { max: 15 }],
63
- // https://eslint.org/docs/rules/max-statements-per-line
64
- 'max-statements-per-line': ['error', { max: 1 }],
65
- // https://eslint.org/docs/rules/max-nested-callbacks
66
- 'max-nested-callbacks': ['error', { max: 3 }],
67
- // https://eslint.org/docs/rules/max-depth
68
- 'max-depth': ['error', { max: 4 }],
69
- // https://eslint.org/docs/rules/max-params
70
- 'max-params': ['error', { max: 3 }],
71
- // https://eslint.org/docs/rules/no-nested-ternary
72
- 'no-nested-ternary': 'error',
73
- // https://eslint.org/docs/rules/no-trailing-spaces
74
- 'no-trailing-spaces': 'error',
75
- // https://eslint.org/docs/rules/one-var
76
- 'one-var': ['error', 'never'],
77
- // https://github.com/avajs/eslint-plugin-ava/blob/main/docs/rules/prefer-power-assert.md
78
- 'ava/prefer-power-assert': 'warn',
79
- // https://github.com/import-js/eslint-plugin-import/issues/2703
80
- 'import/no-unresolved': 'off',
81
- // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v52.0.0/docs/rules/no-anonymous-default-export.md
82
- 'unicorn/no-anonymous-default-export': 'off',
124
+ ...rules,
125
+ // The base no-unused-vars rule is disabled in favour of the TypeScript-aware one.
126
+ // https://typescript-eslint.io/rules/no-unused-vars/
127
+ '@typescript-eslint/no-unused-vars': ['error', { ignoreRestSiblings: true }],
83
128
  },
84
- // end::rules[]
129
+ // end::ts-rules[]
85
130
  plugins: {
86
- ava: eslintPluginAva,
87
- import: eslintPluginImport,
88
- promise: eslintPluginPromise,
89
- security: eslintPluginSecurity,
90
- unicorn: eslintPluginUnicorn,
91
- js
92
- },
93
- settings: {
94
- 'import/core-modules': ['ava'],
131
+ ...plugins,
132
+ '@typescript-eslint': tseslint.plugin,
95
133
  },
134
+ settings,
96
135
  },
97
136
  eslintPluginPrettier,
98
137
  ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r2d2bzh/eslint-config",
3
- "version": "2.1.3",
3
+ "version": "3.0.1",
4
4
  "description": "r2d2bzh eslint configuration",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -23,21 +23,31 @@
23
23
  "access": "public"
24
24
  },
25
25
  "dependencies": {
26
- "@eslint/eslintrc": "^3.3.1",
27
- "@eslint/js": "^9.34.0",
26
+ "@eslint/eslintrc": "^3.3.5",
27
+ "@eslint/js": "^10.0.1",
28
28
  "eslint-config-prettier": "^10.1.8",
29
- "eslint-plugin-ava": "^15.1.0",
30
- "eslint-plugin-import": "^2.32.0",
31
- "eslint-plugin-prettier": "^5.5.4",
32
- "eslint-plugin-promise": "^7.2.1",
33
- "eslint-plugin-security": "^3.0.1",
34
- "eslint-plugin-unicorn": "^60.0.0"
29
+ "eslint-plugin-ava": "^17.0.1",
30
+ "eslint-plugin-import-x": "^4.16.2",
31
+ "eslint-plugin-prettier": "^5.5.6",
32
+ "eslint-plugin-promise": "^7.3.0",
33
+ "eslint-plugin-security": "^4.0.1",
34
+ "eslint-plugin-unicorn": "^67.0.0",
35
+ "globals": "^17.6.0",
36
+ "typescript-eslint": "^8.61.1"
35
37
  },
36
38
  "devDependencies": {
37
- "release-it": "^19.0.4",
38
- "@release-it/conventional-changelog": "10.0.1"
39
+ "release-it": "^20.2.0",
40
+ "@release-it/conventional-changelog": "^11.0.1",
41
+ "eslint": "^10.5.0",
42
+ "typescript": "^6.0.3"
39
43
  },
40
44
  "peerDependencies": {
41
- "eslint": ">=9"
45
+ "eslint": ">=10",
46
+ "typescript": ">=4.8.4 <6.1.0"
47
+ },
48
+ "peerDependenciesMeta": {
49
+ "typescript": {
50
+ "optional": true
51
+ }
42
52
  }
43
53
  }