@d-zero/eslint-config 5.0.0-dev.93 → 6.0.0-alpha.2

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,261 @@
1
+ import dzeroPlugin from '@d-zero/eslint-plugin';
2
+ import js from '@eslint/js';
3
+ import comments from 'eslint-plugin-eslint-comments';
4
+ import { flatConfigs as importX } from 'eslint-plugin-import-x';
5
+ import jsdoc from 'eslint-plugin-jsdoc';
6
+ import * as regexpPlugin from 'eslint-plugin-regexp';
7
+ import sortClassMembers from 'eslint-plugin-sort-class-members';
8
+ import eslintPluginUnicorn from 'eslint-plugin-unicorn';
9
+ import globals from 'globals';
10
+
1
11
  /**
2
- * @type {import('eslint/lib/shared/types').ConfigData}
12
+ * @type {import('eslint').Linter.Config[]}
3
13
  */
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,
14
+ export const base = [
15
+ {
16
+ ...js.configs.recommended,
17
+ rules: {
18
+ ...js.configs.recommended.rules,
19
+ 'no-console': 'warn',
20
+ 'no-mixed-spaces-and-tabs': 0,
21
+ 'no-restricted-syntax': [
22
+ 2,
23
+ {
24
+ selector:
25
+ ':matches(PropertyDefinition, MethodDefinition)[accessibility="private"]',
26
+ message: 'Use #private instead',
27
+ },
28
+ {
29
+ selector:
30
+ ':matches(PropertyDefinition, MethodDefinition)[accessibility="public"]',
31
+ message: 'Remove public keyword',
32
+ },
33
+ {
34
+ selector: 'MethodDefinition[key.name=/^_/]:not([accessibility="protected"])',
35
+ message: 'Add protected keyword',
36
+ },
37
+ {
38
+ selector: 'MethodDefinition:not([key.name=/^_/])[accessibility="protected"]',
39
+ message: 'Start with `_` if you want to use protected',
40
+ },
41
+ {
42
+ selector:
43
+ "CallExpression[callee.property.name='addEventListener'][arguments.0.value='DOMContentLoaded']",
44
+ message:
45
+ "Avoid using 'DOMContentLoaded'. Use 'defer' or 'type=module' attribute instead.",
46
+ },
47
+ ],
48
+ 'no-unused-vars': 0,
49
+ 'no-var': 2,
50
+ 'prefer-const': 2,
51
+ 'prefer-rest-params': 2,
52
+ 'prefer-spread': 2,
53
+ },
19
54
  },
20
- globals: {
21
- NodeJS: true,
55
+ {
56
+ ...eslintPluginUnicorn.configs.recommended,
57
+ rules: {
58
+ ...eslintPluginUnicorn.configs.recommended.rules,
59
+ 'unicorn/consistent-destructuring': 0,
60
+ 'unicorn/consistent-function-scoping': 0,
61
+ 'unicorn/no-anonymous-default-export': 0,
62
+ 'unicorn/no-array-callback-reference': 0,
63
+ 'unicorn/no-nested-ternary': 0,
64
+ 'unicorn/no-null': 0,
65
+ 'unicorn/no-process-exit': 0,
66
+ 'unicorn/prefer-global-this': 0,
67
+ 'unicorn/prefer-query-selector': 0,
68
+ 'unicorn/prefer-string-raw': 0,
69
+ 'unicorn/prefer-ternary': 0,
70
+ 'unicorn/prevent-abbreviations': 0,
71
+ },
22
72
  },
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',
73
+ regexpPlugin.configs['flat/recommended'],
74
+ {
75
+ ...importX.recommended,
76
+ rules: {
77
+ ...importX.recommended.rules,
78
+ 'import-x/no-extraneous-dependencies': 2,
79
+ 'import-x/no-named-as-default': 0,
80
+ 'import-x/no-unresolved': 0,
81
+ 'import-x/order': [
82
+ 2,
83
+ {
84
+ groups: ['type', 'builtin', 'external', 'parent', 'sibling', 'index', 'object'],
85
+ pathGroups: [
86
+ {
87
+ pattern: '@alias/**',
88
+ group: 'parent',
89
+ position: 'before',
90
+ },
91
+ ],
92
+ alphabetize: {
93
+ order: 'asc',
56
94
  },
57
- ],
58
- alphabetize: {
59
- order: 'asc',
95
+ 'newlines-between': 'always',
60
96
  },
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
- },
97
+ ],
98
+ },
99
+ },
100
+ {
101
+ files: [
102
+ '*.{test,spec}.{js,mjs,json}',
103
+ '*.config.{js,mjs,json}',
104
+ '.*rc.{js,mjs,json}',
80
105
  ],
106
+ rules: {
107
+ 'import-x/no-extraneous-dependencies': 0,
108
+ },
81
109
  },
82
- settings: {
83
- jsdoc: {
84
- tagNamePreference: {
85
- param: 'arg',
86
- returns: 'return',
87
- },
110
+ {
111
+ ...jsdoc.configs['flat/recommended'],
112
+ rules: {
113
+ ...jsdoc.configs['flat/recommended'].rules,
114
+ 'jsdoc/require-param-type': 0,
115
+ 'jsdoc/require-param-description': 0,
116
+ 'jsdoc/require-returns': 0,
117
+ 'jsdoc/require-returns-type': 0,
118
+ 'jsdoc/require-returns-description': 0,
88
119
  },
89
120
  },
90
- overrides: [
91
- {
92
- files: '**/*.spec.*',
93
- rules: {
94
- 'import/no-extraneous-dependencies': 0,
95
- },
121
+ {
122
+ plugins: {
123
+ comments,
124
+ },
125
+ },
126
+ {
127
+ plugins: {
128
+ comments,
129
+ 'sort-class-members': sortClassMembers,
96
130
  },
97
- {
98
- files: ['*.config.{js,mjs,json,ts}', '.*rc.{js,mjs,json,ts}'],
99
- rules: {
100
- 'import/no-extraneous-dependencies': 0,
131
+ rules: {
132
+ 'sort-class-members/sort-class-members': [
133
+ 1,
134
+ {
135
+ order: [
136
+ '[public-properties]',
137
+ '[public-readonly-properties]',
138
+ '[public-properties-function]',
139
+ '[private-properties]',
140
+ '[private-properties-function]',
141
+ '[accessor-pairs]',
142
+ '[getters]',
143
+ '[setters]',
144
+ 'constructor',
145
+ '[public-methods]',
146
+ '[private-methods]',
147
+ '[protedted-methods]',
148
+ '[static-properties]',
149
+ '[static-methods]',
150
+ '[everything-else]',
151
+ ],
152
+ groups: {
153
+ 'public-properties': [
154
+ {
155
+ type: 'property',
156
+ kind: 'nonAccessor',
157
+ static: false,
158
+ private: false,
159
+ override: false,
160
+ readonly: false,
161
+ sort: 'alphabetical',
162
+ },
163
+ ],
164
+ 'public-readonly-properties': [
165
+ {
166
+ type: 'property',
167
+ kind: 'nonAccessor',
168
+ static: false,
169
+ private: false,
170
+ override: false,
171
+ readonly: true,
172
+ sort: 'alphabetical',
173
+ },
174
+ ],
175
+ 'public-properties-function': [
176
+ {
177
+ type: 'property',
178
+ propertyType: 'ArrowFunctionExpression',
179
+ kind: 'nonAccessor',
180
+ static: false,
181
+ private: false,
182
+ accessibility: 'public',
183
+ override: false,
184
+ sort: 'alphabetical',
185
+ },
186
+ ],
187
+ 'private-properties': [
188
+ {
189
+ type: 'property',
190
+ kind: 'nonAccessor',
191
+ static: false,
192
+ private: true,
193
+ override: false,
194
+ sort: 'alphabetical',
195
+ },
196
+ ],
197
+ 'private-properties-function': [
198
+ {
199
+ type: 'property',
200
+ propertyType: 'ArrowFunctionExpression',
201
+ kind: 'nonAccessor',
202
+ static: false,
203
+ private: true,
204
+ accessibility: 'public',
205
+ override: false,
206
+ sort: 'alphabetical',
207
+ },
208
+ ],
209
+ 'public-methods': [
210
+ {
211
+ type: 'method',
212
+ kind: 'nonAccessor',
213
+ static: false,
214
+ private: false,
215
+ override: false,
216
+ sort: 'alphabetical',
217
+ },
218
+ ],
219
+ 'private-methods': [
220
+ {
221
+ name: '/#.+/',
222
+ type: 'method',
223
+ kind: 'nonAccessor',
224
+ static: false,
225
+ private: true,
226
+ override: false,
227
+ sort: 'alphabetical',
228
+ },
229
+ ],
230
+ 'protedted-methods': [
231
+ {
232
+ name: '/_.+/',
233
+ type: 'method',
234
+ static: false,
235
+ sort: 'alphabetical',
236
+ },
237
+ ],
238
+ },
239
+ accessorPairPositioning: 'getThenSet',
240
+ },
241
+ ],
242
+ },
243
+ },
244
+ {
245
+ languageOptions: {
246
+ ecmaVersion: 2023,
247
+ globals: {
248
+ ...globals.builtin,
249
+ ...globals.nodeBuiltin,
101
250
  },
102
251
  },
103
- ],
104
- };
252
+ },
253
+ {
254
+ plugins: {
255
+ '@d-zero': dzeroPlugin,
256
+ },
257
+ rules: {
258
+ '@d-zero/no-click-event': 'warn',
259
+ },
260
+ },
261
+ ];
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,39 @@
1
1
  {
2
2
  "name": "@d-zero/eslint-config",
3
- "version": "5.0.0-dev.93+c6646f2",
3
+ "version": "6.0.0-alpha.2",
4
4
  "description": "Configurations of ESLint",
5
- "repository": "https://github.com/d-zero-dev/node-dev-env.git",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/d-zero-dev/linters.git",
8
+ "directory": "packages/@d-zero/eslint-config"
9
+ },
6
10
  "author": "D-ZERO Co., Ltd.",
7
11
  "license": "MIT",
8
- "private": false,
9
12
  "publishConfig": {
10
13
  "access": "public"
11
14
  },
15
+ "engines": {
16
+ "node": ">=22.0.0"
17
+ },
12
18
  "files": [
13
- "index.js",
14
- "base.js"
19
+ "*.js"
15
20
  ],
16
- "type": "commonjs",
17
- "main": "index.js",
21
+ "type": "module",
18
22
  "exports": {
19
- ".": {
20
- "require": "./index.js"
21
- },
22
- "./base": {
23
- "require": "./base.js"
24
- }
23
+ ".": "./index.js"
25
24
  },
26
25
  "dependencies": {
27
- "@typescript-eslint/eslint-plugin": "6.15.0",
28
- "@typescript-eslint/parser": "6.15.0",
29
- "eslint": "8.56.0",
26
+ "@d-zero/eslint-plugin": "6.0.0-alpha.2",
27
+ "@eslint/js": "9.39.3",
28
+ "eslint": "9.39.3",
30
29
  "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.93+c6646f2"
30
+ "eslint-plugin-import-x": "4.16.1",
31
+ "eslint-plugin-jsdoc": "62.7.1",
32
+ "eslint-plugin-regexp": "3.0.0",
33
+ "eslint-plugin-sort-class-members": "1.21.0",
34
+ "eslint-plugin-unicorn": "63.0.0",
35
+ "globals": "17.3.0",
36
+ "typescript-eslint": "8.56.1"
42
37
  },
43
- "gitHead": "c6646f2425c257367f106e5e2cee276c42aef9d5"
38
+ "gitHead": "b2d753122349a8d4dd4b7d484276d03fec498f0d"
44
39
  }
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
+ );