@d-zero/eslint-config 5.0.0-dev.92 → 5.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 D-ZERO Co., Ltd.
3
+ Copyright (c) 2024 D-ZERO Co., Ltd.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,4 +1,55 @@
1
1
  # `@d-zero/eslint-config`
2
2
 
3
- - 使用: 🆗 使用可
4
- - 解説: 🚧 準備中
3
+ ## 個別インストール
4
+
5
+ ```sh
6
+ npm install -D @d-zero/eslint-config
7
+ ```
8
+
9
+ ## 使い方
10
+
11
+ `eslint.config.js`を作成し、`import`からコンフィグデータを読み込みます。
12
+
13
+ ```js
14
+ import dz from '@d-zero/eslint-config';
15
+
16
+ /**
17
+ * @type {import('eslint').ESLint.ConfigData[]}
18
+ */
19
+ export default [...dz.configs.frontend];
20
+ ```
21
+
22
+ ### 拡張
23
+
24
+ プロジェクトに合わせて設定を追加します。
25
+
26
+ ```js
27
+ import dz from '@d-zero/eslint-config';
28
+
29
+ /**
30
+ * @type {import('eslint').ESLint.ConfigData[]}
31
+ */
32
+ export default [
33
+ ...dz.configs.frontend,
34
+ {
35
+ rules: {
36
+ // 例: console.logを許可する
37
+ 'no-console': 0,
38
+ },
39
+ },
40
+ ];
41
+ ```
42
+
43
+ ### プリセット
44
+
45
+ 以下のプリセットが用意されています。
46
+
47
+ | プロパティ | 型 | 説明 |
48
+ | ---------------------- | -------- | -------------------------------------------------- |
49
+ | `configs.frontend` | `Array` | フロントエンド開発用 |
50
+ | `configs.frontendNoTS` | `Array` | フロントエンド開発用(TypeScriptを利用しない場合) |
51
+ | `configs.node` | `Array` | Node.js開発用 |
52
+ | `configs.nodeNoTS` | `Array` | Node.js開発用(TypeScriptを利用しない場合) |
53
+ | `configs.standard` | `Array` | `config.node`と同じ |
54
+ | `configs.base` | `Array` | `config.nodeNoTS`と同じ |
55
+ | `configs.commonjs` | `Object` | CommonJS用単一設定 |
package/base.js CHANGED
@@ -1,104 +1,252 @@
1
+ import js from '@eslint/js';
2
+ import comments from 'eslint-plugin-eslint-comments';
3
+ import { flatConfigs as importX } from 'eslint-plugin-import-x';
4
+ import jsdoc from 'eslint-plugin-jsdoc';
5
+ import * as regexpPlugin from 'eslint-plugin-regexp';
6
+ import sortClassMembers from 'eslint-plugin-sort-class-members';
7
+ import eslintPluginUnicorn from 'eslint-plugin-unicorn';
8
+ import globals from 'globals';
9
+
1
10
  /**
2
- * @type {import('eslint/lib/shared/types').ConfigData}
11
+ * @type {import('eslint').Linter.Config[]}
3
12
  */
