@bpa-dev/eslint-config 1.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/README.md +127 -0
- package/index.js +160 -0
- package/package.json +50 -0
- package/prettier.config.js +18 -0
- package/react.js +70 -0
package/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# @bpa/eslint-config
|
|
2
|
+
|
|
3
|
+
Универсальная конфигурация ESLint и Prettier для проектов BPA. Поддерживает JavaScript, TypeScript и React.
|
|
4
|
+
|
|
5
|
+
## 🚀 Особенности
|
|
6
|
+
|
|
7
|
+
- ✅ Современный **ESLint 9+ Flat Config**
|
|
8
|
+
- ✅ Поддержка **JavaScript (ES2024)** и **TypeScript**
|
|
9
|
+
- ✅ Конфигурация для **React** с хуками и доступностью
|
|
10
|
+
- ✅ Единый стиль кода с **Prettier**
|
|
11
|
+
- ✅ Правила для импортов и сортировки
|
|
12
|
+
- ✅ Готово к использованию из коробки
|
|
13
|
+
|
|
14
|
+
## 📦 Установка
|
|
15
|
+
|
|
16
|
+
### Для JavaScript/TypeScript проектов
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install --save-dev @bpa/eslint-config eslint prettier typescript
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Для React проектов
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install --save-dev @bpa/eslint-config eslint prettier typescript
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## ⚙️ Использование
|
|
29
|
+
|
|
30
|
+
### ESLint
|
|
31
|
+
|
|
32
|
+
#### Для обычных JS/TS проектов
|
|
33
|
+
|
|
34
|
+
Создайте файл `eslint.config.js` в корне проекта:
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
import bpaConfig from '@bpa/eslint-config';
|
|
38
|
+
|
|
39
|
+
export default bpaConfig;
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
#### Для React проектов
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
import bpaReactConfig from '@bpa/eslint-config/react';
|
|
46
|
+
|
|
47
|
+
export default bpaReactConfig;
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### Расширение конфигурации
|
|
51
|
+
|
|
52
|
+
Вы можете добавить свои правила:
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
import bpaConfig from '@bpa/eslint-config';
|
|
56
|
+
|
|
57
|
+
export default [
|
|
58
|
+
...bpaConfig,
|
|
59
|
+
{
|
|
60
|
+
rules: {
|
|
61
|
+
// Ваши дополнительные правила
|
|
62
|
+
'no-console': 'off',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Prettier
|
|
69
|
+
|
|
70
|
+
Создайте файл `prettier.config.js` в корне проекта:
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
import bpaPrettierConfig from '@bpa/eslint-config/prettier';
|
|
74
|
+
|
|
75
|
+
export default bpaPrettierConfig;
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Или расширьте конфигурацию:
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
import bpaPrettierConfig from '@bpa/eslint-config/prettier';
|
|
82
|
+
|
|
83
|
+
export default {
|
|
84
|
+
...bpaPrettierConfig,
|
|
85
|
+
printWidth: 120, // переопределение настроек
|
|
86
|
+
};
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### package.json скрипты
|
|
90
|
+
|
|
91
|
+
Добавьте в `package.json`:
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"scripts": {
|
|
96
|
+
"lint": "eslint .",
|
|
97
|
+
"lint:fix": "eslint . --fix",
|
|
98
|
+
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,css,md}\"",
|
|
99
|
+
"format:check": "prettier --check \"**/*.{js,jsx,ts,tsx,json,css,md}\""
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## 🎯 VS Code интеграция
|
|
105
|
+
|
|
106
|
+
Установите расширения:
|
|
107
|
+
|
|
108
|
+
- [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
|
|
109
|
+
- [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)
|
|
110
|
+
|
|
111
|
+
Создайте `.vscode/settings.json`:
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"editor.formatOnSave": true,
|
|
116
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
117
|
+
"editor.codeActionsOnSave": {
|
|
118
|
+
"source.fixAll.eslint": "explicit"
|
|
119
|
+
},
|
|
120
|
+
"eslint.validate": [
|
|
121
|
+
"javascript",
|
|
122
|
+
"javascriptreact",
|
|
123
|
+
"typescript",
|
|
124
|
+
"typescriptreact"
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
```
|
package/index.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Базовый ESLint конфиг для JavaScript и TypeScript проектов BPA
|
|
3
|
+
* Используется ESLint 9+ Flat Config
|
|
4
|
+
* @see https://eslint.org/docs/latest/use/configure/configuration-files
|
|
5
|
+
*/
|
|
6
|
+
import js from '@eslint/js';
|
|
7
|
+
import tseslint from 'typescript-eslint';
|
|
8
|
+
import prettierConfig from 'eslint-config-prettier';
|
|
9
|
+
import importPlugin from 'eslint-plugin-import';
|
|
10
|
+
import globals from 'globals';
|
|
11
|
+
|
|
12
|
+
export default tseslint.config(
|
|
13
|
+
// Игнорируемые файлы
|
|
14
|
+
{
|
|
15
|
+
ignores: [
|
|
16
|
+
'**/node_modules/**',
|
|
17
|
+
'**/dist/**',
|
|
18
|
+
'**/build/**',
|
|
19
|
+
'**/.next/**',
|
|
20
|
+
'**/out/**',
|
|
21
|
+
'**/coverage/**',
|
|
22
|
+
'**/.turbo/**',
|
|
23
|
+
'**/.cache/**',
|
|
24
|
+
'**/*.min.js',
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
// Базовые правила для всех JS файлов
|
|
29
|
+
{
|
|
30
|
+
files: ['**/*.{js,mjs,cjs,jsx}'],
|
|
31
|
+
languageOptions: {
|
|
32
|
+
ecmaVersion: 2024,
|
|
33
|
+
sourceType: 'module',
|
|
34
|
+
globals: {
|
|
35
|
+
...globals.browser,
|
|
36
|
+
...globals.node,
|
|
37
|
+
...globals.es2021,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
plugins: {
|
|
41
|
+
import: importPlugin,
|
|
42
|
+
},
|
|
43
|
+
rules: {
|
|
44
|
+
...js.configs.recommended.rules,
|
|
45
|
+
|
|
46
|
+
// Общие правила
|
|
47
|
+
'no-console': ['warn', { allow: ['warn', 'error'] }],
|
|
48
|
+
'no-debugger': 'warn',
|
|
49
|
+
'no-alert': 'warn',
|
|
50
|
+
'no-var': 'error',
|
|
51
|
+
'prefer-const': 'error',
|
|
52
|
+
'prefer-arrow-callback': 'error',
|
|
53
|
+
'prefer-template': 'error',
|
|
54
|
+
'prefer-destructuring': ['error', { object: true, array: false }],
|
|
55
|
+
'no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
|
|
56
|
+
'no-duplicate-imports': 'error',
|
|
57
|
+
'object-shorthand': ['error', 'always'],
|
|
58
|
+
'no-return-await': 'error',
|
|
59
|
+
eqeqeq: ['error', 'always', { null: 'ignore' }],
|
|
60
|
+
curly: ['error', 'all'],
|
|
61
|
+
|
|
62
|
+
// Import правила
|
|
63
|
+
'import/order': [
|
|
64
|
+
'error',
|
|
65
|
+
{
|
|
66
|
+
groups: [
|
|
67
|
+
'builtin',
|
|
68
|
+
'external',
|
|
69
|
+
'internal',
|
|
70
|
+
['parent', 'sibling'],
|
|
71
|
+
'index',
|
|
72
|
+
'object',
|
|
73
|
+
'type',
|
|
74
|
+
],
|
|
75
|
+
'newlines-between': 'always',
|
|
76
|
+
alphabetize: { order: 'asc', caseInsensitive: true },
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
'import/no-duplicates': 'error',
|
|
80
|
+
'import/newline-after-import': 'error',
|
|
81
|
+
'import/no-unresolved': 'off',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
// TypeScript файлы
|
|
86
|
+
{
|
|
87
|
+
files: ['**/*.{ts,tsx,mts,cts}'],
|
|
88
|
+
languageOptions: {
|
|
89
|
+
parser: tseslint.parser,
|
|
90
|
+
parserOptions: {
|
|
91
|
+
ecmaVersion: 2024,
|
|
92
|
+
sourceType: 'module',
|
|
93
|
+
},
|
|
94
|
+
globals: {
|
|
95
|
+
...globals.browser,
|
|
96
|
+
...globals.node,
|
|
97
|
+
...globals.es2021,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
plugins: {
|
|
101
|
+
'@typescript-eslint': tseslint.plugin,
|
|
102
|
+
import: importPlugin,
|
|
103
|
+
},
|
|
104
|
+
rules: {
|
|
105
|
+
...js.configs.recommended.rules,
|
|
106
|
+
...tseslint.configs.recommended.rules,
|
|
107
|
+
|
|
108
|
+
'no-unused-vars': 'off',
|
|
109
|
+
'@typescript-eslint/no-unused-vars': [
|
|
110
|
+
'error',
|
|
111
|
+
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
|
|
112
|
+
],
|
|
113
|
+
|
|
114
|
+
// TypeScript специфичные правила
|
|
115
|
+
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
116
|
+
'@typescript-eslint/no-explicit-any': 'warn',
|
|
117
|
+
'@typescript-eslint/no-non-null-assertion': 'warn',
|
|
118
|
+
'@typescript-eslint/consistent-type-imports': [
|
|
119
|
+
'error',
|
|
120
|
+
{ prefer: 'type-imports', fixStyle: 'separate-type-imports' },
|
|
121
|
+
],
|
|
122
|
+
'@typescript-eslint/consistent-type-exports': 'error',
|
|
123
|
+
'@typescript-eslint/no-import-type-side-effects': 'error',
|
|
124
|
+
|
|
125
|
+
// Общие правила
|
|
126
|
+
'no-console': ['warn', { allow: ['warn', 'error'] }],
|
|
127
|
+
'no-debugger': 'warn',
|
|
128
|
+
'no-alert': 'warn',
|
|
129
|
+
'prefer-const': 'error',
|
|
130
|
+
'prefer-arrow-callback': 'error',
|
|
131
|
+
'prefer-template': 'error',
|
|
132
|
+
'object-shorthand': ['error', 'always'],
|
|
133
|
+
eqeqeq: ['error', 'always', { null: 'ignore' }],
|
|
134
|
+
curly: ['error', 'all'],
|
|
135
|
+
|
|
136
|
+
// Import правила
|
|
137
|
+
'import/order': [
|
|
138
|
+
'error',
|
|
139
|
+
{
|
|
140
|
+
groups: [
|
|
141
|
+
'builtin',
|
|
142
|
+
'external',
|
|
143
|
+
'internal',
|
|
144
|
+
['parent', 'sibling'],
|
|
145
|
+
'index',
|
|
146
|
+
'object',
|
|
147
|
+
'type',
|
|
148
|
+
],
|
|
149
|
+
'newlines-between': 'always',
|
|
150
|
+
alphabetize: { order: 'asc', caseInsensitive: true },
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
'import/no-duplicates': 'error',
|
|
154
|
+
'import/newline-after-import': 'error',
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
// Отключаем конфликтующие с Prettier правила
|
|
159
|
+
prettierConfig
|
|
160
|
+
);
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bpa-dev/eslint-config",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Набор конфигураций для ESLint и Prettier для проектов BPA",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.js",
|
|
9
|
+
"./prettier": "./prettier.config.js",
|
|
10
|
+
"./react": "./react.js"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"index.js",
|
|
14
|
+
"react.js",
|
|
15
|
+
"prettier.config.js"
|
|
16
|
+
],
|
|
17
|
+
"keywords": [
|
|
18
|
+
"eslint",
|
|
19
|
+
"eslintconfig",
|
|
20
|
+
"prettier",
|
|
21
|
+
"config",
|
|
22
|
+
"javascript",
|
|
23
|
+
"typescript",
|
|
24
|
+
"react"
|
|
25
|
+
],
|
|
26
|
+
"author": "BPA",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"eslint": "^9.0.0",
|
|
30
|
+
"prettier": "^3.0.0",
|
|
31
|
+
"typescript": "^5.0.0"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@eslint/js": "^9.17.0",
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^8.19.1",
|
|
36
|
+
"@typescript-eslint/parser": "^8.19.1",
|
|
37
|
+
"eslint-config-prettier": "^9.1.0",
|
|
38
|
+
"eslint-plugin-import": "^2.31.0",
|
|
39
|
+
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
40
|
+
"eslint-plugin-react": "^7.37.2",
|
|
41
|
+
"eslint-plugin-react-hooks": "^5.1.0",
|
|
42
|
+
"globals": "^15.14.0",
|
|
43
|
+
"typescript-eslint": "^8.19.1"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"eslint": "^9.17.0",
|
|
47
|
+
"prettier": "^3.4.2",
|
|
48
|
+
"typescript": "^5.7.2"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prettier конфигурация для проектов BPA
|
|
3
|
+
* @see https://prettier.io/docs/configuration
|
|
4
|
+
* @type {import("prettier").Config}
|
|
5
|
+
*/
|
|
6
|
+
const config = {
|
|
7
|
+
semi: false,
|
|
8
|
+
tabWidth: 2,
|
|
9
|
+
printWidth: 120,
|
|
10
|
+
singleQuote: true,
|
|
11
|
+
trailingComma: 'none',
|
|
12
|
+
jsxSingleQuote: true,
|
|
13
|
+
endOfLine: 'auto',
|
|
14
|
+
bracketSpacing: true,
|
|
15
|
+
arrowParens: 'always'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default config
|
package/react.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ESLint конфиг для React проектов BPA
|
|
3
|
+
* Расширяет базовый конфиг с поддержкой React и JSX
|
|
4
|
+
*/
|
|
5
|
+
import baseConfig from './index.js';
|
|
6
|
+
import react from 'eslint-plugin-react';
|
|
7
|
+
import reactHooks from 'eslint-plugin-react-hooks';
|
|
8
|
+
import jsxA11y from 'eslint-plugin-jsx-a11y';
|
|
9
|
+
import globals from 'globals';
|
|
10
|
+
|
|
11
|
+
export default [
|
|
12
|
+
...baseConfig,
|
|
13
|
+
|
|
14
|
+
// React конфигурация
|
|
15
|
+
{
|
|
16
|
+
files: ['**/*.{jsx,tsx}'],
|
|
17
|
+
languageOptions: {
|
|
18
|
+
parserOptions: {
|
|
19
|
+
ecmaFeatures: {
|
|
20
|
+
jsx: true,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
globals: {
|
|
24
|
+
...globals.browser,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
plugins: {
|
|
28
|
+
react,
|
|
29
|
+
'react-hooks': reactHooks,
|
|
30
|
+
'jsx-a11y': jsxA11y,
|
|
31
|
+
},
|
|
32
|
+
settings: {
|
|
33
|
+
react: {
|
|
34
|
+
version: 'detect',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
rules: {
|
|
38
|
+
// React основные правила
|
|
39
|
+
...react.configs.recommended.rules,
|
|
40
|
+
'react/react-in-jsx-scope': 'off',
|
|
41
|
+
'react/prop-types': 'off',
|
|
42
|
+
'react/jsx-no-target-blank': 'error',
|
|
43
|
+
'react/jsx-key': ['error', { checkFragmentShorthand: true }],
|
|
44
|
+
'react/jsx-curly-brace-presence': ['error', { props: 'never', children: 'never' }],
|
|
45
|
+
'react/self-closing-comp': 'error',
|
|
46
|
+
'react/jsx-boolean-value': ['error', 'never'],
|
|
47
|
+
'react/jsx-pascal-case': 'error',
|
|
48
|
+
'react/no-array-index-key': 'warn',
|
|
49
|
+
'react/no-unstable-nested-components': 'error',
|
|
50
|
+
'react/jsx-fragments': ['error', 'syntax'],
|
|
51
|
+
|
|
52
|
+
// React Hooks правила
|
|
53
|
+
...reactHooks.configs.recommended.rules,
|
|
54
|
+
'react-hooks/rules-of-hooks': 'error',
|
|
55
|
+
'react-hooks/exhaustive-deps': 'warn',
|
|
56
|
+
|
|
57
|
+
// Доступность
|
|
58
|
+
...jsxA11y.configs.recommended.rules,
|
|
59
|
+
'jsx-a11y/anchor-is-valid': [
|
|
60
|
+
'error',
|
|
61
|
+
{
|
|
62
|
+
components: ['Link'],
|
|
63
|
+
specialLink: ['to'],
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
'jsx-a11y/click-events-have-key-events': 'warn',
|
|
67
|
+
'jsx-a11y/no-static-element-interactions': 'warn',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
];
|