@zalib/linter 1.0.9

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/.eslintrc.js ADDED
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ overrides: [
3
+ {
4
+ extends: ['./eslint/js'],
5
+ files: ['*.js'],
6
+ },
7
+ ],
8
+ root: true,
9
+ };
package/README.md ADDED
@@ -0,0 +1,92 @@
1
+ ## Установка модуля
2
+ ```
3
+ npm i --save-dev --save-exact @zalib/linter
4
+ ```
5
+
6
+ ## Подключение конфигов
7
+
8
+ ### eslint
9
+ Пример конфига **.eslintrc.js** из корня сервиса.
10
+ ```
11
+ const jsEslintConfig = require('@zalib/linter/eslint/js');
12
+ const tsEslintConfig = require('@zalib/linter/eslint/ts');
13
+
14
+ module.exports = {
15
+ overrides: [
16
+ {
17
+ ...jsEslintConfig,
18
+ files: ['*.js'],
19
+ },
20
+ {
21
+ ...tsEslintConfig,
22
+ files: ['*.ts'],
23
+ parser: '@typescript-eslint/parser',
24
+ parserOptions: {
25
+ include: ['./src/**/*.ts', './test/**/*.ts'],
26
+ project: './tsconfig.json',
27
+ },
28
+ },
29
+ ],
30
+ root: true,
31
+ };
32
+ ```
33
+
34
+ ### prettier
35
+ Добавить в **package.json** в корневую секцию:
36
+ ```
37
+ "prettier": "@zalib/linter/prettier"
38
+ ```
39
+
40
+ ## Использование
41
+
42
+ ### Подключение "коротких" команд
43
+ Добавить в **package.json** в секцию **scripts**:
44
+ ```
45
+ "format": "prettier --write 'src/**/*.ts'",
46
+ "lint": "eslint 'src/**/*.{ts,js}' --quiet",
47
+ "lint:fix": "eslint 'src/**/*.{js,ts}' --quiet --fix",
48
+ "lint:warns": "eslint 'src/**/*.ts' --max-warnings 0",
49
+ ```
50
+
51
+ ### Автоматизация при работе в репозитории
52
+ Установить пакет **husky**:
53
+ ```
54
+ npm i --save-dev --save-exact husky@latest
55
+ ```
56
+
57
+ Добавить в **package.json** в корневую секцию:
58
+ ```
59
+ "lint-staged": {
60
+ "*.{js,ts}": [
61
+ "eslint --quiet --max-warnings 0",
62
+ "eslint --quiet --fix",
63
+ "prettier --write"
64
+ ]
65
+ },
66
+ "husky": {
67
+ "hooks": {
68
+ "pre-commit": "lint-staged --allow-empty"
69
+ }
70
+ },
71
+ ```
72
+
73
+ ### Версии пакетов с отсуствием конфликтов
74
+ ```
75
+ "devDependencies": {
76
+ "@typescript-eslint/eslint-plugin": "7.18.0",
77
+ "@typescript-eslint/parser": "7.18.0",
78
+ "eslint": "8.57.1",
79
+ "eslint-config-airbnb-base": "15.0.0",
80
+ "eslint-config-airbnb-typescript": "18.0.0",
81
+ "eslint-config-prettier": "10.1.1",
82
+ "eslint-plugin-import": "2.31.0",
83
+ "eslint-plugin-jest": "28.11.0",
84
+ "eslint-plugin-jsx-a11y": "6.10.2",
85
+ "eslint-plugin-prettier": "5.2.3",
86
+ "eslint-plugin-simple-import-sort": "12.1.1",
87
+ "eslint-plugin-typescript-sort": "0.1.11",
88
+ "jest": "29.7.0",
89
+ "prettier": "3.5.3",
90
+ "typescript": "5.8.2"
91
+ }
92
+ ```
package/eslint/js.js ADDED
@@ -0,0 +1,94 @@
1
+ module.exports = {
2
+ env: {
3
+ browser: false,
4
+ es6: true,
5
+ jest: true,
6
+ 'jest/globals': true,
7
+ node: true,
8
+ },
9
+ extends: [
10
+ 'airbnb-base',
11
+ 'eslint:recommended',
12
+ 'plugin:jest/recommended',
13
+ 'plugin:jest/style',
14
+ 'prettier',
15
+ 'plugin:prettier/recommended',
16
+ ],
17
+ files: ['*.js'],
18
+ plugins: ['jest'],
19
+ rules: {
20
+ 'arrow-parens': [
21
+ 1,
22
+ 'always',
23
+ {
24
+ requireForBlockBody: true,
25
+ },
26
+ ],
27
+ 'class-methods-use-this': 0,
28
+ 'comma-dangle': [
29
+ 'error',
30
+ {
31
+ arrays: 'always-multiline',
32
+ exports: 'always-multiline',
33
+ functions: 'always-multiline',
34
+ imports: 'always-multiline',
35
+ objects: 'always-multiline',
36
+ },
37
+ ],
38
+ complexity: [2, { max: 10 }],
39
+ 'function-paren-newline': 0,
40
+ 'implicit-arrow-linebreak': 0,
41
+ 'import/extensions': 0,
42
+ 'import/no-unresolved': 0,
43
+ 'max-lines': [
44
+ 2,
45
+ {
46
+ max: 500,
47
+ skipBlankLines: false,
48
+ skipComments: true,
49
+ },
50
+ ],
51
+ 'max-lines-per-function': [
52
+ 2,
53
+ {
54
+ max: 200,
55
+ skipBlankLines: false,
56
+ skipComments: true,
57
+ },
58
+ ],
59
+ 'max-params': [2, { max: 3 }],
60
+ 'no-await-in-loop': 0,
61
+ 'no-continue': 0,
62
+ 'no-plusplus': [
63
+ 2,
64
+ {
65
+ allowForLoopAfterthoughts: true,
66
+ },
67
+ ],
68
+ 'no-promise-executor-return': 0,
69
+ 'no-restricted-syntax': 0,
70
+ 'padding-line-between-statements': [
71
+ 2,
72
+ {
73
+ blankLine: 'always',
74
+ next: '*',
75
+ prev: ['block-like'],
76
+ },
77
+ {
78
+ blankLine: 'always',
79
+ next: 'if',
80
+ prev: '*',
81
+ },
82
+ {
83
+ blankLine: 'always',
84
+ next: '*',
85
+ prev: 'if',
86
+ },
87
+ ],
88
+ 'react/jsx-filename-extension': 0,
89
+ 'require-await': 1,
90
+ 'sort-imports': 2,
91
+ 'sort-keys': 2,
92
+ strict: 0,
93
+ },
94
+ };
package/eslint/ts.js ADDED
@@ -0,0 +1,303 @@
1
+ function eslintMembersGroup(suffix) {
2
+ return [
3
+ `public-static-${suffix}`,
4
+ `protected-static-${suffix}`,
5
+ `private-static-${suffix}`,
6
+ `#private-static-${suffix}`,
7
+
8
+ `public-instance-${suffix}`,
9
+ `protected-instance-${suffix}`,
10
+ `private-instance-${suffix}`,
11
+ `#private-instance-${suffix}`,
12
+
13
+ `public-abstract-${suffix}`,
14
+ `protected-abstract-${suffix}`,
15
+
16
+ `public-${suffix}`,
17
+ `protected-${suffix}`,
18
+ `private-${suffix}`,
19
+ `#private-${suffix}`,
20
+
21
+ `static-${suffix}`,
22
+ `instance-${suffix}`,
23
+ `abstract-${suffix}`,
24
+
25
+ suffix,
26
+ ];
27
+ }
28
+
29
+ module.exports = {
30
+ extends: [
31
+ 'airbnb-typescript/base',
32
+ 'eslint:recommended',
33
+ 'plugin:@typescript-eslint/recommended',
34
+ 'plugin:@typescript-eslint/recommended-requiring-type-checking',
35
+ 'plugin:import/errors',
36
+ 'plugin:import/typescript',
37
+ 'plugin:import/warnings',
38
+ 'prettier',
39
+ 'plugin:prettier/recommended',
40
+ ],
41
+ files: ['*.ts'],
42
+ parser: '@typescript-eslint/parser',
43
+ plugins: ['@typescript-eslint', 'jest', 'simple-import-sort', 'typescript-sort'],
44
+ rules: {
45
+ '@typescript-eslint/await-thenable': 1,
46
+ '@typescript-eslint/comma-dangle': [
47
+ 2,
48
+ {
49
+ arrays: 'always-multiline',
50
+ enums: 'always-multiline',
51
+ exports: 'always-multiline',
52
+ functions: 'always-multiline',
53
+ generics: 'always-multiline',
54
+ imports: 'always-multiline',
55
+ objects: 'always-multiline',
56
+ tuples: 'always-multiline',
57
+ },
58
+ ],
59
+ '@typescript-eslint/explicit-function-return-type': [
60
+ 'error',
61
+ {
62
+ allowExpressions: true,
63
+ },
64
+ ],
65
+ '@typescript-eslint/explicit-member-accessibility': [
66
+ 2,
67
+ {
68
+ accessibility: 'explicit',
69
+ overrides: {
70
+ constructors: 'no-public',
71
+ },
72
+ },
73
+ ],
74
+ '@typescript-eslint/explicit-module-boundary-types': 2,
75
+ '@typescript-eslint/member-ordering': [
76
+ 'error',
77
+ {
78
+ default: [
79
+ // Index signature
80
+ 'signature',
81
+ 'call-signature',
82
+
83
+ // Fields
84
+ ...eslintMembersGroup('field'),
85
+
86
+ // Static initialization
87
+ 'static-initialization',
88
+
89
+ // Constructors
90
+ 'public-constructor',
91
+ 'protected-constructor',
92
+ 'private-constructor',
93
+
94
+ 'constructor',
95
+
96
+ // Getters
97
+ ...eslintMembersGroup('get'),
98
+
99
+ // Setters
100
+ ...eslintMembersGroup('set'),
101
+
102
+ // Methods
103
+ ...eslintMembersGroup('method'),
104
+ ],
105
+ },
106
+ ],
107
+ '@typescript-eslint/naming-convention': [
108
+ 2,
109
+ {
110
+ format: ['camelCase'],
111
+ leadingUnderscore: 'forbid',
112
+ selector: 'default',
113
+ trailingUnderscore: 'forbid',
114
+ },
115
+ {
116
+ format: null,
117
+ modifiers: ['requiresQuotes'],
118
+ selector: [
119
+ 'accessor',
120
+ 'classMethod',
121
+ 'classProperty',
122
+ 'enumMember',
123
+ 'objectLiteralMethod',
124
+ 'objectLiteralProperty',
125
+ 'typeMethod',
126
+ 'typeProperty',
127
+ ],
128
+ },
129
+ {
130
+ format: null,
131
+ modifiers: ['destructured', 'unused'],
132
+ selector: 'variable',
133
+ },
134
+ {
135
+ format: ['camelCase', 'UPPER_CASE'],
136
+ leadingUnderscore: 'forbid',
137
+ selector: 'variable',
138
+ trailingUnderscore: 'forbid',
139
+ },
140
+ {
141
+ format: ['camelCase', 'snake_case'],
142
+ leadingUnderscore: 'forbid',
143
+ selector: 'property',
144
+ trailingUnderscore: 'forbid',
145
+ },
146
+ {
147
+ format: ['camelCase'],
148
+ leadingUnderscore: 'allow',
149
+ selector: 'parameter',
150
+ trailingUnderscore: 'forbid',
151
+ },
152
+ {
153
+ format: ['PascalCase'],
154
+ leadingUnderscore: 'forbid',
155
+ selector: 'typeLike',
156
+ trailingUnderscore: 'forbid',
157
+ },
158
+ {
159
+ format: ['PascalCase', 'UPPER_CASE'],
160
+ leadingUnderscore: 'forbid',
161
+ selector: 'enum',
162
+ trailingUnderscore: 'forbid',
163
+ },
164
+ {
165
+ format: ['PascalCase', 'UPPER_CASE'],
166
+ leadingUnderscore: 'forbid',
167
+ selector: 'enumMember',
168
+ trailingUnderscore: 'forbid',
169
+ },
170
+ ],
171
+ '@typescript-eslint/no-explicit-any': 2,
172
+ '@typescript-eslint/no-floating-promises': 0,
173
+ '@typescript-eslint/no-magic-numbers': [
174
+ 1,
175
+ {
176
+ ignore: [-1, 0, 1],
177
+ ignoreArrayIndexes: true,
178
+ ignoreDefaultValues: true,
179
+ ignoreEnums: true,
180
+ ignoreNumericLiteralTypes: true,
181
+ ignoreReadonlyClassProperties: true,
182
+ },
183
+ ],
184
+ '@typescript-eslint/no-misused-promises': 0,
185
+ '@typescript-eslint/no-unsafe-assignment': 0,
186
+ '@typescript-eslint/no-unsafe-call': 0,
187
+ '@typescript-eslint/no-unsafe-member-access': 0,
188
+ '@typescript-eslint/no-unsafe-return': 0,
189
+ '@typescript-eslint/require-await': 1,
190
+ '@typescript-eslint/restrict-template-expressions': [
191
+ 2,
192
+ {
193
+ allowAny: true,
194
+ allowBoolean: true,
195
+ allowNullish: true,
196
+ allowNumber: true,
197
+ },
198
+ ],
199
+ '@typescript-eslint/return-await': [2, 'in-try-catch'],
200
+ 'arrow-parens': [
201
+ 1,
202
+ 'always',
203
+ {
204
+ requireForBlockBody: true,
205
+ },
206
+ ],
207
+ 'class-methods-use-this': 0,
208
+ 'comma-dangle': 0,
209
+ complexity: [2, { max: 10 }],
210
+ 'function-paren-newline': 0,
211
+ 'implicit-arrow-linebreak': 0,
212
+ 'import/default': 2,
213
+ 'import/export': 2,
214
+ 'import/first': 2,
215
+ 'import/named': 2,
216
+ 'import/namespace': 2,
217
+ 'import/newline-after-import': 2,
218
+ 'import/no-cycle': 2,
219
+ 'import/no-extraneous-dependencies': [
220
+ 2,
221
+ {
222
+ devDependencies: true,
223
+ },
224
+ ],
225
+ 'import/order': 0,
226
+ 'import/prefer-default-export': 0,
227
+ 'max-classes-per-file': 0,
228
+ 'max-lines': [
229
+ 2,
230
+ {
231
+ max: 500,
232
+ skipBlankLines: false,
233
+ skipComments: true,
234
+ },
235
+ ],
236
+ 'max-lines-per-function': [
237
+ 2,
238
+ {
239
+ max: 200,
240
+ skipBlankLines: false,
241
+ skipComments: true,
242
+ },
243
+ ],
244
+ 'max-params': [2, { max: 3 }],
245
+ 'no-await-in-loop': 0,
246
+ 'no-continue': 0,
247
+ 'no-plusplus': [
248
+ 2,
249
+ {
250
+ allowForLoopAfterthoughts: true,
251
+ },
252
+ ],
253
+ 'no-promise-executor-return': 0,
254
+ 'no-restricted-syntax': 0,
255
+ 'padding-line-between-statements': [
256
+ 2,
257
+ {
258
+ blankLine: 'always',
259
+ next: '*',
260
+ prev: ['block-like'],
261
+ },
262
+ {
263
+ blankLine: 'always',
264
+ next: 'if',
265
+ prev: '*',
266
+ },
267
+ {
268
+ blankLine: 'always',
269
+ next: '*',
270
+ prev: 'if',
271
+ },
272
+ ],
273
+ 'react/jsx-filename-extension': 0,
274
+ 'require-await': 0,
275
+ 'simple-import-sort/imports': [
276
+ 2,
277
+ {
278
+ groups: [
279
+ // Side effect imports.
280
+ ['^\\u0000'],
281
+ // Packages.
282
+ // Things that start with a letter (or digit or underscore), or `@` followed by a letter.
283
+ ['^@?\\w'],
284
+ // Absolute imports and other imports such as Vue-style `@/foo`.
285
+ // Anything not matched in another group.
286
+ ['^'],
287
+ // Relative imports.
288
+ // Anything that starts with a dot.
289
+ ['^\\.'],
290
+ // Interfaces, typings
291
+ ['^\\..*(\\/|\\.)(interface|types$|typings$)'],
292
+ // Constants
293
+ ['^\\..*(\\/|\\.)(constant|config)'],
294
+ ],
295
+ },
296
+ ],
297
+ 'sort-imports': 0,
298
+ 'sort-keys': 2,
299
+ 'typescript-sort/interface': 2,
300
+ 'typescript-sort/type': 2,
301
+ 'typescript-sort/enum': 2,
302
+ },
303
+ };
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@zalib/linter",
3
+ "version": "1.0.9",
4
+ "description": "Linter configs",
5
+ "author": "https://github.com/wsp-repo/",
6
+ "license": "UNLICENSED",
7
+ "keywords": [
8
+ "prettier",
9
+ "eslint",
10
+ "tslint"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/wsp-repo/linter.git"
15
+ },
16
+ "homepage": "https://github.com/wsp-repo/linter#readme",
17
+ "bugs": {
18
+ "url": "https://github.com/wsp-repo/linter/issues"
19
+ },
20
+ "devDependencies": {
21
+ "@typescript-eslint/eslint-plugin": "7.18.0",
22
+ "@typescript-eslint/parser": "7.18.0",
23
+ "eslint": "8.57.1",
24
+ "eslint-config-airbnb-base": "15.0.0",
25
+ "eslint-config-airbnb-typescript": "18.0.0",
26
+ "eslint-config-prettier": "10.1.1",
27
+ "eslint-plugin-import": "2.31.0",
28
+ "eslint-plugin-jest": "28.11.0",
29
+ "eslint-plugin-jsx-a11y": "6.10.2",
30
+ "eslint-plugin-prettier": "5.2.3",
31
+ "eslint-plugin-simple-import-sort": "12.1.1",
32
+ "eslint-plugin-typescript-sort": "0.1.11",
33
+ "jest": "29.7.0",
34
+ "prettier": "3.5.3",
35
+ "typescript": "5.8.2"
36
+ }
37
+ }
@@ -0,0 +1,10 @@
1
+ module.exports = {
2
+ arrowParens: 'always',
3
+ jsxBracketSameLine: false,
4
+ printWidth: 80,
5
+ semi: true,
6
+ singleQuote: true,
7
+ tabWidth: 2,
8
+ trailingComma: 'all',
9
+ useTabs: false,
10
+ };
@@ -0,0 +1 @@
1
+ module.exports = require('./prettier');