@nitra/eslint-config 3.1.6 → 3.2.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.
Files changed (3) hide show
  1. package/README.md +0 -12
  2. package/index.js +74 -102
  3. package/package.json +4 -3
package/README.md CHANGED
@@ -15,18 +15,6 @@ bun add @nitra/eslint-config -D
15
15
 
16
16
  _Це лише спільна конфігурація. Prettier, ESLint та плагіни потрібно встановлювати окремо або вони підтягнуться як залежності._
17
17
 
18
- ### Єдина версія `eslint-scope` (рекомендовано)
19
-
20
- Щоб уникнути конфліктів версій `eslint-scope` між ESLint і плагінами (наприклад vue-eslint-parser), додайте **один раз** у кореневий `package.json` проєкту:
21
-
22
- ```json
23
- "overrides": {
24
- "eslint-scope": "^9.1.0"
25
- }
26
- ```
27
-
28
- Після цього виконайте `bun install` (або `npm install`). Override застосується до всього дерева залежностей проєкту.
29
-
30
18
  ## Використання
31
19
 
32
20
  У корені проєкту створіть **`eslint.config.js`** (або `eslint.config.mjs`):
package/index.js CHANGED
@@ -1,4 +1,3 @@
1
- // import sdlPlugin from '@microsoft/eslint-plugin-sdl'
2
1
  import js from '@eslint/js'
3
2
  import configPrettier from 'eslint-config-prettier'
4
3
  import { flatConfigs as importPlugin } from 'eslint-plugin-import'
@@ -6,12 +5,12 @@ import jsdocPlugin from 'eslint-plugin-jsdoc'
6
5
  import markdownPlugin from 'eslint-plugin-markdown'
7
6
  import nodePlugin from 'eslint-plugin-n'
8
7
  import oxlint from 'eslint-plugin-oxlint'
9
- // import securityPlugin from 'eslint-plugin-security'
10
8
  import unicornPlugin from 'eslint-plugin-unicorn'
11
- // import vuePlugin from 'eslint-plugin-vue'
9
+ import vuePlugin from 'eslint-plugin-vue'
12
10
  import { configs as ymlConfigs } from 'eslint-plugin-yml'
13
11
  import globals from 'globals'
14
- // import configStandard from 'eslint-config-standard'
12
+ // import securityPlugin from 'eslint-plugin-security'
13
+ // import sdlPlugin from '@microsoft/eslint-plugin-sdl' https://github.com/microsoft/eslint-plugin-sdl/pull/91/changes
15
14
 
16
15
  // Перевизначаємо версію EcmaScript на останню
