@r2d2bzh/eslint-config 2.1.2 → 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 +118 -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,90 +1,137 @@
1
1
  import { defineConfig, globalIgnores } from 'eslint/config';
2
2
  import js from '@eslint/js';
3
+ import globals from 'globals';
4
+ import tseslint from 'typescript-eslint';
3
5
 
4
6
  import eslintPluginPrettier from 'eslint-plugin-prettier/recommended';
5
7
  import eslintPluginAva from 'eslint-plugin-ava';
6
- import eslintPluginImport from 'eslint-plugin-import';
8
+ import eslintPluginImportX, { flatConfigs as eslintPluginImportXConfigs } from 'eslint-plugin-import-x';
7
9
  import eslintPluginPromise from 'eslint-plugin-promise';
8
10
  import eslintPluginSecurity from 'eslint-plugin-security';
9
11
  import eslintPluginUnicorn from 'eslint-plugin-unicorn';
10
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
+
11
95
  export default defineConfig([
12
- globalIgnores(['**/node_modules', '**/coverage', '/__tests__']),
96
+ globalIgnores(['**/node_modules', '**/coverage', '/__tests__', '**/vendor.d.ts']),
13
97
  {
14
- files: ['**/*.js'],
98
+ files: ['**/*.js', '**/*.cjs', '**/*.mjs'],
15
99
  extends: ['js/recommended'],
16
- // tag::rules[]
100
+ languageOptions: {
101
+ ecmaVersion: 'latest',
102
+ sourceType: 'module',
103
+ globals: {
104
+ ...globals.node,
105
+ },
106
+ },
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[]
17
123
  rules: {
18
- ...eslintPluginAva.configs.recommended.rules,
19
- ...eslintPluginImport.configs.recommended.rules,
20
- ...eslintPluginPromise.configs.recommended.rules,
21
- ...eslintPluginSecurity.configs.recommended.rules,
22
- ...eslintPluginUnicorn.configs.recommended.rules,
23
- // https://prettier.io/docs/en/integrating-with-linters.html#use-eslint-to-run-prettier
24
- // https://github.com/prettier/eslint-plugin-prettier#options
25
- 'prettier/prettier': [
26
- 'error',
27
- // https://prettier.io/docs/en/configuration.html#basic-configuration
28
- {
29
- // https://prettier.io/docs/en/options.html#quotes
30
- singleQuote: true,
31
- // https://prettier.io/docs/en/options.html#semicolons
32
- semi: true,
33
- // https://prettier.io/docs/en/options.html#tab-width
34
- tabWidth: 2,
35
- // https://prettier.io/docs/en/options.html#print-width
36
- printWidth: 120,
37
- },
38
- ],
39
- // https://eslint.org/docs/rules/no-unused-vars#ignorerestsiblings
40
- 'no-unused-vars': ['error', { ignoreRestSiblings: true }],
41
- // https://eslint.org/docs/rules/prefer-const
42
- 'prefer-const': 'error',
43
- // https://eslint.org/docs/rules/no-alert
44
- 'no-alert': 'error',
45
- // https://eslint.org/docs/rules/no-console
46
- 'no-console': 'error',
47
- // https://eslint.org/docs/rules/no-var
48
- 'no-var': 'error',
49
- // https://eslint.org/docs/rules/linebreak-style
50
- 'linebreak-style': ['error', 'unix'],
51
- // https://eslint.org/docs/rules/complexity
52
- complexity: ['error', { max: 20 }],
53
- // https://eslint.org/docs/rules/max-statements
54
- 'max-statements': ['error', { max: 15 }],
55
- // https://eslint.org/docs/rules/max-statements-per-line
56
- 'max-statements-per-line': ['error', { max: 1 }],
57
- // https://eslint.org/docs/rules/max-nested-callbacks
58
- 'max-nested-callbacks': ['error', { max: 3 }],
59
- // https://eslint.org/docs/rules/max-depth
60
- 'max-depth': ['error', { max: 4 }],
61
- // https://eslint.org/docs/rules/max-params
62
- 'max-params': ['error', { max: 3 }],
63
- // https://eslint.org/docs/rules/no-nested-ternary
64
- 'no-nested-ternary': 'error',
65
- // https://eslint.org/docs/rules/no-trailing-spaces
66
- 'no-trailing-spaces': 'error',
67
- // https://eslint.org/docs/rules/one-var
68
- 'one-var': ['error', 'never'],
69
- // https://github.com/avajs/eslint-plugin-ava/blob/main/docs/rules/prefer-power-assert.md
70
- 'ava/prefer-power-assert': 'warn',
71
- // https://github.com/import-js/eslint-plugin-import/issues/2703
72
- 'import/no-unresolved': 'off',
73
- // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v52.0.0/docs/rules/no-anonymous-default-export.md
74
- '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 }],
75
128
  },
76
- // end::rules[]
129
+ // end::ts-rules[]
77
130
  plugins: {
78
- ava: eslintPluginAva,
79
- import: eslintPluginImport,
80
- promise: eslintPluginPromise,
81
- security: eslintPluginSecurity,
82
- unicorn: eslintPluginUnicorn,
83
- js
84
- },
85
- settings: {
86
- 'import/core-modules': ['ava'],
131
+ ...plugins,
132
+ '@typescript-eslint': tseslint.plugin,
87
133
  },
134
+ settings,
88
135
  },
89
136
  eslintPluginPrettier,
90
137
  ]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r2d2bzh/eslint-config",
3
- "version": "2.1.2",
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
  }