4
- module.exports = {
5
- extends: [
6
- 'eslint:recommended',
7
- 'plugin:unicorn/recommended',
8
- 'plugin:regexp/recommended',
9
- 'plugin:import/recommended',
10
- ],
11
- env: {
12
- browser: true,
13
- es6: true,
14
- node: true,
15
- },
16
- plugins: ['unicorn', 'jsdoc', 'eslint-comments', 'import', 'sort-class-members'],
17
- parserOptions: {
18
- ecmaVersion: 2023,
13
+ export const base = [
14
+ {
15
+ ...js.configs.recommended,
16
+ rules: {
17
+ ...js.configs.recommended.rules,
18
+ 'no-console': 'warn',
19
+ 'no-mixed-spaces-and-tabs': 0,
20
+ 'no-restricted-syntax': [
21
+ 2,
22
+ {
23
+ selector:
24
+ ':matches(PropertyDefinition, MethodDefinition)[accessibility="private"]',
25
+ message: 'Use #private instead',
26
+ },
27
+ {
28
+ selector:
29
+ ':matches(PropertyDefinition, MethodDefinition)[accessibility="public"]',
30
+ message: 'Remove public keyword',
31
+ },
32
+ {
33
+ selector: 'MethodDefinition[key.name=/^_/]:not([accessibility="protected"])',
34
+ message: 'Add protected keyword',
35
+ },
36
+ {
37
+ selector: 'MethodDefinition:not([key.name=/^_/])[accessibility="protected"]',
38
+ message: 'Start with `_` if you want to use protected',
39
+ },
40
+ {
41
+ selector:
42
+ "CallExpression[callee.property.name='addEventListener'][arguments.0.value='DOMContentLoaded']",
43
+ message:
44
+ "Avoid using 'DOMContentLoaded'. Use 'defer' or 'type=module' attribute instead.",
45
+ },
46
+ ],
47
+ 'no-unused-vars': 0,
48
+ 'no-var': 2,
49
+ 'prefer-const': 2,
50
+ 'prefer-rest-params': 2,
51
+ 'prefer-spread': 2,
52
+ },
19
53
  },
20
- globals: {
21
- NodeJS: true,
54
+ {
55
+ ...eslintPluginUnicorn.configs.recommended,
56
+ rules: {
57
+ ...eslintPluginUnicorn.configs.recommended.rules,
58
+ 'unicorn/consistent-destructuring': 0,
59
+ 'unicorn/consistent-function-scoping': 0,
60
+ 'unicorn/no-anonymous-default-export': 0,
61
+ 'unicorn/no-array-callback-reference': 0,
62
+ 'unicorn/no-nested-ternary': 0,
63
+ 'unicorn/no-null': 0,
64
+ 'unicorn/no-process-exit': 0,
65
+ 'unicorn/prefer-global-this': 0,
66
+ 'unicorn/prefer-query-selector': 0,
67
+ 'unicorn/prefer-string-raw': 0,
68
+ 'unicorn/prefer-ternary': 0,
69
+ 'unicorn/prevent-abbreviations': 0,
70
+ },
22
71
  },
23
- rules: {
24
- // Standard
25
- 'no-var': 2,
26
- 'no-unused-vars': 0,
27
- 'no-console': 'warn',
28
- 'no-mixed-spaces-and-tabs': 0,
29
- 'prefer-const': 2,
30
- 'prefer-rest-params': 2,
31
- 'prefer-spread': 2,
32
-
33
- // Unicorn
34
- 'unicorn/consistent-destructuring': 0,
35
- 'unicorn/consistent-function-scoping': 0,
36
- 'unicorn/no-array-callback-reference': 0,
37
- 'unicorn/no-nested-ternary': 0,
38
- 'unicorn/no-null': 0,
39
- 'unicorn/prefer-query-selector': 0,
40
- 'unicorn/prefer-ternary': 0,
41
- 'unicorn/prevent-abbreviations': 0,
42
-
43
- // import
44
- 'import/no-named-as-default': 0,
45
- 'import/no-unresolved': 0,
46
- 'import/no-extraneous-dependencies': 2,
47
- 'import/order': [
48
- 2,
49
- {
50
- groups: ['type', 'builtin', 'external', 'parent', 'sibling', 'index', 'object'],
51
- pathGroups: [
52
- {
53
- pattern: '@alias/**',
54
- group: 'parent',
55
- position: 'before',
72
+ regexpPlugin.configs['flat/recommended'],
73
+ {
74
+ ...importX.recommended,
75
+ rules: {
76
+ ...importX.recommended.rules,
77
+ 'import-x/no-extraneous-dependencies': 2,
78
+ 'import-x/no-named-as-default': 0,
79
+ 'import-x/no-unresolved': 0,
80
+ 'import-x/order': [
81
+ 2,
82
+ {
83
+ groups: ['type', 'builtin', 'external', 'parent', 'sibling', 'index', 'object'],
84
+ pathGroups: [
85
+ {
86
+ pattern: '@alias/**',
87
+ group: 'parent',
88
+ position: 'before',
89
+ },
90
+ ],
91
+ alphabetize: {
92
+ order: 'asc',
56
93
  },
57
- ],
58
- alphabetize: {
59
- order: 'asc',
94
+ 'newlines-between': 'always',
60
95
  },
61
- 'newlines-between': 'always',
62
- },
63
- ],
64
-
65
- // sort-class-members
66
- 'sort-class-members/sort-class-members': [
67
- 1,
68
- {
69
- order: [
70
- '[static-properties]',
71
- '[static-methods]',
72
- '[properties]',
73
- '[conventional-private-properties]',
74
- 'constructor',
75
- '[methods]',
76
- '[conventional-private-methods]',
77
- ],
78
- accessorPairPositioning: 'getThenSet',
79
- },
96
+ ],
97
+ },
98
+ },
99
+ {
100
+ files: [
101
+ '*.{test,spec}.{js,mjs,json}',
102
+ '*.config.{js,mjs,json}',
103
+ '.*rc.{js,mjs,json}',
80
104
  ],
105
+ rules: {
106
+ 'import-x/no-extraneous-dependencies': 0,
107
+ },
81
108
  },
82
- settings: {
83
- jsdoc: {
84
- tagNamePreference: {
85
- param: 'arg',
86
- returns: 'return',
87
- },
109
+ {
110
+ ...jsdoc.configs['flat/recommended'],
111
+ rules: {
112
+ ...jsdoc.configs['flat/recommended'].rules,
113
+ 'jsdoc/require-param-type': 0,
114
+ 'jsdoc/require-param-description': 0,
115
+ 'jsdoc/require-returns': 0,
116
+ 'jsdoc/require-returns-type': 0,
117
+ 'jsdoc/require-returns-description': 0,
88
118
  },
89
119
  },
90
- overrides: [
91
- {
92
- files: '**/*.spec.*',
93
- rules: {
94
- 'import/no-extraneous-dependencies': 0,
95
- },
120
+ {
121
+ plugins: {
122
+ comments,
96
123
  },
97
- {
98
- files: ['*.config.{js,mjs,json,ts}', '.*rc.{js,mjs,json,ts}'],
99
- rules: {
100
- 'import/no-extraneous-dependencies': 0,
124
+ },
125
+ {
126
+ plugins: {
127
+ comments,
128
+ 'sort-class-members': sortClassMembers,
129
+ },
130
+ rules: {
131
+ 'sort-class-members/sort-class-members': [
132
+ 1,
133
+ {
134
+ order: [
135
+ '[public-properties]',
136
+ '[public-readonly-properties]',
137
+ '[public-properties-function]',
138
+ '[private-properties]',
139
+ '[private-properties-function]',
140
+ '[accessor-pairs]',
141
+ '[getters]',
142
+ '[setters]',
143
+ 'constructor',
144
+ '[public-methods]',
145
+ '[private-methods]',
146
+ '[protedted-methods]',
147
+ '[static-properties]',
148
+ '[static-methods]',
149
+ '[everything-else]',
150
+ ],
151
+ groups: {
152
+ 'public-properties': [
153
+ {
154
+ type: 'property',
155
+ kind: 'nonAccessor',
156
+ static: false,
157
+ private: false,
158
+ override: false,
159
+ readonly: false,
160
+ sort: 'alphabetical',
161
+ },
162
+ ],
163
+ 'public-readonly-properties': [
164
+ {
165
+ type: 'property',
166
+ kind: 'nonAccessor',
167
+ static: false,
168
+ private: false,
169
+ override: false,
170
+ readonly: true,
171
+ sort: 'alphabetical',
172
+ },
173
+ ],
174
+ 'public-properties-function': [
175
+ {
176
+ type: 'property',
177
+ propertyType: 'ArrowFunctionExpression',
178
+ kind: 'nonAccessor',
179
+ static: false,
180
+ private: false,
181
+ accessibility: 'public',
182
+ override: false,
183
+ sort: 'alphabetical',
184
+ },
185
+ ],
186
+ 'private-properties': [
187
+ {
188
+ type: 'property',
189
+ kind: 'nonAccessor',
190
+ static: false,
191
+ private: true,
192
+ override: false,
193
+ sort: 'alphabetical',
194
+ },
195
+ ],
196
+ 'private-properties-function': [
197
+ {
198
+ type: 'property',
199
+ propertyType: 'ArrowFunctionExpression',
200
+ kind: 'nonAccessor',
201
+ static: false,
202
+ private: true,
203
+ accessibility: 'public',
204
+ override: false,
205
+ sort: 'alphabetical',
206
+ },
207
+ ],
208
+ 'public-methods': [
209
+ {
210
+ type: 'method',
211
+ kind: 'nonAccessor',
212
+ static: false,
213
+ private: false,
214
+ override: false,
215
+ sort: 'alphabetical',
216
+ },
217
+ ],
218
+ 'private-methods': [
219
+ {
220
+ name: '/#.+/',
221
+ type: 'method',
222
+ kind: 'nonAccessor',
223
+ static: false,
224
+ private: true,
225
+ override: false,
226
+ sort: 'alphabetical',
227
+ },
228
+ ],
229
+ 'protedted-methods': [
230
+ {
231
+ name: '/_.+/',
232
+ type: 'method',
233
+ static: false,
234
+ sort: 'alphabetical',
235
+ },
236
+ ],
237
+ },
238
+ accessorPairPositioning: 'getThenSet',
239
+ },
240
+ ],
241
+ },
242
+ },
243
+ {
244
+ languageOptions: {
245
+ ecmaVersion: 2023,
246
+ globals: {
247
+ ...globals.builtin,
248
+ ...globals.nodeBuiltin,
101
249
  },
102
250
  },
103
- ],
104
- };
251
+ },
252
+ ];
package/commonjs.js ADDED
@@ -0,0 +1,16 @@
1
+ import globals from 'globals';
2
+
3
+ /**
4
+ * @type {import('eslint').Linter.Config}
5
+ */
6
+ export const commonjs = {
7
+ rules: {
8
+ 'unicorn/prefer-module': 0,
9
+ '@typescript-eslint/no-require-imports': 0,
10
+ },
11
+ languageOptions: {
12
+ globals: {
13
+ ...globals.commonjs,
14
+ },
15
+ },
16
+ };
package/frontend.js ADDED
@@ -0,0 +1,15 @@
1
+ import globals from 'globals';
2
+
3
+ /**
4
+ * @type {import('eslint').Linter.Config}
5
+ */
6
+ export const frontend = {
7
+ rules: {
8
+ 'unicorn/prefer-top-level-await': 0,
9
+ },
10
+ languageOptions: {
11
+ globals: {
12
+ ...globals.browser,
13
+ },
14
+ },
15
+ };
package/index.js CHANGED
@@ -1,79 +1,19 @@
1
- const base = require('./base');
1
+ import { base } from './base.js';
2
+ import { commonjs } from './commonjs.js';
3
+ import { frontend } from './frontend.js';
4
+ import { ts } from './typescript.js';
2
5
 
3
6
  /**
4
- * @type {import('eslint/lib/shared/types').ConfigData}
7
+ * @type {import('eslint').ESLint.Plugin}
5
8
  */
6
- module.exports = {
7
- ...base,
8
- overrides: [
9
- {
10
- files: '**/*.{ts,tsx}',
11
- extends: ['plugin:import/typescript', 'plugin:@typescript-eslint/recommended'],
12
- plugins: ['@typescript-eslint', ...base.plugins],
13
- parser: '@typescript-eslint/parser',
14
- parserOptions: {
15
- sourceType: 'module',
16
- project: ['./tsconfig.json'],
17
- },
18
- settings: {
19
- ...base.settings,
20
- 'import/parsers': {
21
- '@typescript-eslint/parser': ['.ts'],
22
- },
23
- },
24
- rules: {
25
- ...base.rules,
26
- // @typescript-eslint
27
- '@typescript-eslint/no-unused-vars': 2,
28
- '@typescript-eslint/no-array-constructor': 2,
29
- '@typescript-eslint/adjacent-overload-signatures': 2,
30
- '@typescript-eslint/no-namespace': [2, { allowDeclarations: true }],
31
- '@typescript-eslint/prefer-namespace-keyword': 2,
32
- '@typescript-eslint/no-var-requires': 2,
33
- '@typescript-eslint/no-unnecessary-type-assertion': 2,
34
- '@typescript-eslint/restrict-plus-operands': 0,
35
- '@typescript-eslint/consistent-type-imports': 1,
36
- '@typescript-eslint/require-await': 2,
37
- '@typescript-eslint/no-floating-promises': 2,
38
- '@typescript-eslint/member-ordering': [
39
- 'warn',
40
- {
41
- default: 'never',
42
- classes: {
43
- memberTypes: [
44
- 'public-static-field',
45
- 'protected-static-field',
46
- 'private-static-field',
47
- 'public-static-method',
48
- 'protected-static-method',
49
- 'public-static-get',
50
- 'protected-static-get',
51
- 'private-static-get',
52
- 'public-instance-field',
53
- 'protected-instance-field',
54
- 'private-instance-field',
55
- 'public-abstract-field',
56
- 'protected-abstract-field',
57
- 'public-constructor',
58
- 'protected-constructor',
59
- 'private-constructor',
60
- ['public-abstract-get', 'public-abstract-set'],
61
- ['protected-abstract-get', 'protected-abstract-set'],
62
- ['public-instance-get', 'public-instance-set'],
63
- ['protected-instance-get', 'protected-instance-set'],
64
- ['private-instance-get', 'private-instance-set'],
65
- 'public-abstract-method',
66
- 'protected-abstract-method',
67
- 'public-instance-method',
68
- 'protected-instance-method',
69
- 'private-instance-method',
70
- 'private-static-method',
71
- ],
72
- order: 'alphabetically',
73
- },
74
- },
75
- ],
76
- },
77
- },
78
- ],
9
+ export default {
10
+ configs: {
11
+ standard: [...ts],
12
+ base: [...base],
13
+ node: [...ts],
14
+ nodeNoTS: [...base],
15
+ frontend: [...ts, frontend],
16
+ frontendNoTS: [...base, frontend],
17
+ commonjs,
18
+ },
79
19
  };
package/package.json CHANGED
@@ -1,44 +1,34 @@
1
1
  {
2
2
  "name": "@d-zero/eslint-config",
3
- "version": "5.0.0-dev.92+cac5756",
3
+ "version": "5.0.0",
4
4
  "description": "Configurations of ESLint",
5
- "repository": "https://github.com/d-zero-dev/node-dev-env.git",
5
+ "repository": "https://github.com/d-zero-dev/linters.git",
6
6
  "author": "D-ZERO Co., Ltd.",
7
7
  "license": "MIT",
8
- "private": false,
9
8
  "publishConfig": {
10
9
  "access": "public"
11
10
  },
11
+ "engines": {
12
+ "node": ">=22.0.0"
13
+ },
12
14
  "files": [
13
- "index.js",
14
- "base.js"
15
+ "*.js"
15
16
  ],
16
- "type": "commonjs",
17
- "main": "index.js",
17
+ "type": "module",
18
18
  "exports": {
19
- ".": {
20
- "require": "./index.js"
21
- },
22
- "./base": {
23
- "require": "./base.js"
24
- }
19
+ ".": "./index.js"
25
20
  },
26
21
  "dependencies": {
27
- "@typescript-eslint/eslint-plugin": "6.15.0",
28
- "@typescript-eslint/parser": "6.15.0",
29
- "eslint": "8.56.0",
22
+ "@eslint/js": "9.39.2",
23
+ "eslint": "9.39.2",
30
24
  "eslint-plugin-eslint-comments": "3.2.0",
31
- "eslint-plugin-import": "2.29.1",
32
- "eslint-plugin-jsdoc": "46.9.1",
33
- "eslint-plugin-regexp": "2.1.2",
34
- "eslint-plugin-sort-class-members": "1.19.0",
35
- "eslint-plugin-unicorn": "50.0.1"
36
- },
37
- "peerDependencies": {
38
- "@d-zero/tsconfig": ">= 5"
39
- },
40
- "devDependencies": {
41
- "@d-zero/tsconfig": "5.0.0-dev.92+cac5756"
25
+ "eslint-plugin-import-x": "4.16.1",
26
+ "eslint-plugin-jsdoc": "61.5.0",
27
+ "eslint-plugin-regexp": "2.10.0",
28
+ "eslint-plugin-sort-class-members": "1.21.0",
29
+ "eslint-plugin-unicorn": "62.0.0",
30
+ "globals": "17.0.0",
31
+ "typescript-eslint": "8.51.0"
42
32
  },
43
- "gitHead": "cac5756806a90edaa73a57e49f0dcd45495290ab"
33
+ "gitHead": "7f635ad8bbb1455d0d362fe00478a2f7bd216924"
44
34
  }
package/typescript.js ADDED
@@ -0,0 +1,44 @@
1
+ import tsESLint from 'typescript-eslint';
2
+
3
+ import { base } from './base.js';
4
+
5
+ export const ts = tsESLint.config(
6
+ base,
7
+ tsESLint.configs.recommended,
8
+ {
9
+ files: ['*.{ts,tsx}', '**/*.{ts,tsx}'],
10
+ languageOptions: {
11
+ parserOptions: {
12
+ sourceType: 'module',
13
+ project: ['./tsconfig.json'],
14
+ },
15
+ },
16
+ settings: {
17
+ 'import-x/parsers': {
18
+ '@typescript-eslint/parser': ['.ts'],
19
+ },
20
+ },
21
+ rules: {
22
+ '@typescript-eslint/adjacent-overload-signatures': 2,
23
+ '@typescript-eslint/ban-ts-comment': 0,
24
+ '@typescript-eslint/consistent-type-imports': 1,
25
+ '@typescript-eslint/member-ordering': 0,
26
+ '@typescript-eslint/no-array-constructor': 2,
27
+ '@typescript-eslint/no-explicit-any': [1, { fixToUnknown: true }],
28
+ '@typescript-eslint/no-floating-promises': 2,
29
+ '@typescript-eslint/no-namespace': [2, { allowDeclarations: true }],
30
+ '@typescript-eslint/no-unnecessary-type-assertion': 2,
31
+ '@typescript-eslint/no-unused-vars': 2,
32
+ '@typescript-eslint/no-var-requires': 2,
33
+ '@typescript-eslint/prefer-namespace-keyword': 2,
34
+ '@typescript-eslint/require-await': 2,
35
+ '@typescript-eslint/restrict-plus-operands': 0,
36
+ },
37
+ },
38
+ {
39
+ files: ['*.{test,spec}.{ts,mts,tsx}'],
40
+ rules: {
41
+ 'import/no-extraneous-dependencies': 0,
42
+ },
43
+ },
44
+ );