17
16
  const importPluginEcmaLatest = {
@@ -30,7 +29,6 @@ const all = [
30
29
  // Загальні правила для всіх Yaml файлів проекту
31
30
  ...ymlConfigs['flat/prettier'],
32
31
  // Загальні правила для всіх MD файлів проекту
33
- // @ts-ignore
34
32
  ...markdownPlugin.configs.recommended,
35
33
  // Плагін eslint-plugin-import
36
34
  importPluginEcmaLatest,
@@ -134,48 +132,46 @@ const vueAllVite = [
134
132
  }
135
133
  ]
136
134
 
137
- // Для Vue файлів Vue проектів
138
- // files: ['**/*.vue']
139
135
  const vue = [
140
- // ...vuePlugin.configs['flat/recommended'],
141
- // {
142
- // rules: {
143
- // 'vue/no-v-html': 'off',
144
- // 'vue/html-indent': 'off',
145
- // 'vue/max-attributes-per-line': 'off',
146
- // 'vue/html-closing-bracket-newline': 'off',
147
- // 'vue/singleline-html-element-content-newline': 'off',
148
- // 'vue/multi-word-component-names': 'off',
149
- // 'vue/html-self-closing': [
150
- // 'error',
151
- // {
152
- // html: {
153
- // void: 'always' // під преттієр https://github.com/prettier/prettier/issues/5641
154
- // }
155
- // }
156
- // ],
157
- // // Нітра порядок сортування
158
- // 'vue/attributes-order': [
159
- // 'error',
160
- // {
161
- // order: [
162
- // 'DEFINITION',
163
- // 'LIST_RENDERING',
164
- // 'CONDITIONALS',
165
- // 'RENDER_MODIFIERS',
166
- // 'GLOBAL',
167
- // ['UNIQUE', 'SLOT'],
168
- // 'TWO_WAY_BINDING',
169
- // 'OTHER_DIRECTIVES',
170
- // 'EVENTS',
171
- // 'OTHER_ATTR',
172
- // 'CONTENT'
173
- // ],
174
- // alphabetical: false
175
- // }
176
- // ]
177
- // }
178
- // }
136
+ ...vuePlugin.configs['flat/recommended'],
137
+ {
138
+ rules: {
139
+ 'vue/no-v-html': 'off',
140
+ 'vue/html-indent': 'off',
141
+ 'vue/max-attributes-per-line': 'off',
142
+ 'vue/html-closing-bracket-newline': 'off',
143
+ 'vue/singleline-html-element-content-newline': 'off',
144
+ 'vue/multi-word-component-names': 'off',
145
+ 'vue/html-self-closing': [
146
+ 'error',
147
+ {
148
+ html: {
149
+ void: 'always' // під преттієр https://github.com/prettier/prettier/issues/5641
150
+ }
151
+ }
152
+ ],
153
+ // Нітра порядок сортування
154
+ 'vue/attributes-order': [
155
+ 'error',
156
+ {
157
+ order: [
158
+ 'DEFINITION',
159
+ 'LIST_RENDERING',
160
+ 'CONDITIONALS',
161
+ 'RENDER_MODIFIERS',
162
+ 'GLOBAL',
163
+ ['UNIQUE', 'SLOT'],
164
+ 'TWO_WAY_BINDING',
165
+ 'OTHER_DIRECTIVES',
166
+ 'EVENTS',
167
+ 'OTHER_ATTR',
168
+ 'CONTENT'
169
+ ],
170
+ alphabetical: false
171
+ }
172
+ ]
173
+ }
174
+ }
179
175
  ]
180
176
 
181
177
  const vue2 = [
@@ -187,74 +183,50 @@ const vue2 = [
187
183
  ]
188
184
 
189
185
  /**
190
- * Eslint правила
191
- * @param {{node?: Array, vue?: Array, vue2?: Array}} params список директорій до яких примінити Eslint правили
192
- * @returns {Array} конфігурації eslint
186
+ * Додає до result конфіги для Vue-проєктів (vite, .vue, .js).
187
+ * @param {Array} result масив конфігів
188
+ * @param {string[]} dirs директорії Vue-проєктів
189
+ * @param {{ includeVite?: boolean, extraVueConfigs?: Array }} [options]
190
+ */
191
+ function pushVueConfigs(result, dirs, options = {}) {
192
+ const { includeVite = false, extraVueConfigs = [] } = options
193
+
194
+ if (includeVite) {
195
+ const filesVite = dirs.map(name => `${name}/**/vite.config.js`)
196
+ result.push(...vueVite.map(configObject => ({ files: filesVite, ...configObject })))
197
+ }
198
+
199
+ const filesVue = dirs.map(name => `${name}/**/*.vue`)
200
+ const vueConfigs = [...vueAllVite, ...vue, ...extraVueConfigs]
201
+ result.push(...vueConfigs.map(configObject => ({ files: filesVue, ...configObject })))
202
+
203
+ const filesJS = dirs.map(name => `${name}/**/*.js`)
204
+ result.push(...vueAllVite.map(configObject => ({ files: filesJS, ...configObject })))
205
+ }
206
+
207
+ /**
208
+ * ESLint flat config для проєктів на Vue та Node.
209
+ * @param {Object} [params] — список директорій для застосування правил
210
+ * @param {string[]} [params.node] — шляхи до Node.js коду
211
+ * @param {string[]} [params.vue] — шляхи до Vue 3
212
+ * @param {string[]} [params.vue2] — шляхи до Vue 2
213
+ * @returns {import('eslint').Linter.FlatConfig[]} масив конфігурацій ESLint
193
214
  */
194
215
  // oxlint-disable-next-line unicorn/no-object-as-default-parameter
195
216
  export function getConfig(params = { node: [], vue: [], vue2: [] }) {
196
- const result = all
217
+ const result = [...all]
197
218
 
198
- // якщо присутні nodejs проекти в monorepo
199
219
  if (params.node?.length) {
200
220
  const files = params.node.map(name => `${name}/**/*.js`)
201
- const nodeConfig = node.map(configObject => ({
202
- files,
203
- ...configObject
204
- }))
205
- result.push(...nodeConfig)
221
+ result.push(...node.map(configObject => ({ files, ...configObject })))
206
222
  }
207
223
 
208
- // Правила для Vue3
209
224
  if (params.vue?.length) {
210
- // по певним файлам правили
211
- const filesVite = params.vue.map(name => `${name}/**/vite.config.js`)
212
- const vueViteConfig = vueVite.map(configObject => ({
213
- files: filesVite,
214
- ...configObject
215
- }))
216
- // @ts-ignore
217
- result.push(...vueViteConfig)
218
-
219
- // Для Vue файлів правила
220
- const files = params.vue.map(name => `${name}/**/*.vue`)
221
- const vueConfig = [...vueAllVite, ...vue].map(configObject => ({
222
- files,
223
- ...configObject
224
- }))
225
-
226
- result.push(...vueConfig)
227
-
228
- // Для js файлів всередині Vue проектів правила
229
- const filesJS = params.vue.map(name => `${name}/**/*.js`)
230
- const vueJSConfig = vueAllVite.map(configObject => ({
231
- files: filesJS,
232
- ...configObject
233
- }))
234
- // @ts-ignore
235
- result.push(...vueJSConfig)
225
+ pushVueConfigs(result, params.vue, { includeVite: true })
236
226
  }
237
227
 
238
- // Правила для Vue2
239
228
  if (params.vue2?.length) {
240
- // по певним файлам правили
241
- // Для Vue файлів правила
242
- const files = params.vue2.map(name => `${name}/**/*.vue`)
243
- const vueConfig = [...vueAllVite, ...vue, ...vue2].map(configObject => ({
244
- files,
245
- ...configObject
246
- }))
247
-
248
- result.push(...vueConfig)
249
-
250
- // Для js файлів всередині Vue проектів правила
251
- const filesJS = params.vue2.map(name => `${name}/**/*.js`)
252
- const vueJSConfig = vueAllVite.map(configObject => ({
253
- files: filesJS,
254
- ...configObject
255
- }))
256
- // @ts-ignore
257
- result.push(...vueJSConfig)
229
+ pushVueConfigs(result, params.vue2, { extraVueConfigs: vue2 })
258
230
  }
259
231
 
260
232
  result.push(...oxlint.configs['flat/recommended'])
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nitra/eslint-config",
3
- "version": "3.1.6",
4
- "description": "A Eslint shareable config for projects using 'Vue' and 'Node'",
3
+ "version": "3.2.0",
4
+ "description": "An ESLint shareable config for projects using Vue and Node",
5
5
  "keywords": [
6
6
  "eslint",
7
7
  "eslintconfig",
@@ -13,6 +13,7 @@
13
13
  "type": "git",
14
14
  "url": "git@github.com:nitra/eslint-config.git"
15
15
  },
16
+ "types": "index.d.ts",
16
17
  "files": [
17
18
  "index.js"
18
19
  ],
@@ -27,8 +28,8 @@
27
28
  "eslint-plugin-n": "^17.23.2",
28
29
  "eslint-plugin-oxlint": "^1.43.0",
29
30
  "eslint-plugin-unicorn": "^62.0.0",
31
+ "eslint-plugin-vue": "^10.7.0",
30
32
  "eslint-plugin-yml": "^3.1.2",
31
- "eslint-scope": "^9.1.0",
32
33
  "globals": "^17.3.0"
33
34
  },
34
35
  "engines": {