@nitra/eslint-config 3.6.3 → 3.6.6

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.
@@ -20,6 +20,42 @@ const RELEVANT_KEYWORDS = ['gql', 'graphql', 'GraphQL']
20
20
  /** Регулярний вираз на рівні модуля для e18e/prefer-static-regex. */
21
21
  const VUE_OR_SVELTE_FILE_RE = /\.(vue|svelte)$/
22
22
 
23
+ /** Сегмент шляху до залежностей: виключаємо з пулу sibling-операцій для unique-operation-name / unique-fragment-name. */
24
+ const NODE_MODULES_SEGMENT_RE = /[/\\]node_modules[/\\]/
25
+
26
+ /**
27
+ * Чи шлях джерела документа не всередині `node_modules`.
28
+ * @param {{ filePath?: string }} entry запис операції/фрагмента з graphql-eslint
29
+ * @returns {boolean} `true`, якщо `filePath` заданий і не містить сегмента `node_modules`
30
+ */
31
+ function documentEntryOutsideNodeModules(entry) {
32
+ return typeof entry?.filePath === 'string' && !NODE_MODULES_SEGMENT_RE.test(entry.filePath)
33
+ }
34
+
35
+ /**
36
+ * Обгортка siblingOperations: graphql-config може підтягувати `documents` із `node_modules`, тоді
37
+ * правила з `requiresSiblings` бачать дублікати імен між застосунком і залежністю. Фільтр лишає
38
+ * лише записи зі шляхів поза `node_modules` (кеш плагіна не змінюється).
39
+ * @param {object} siblings оригінальний `siblingOperations` з graphql-eslint parser services
40
+ * @returns {object} той самий API з відфільтрованими `getOperation` / `getFragment` / списками
41
+ */
42
+ function siblingOperationsWithoutNodeModules(siblings) {
43
+ if (!siblings?.available) {
44
+ return siblings
45
+ }
46
+ return {
47
+ ...siblings,
48
+ getFragment: name => siblings.getFragment(name).filter(entry => documentEntryOutsideNodeModules(entry)),
49
+ getFragments: () => siblings.getFragments().filter(entry => documentEntryOutsideNodeModules(entry)),
50
+ getFragmentByType: typeName =>
51
+ siblings.getFragmentByType(typeName).filter(entry => documentEntryOutsideNodeModules(entry)),
52
+ getOperation: name => siblings.getOperation(name).filter(entry => documentEntryOutsideNodeModules(entry)),
53
+ getOperations: () => siblings.getOperations().filter(entry => documentEntryOutsideNodeModules(entry)),
54
+ getOperationByType: type =>
55
+ siblings.getOperationByType(type).filter(entry => documentEntryOutsideNodeModules(entry))
56
+ }
57
+ }
58
+
23
59
  /**
24
60
  * Шлях для graphql-config: для віртуальних блоків Vue — фізичний .vue, інакше той самий filePath.
25
61
  * @param {string} filePath шлях файлу, який обробляє processor
@@ -127,10 +163,15 @@ const baseParser = graphqlEslintPlugin.parser
127
163
  */
128
164
  export function graphqlParseForESLintWithAnchor(code, options = {}) {
129
165
  const filePath = options.filePath || ''
130
- return baseParser.parseForESLint(code, {
166
+ const parsed = baseParser.parseForESLint(code, {
131
167
  ...options,
132
168
  filePath: graphQLConfigPathAnchor(filePath)
133
169
  })
170
+ const sibs = parsed.services?.siblingOperations
171
+ if (sibs) {
172
+ parsed.services.siblingOperations = siblingOperationsWithoutNodeModules(sibs)
173
+ }
174
+ return parsed
134
175
  }
135
176
 
136
177
  /** Парсер для flat config (обгортка над graphql-eslint). */
package/index.js CHANGED
@@ -20,6 +20,9 @@ import globals from 'globals'
20
20
  import vueEslintParser from 'vue-eslint-parser'
21
21
  import { graphqlCodefileProcessor, graphqlParserWithConfigAnchor } from './graphql-eslint-anchor.js'
22
22
 
23
+ /** Витягнуті graphql-eslint документи: gql під `node_modules` не обробляються (sibling-фільтр у `graphql-eslint-anchor` уже прибирає залежності з унікальності імен; patterns `ignores` скорочують шум і час). */
24
+ const GRAPHQL_EXTRACTED_IGNORES = ['**/node_modules/**']
25
+
23
26
  /** Glob-патерни файлів для eslint-plugin-unicorn (JS-подібні джерела; без сирих YAML/Markdown). */
24
27
  const UNICORN_FILES = ['**/*.{js,mjs,cjs,vue}']
25
28
 
@@ -46,8 +49,17 @@ const VUE_SCRIPT_ESLINT_RECOMMENDED_GAP_RULES = {
46
49
  // @ts-expect-error типізація плагіна не гарантує `configs.recommended`; у runtime поле є.
47
50
  const e18eRecommendedFlat = /** @type {import('eslint').Linter.FlatConfig} */ (e18ePlugin.configs.recommended)
48
51
 
49
- /** Віртуальні документи з gql/graphql у .js/.vue (processor); ESLint обробляє їх як окремі `*.graphql` файли. */
50
- const GRAPHQL_EXTRACTED_DOCUMENT_FILES = ['**/*.graphql']
52
+ /**
53
+ * Лише віртуальні GraphQL-документи з процесора (gql у `.js`/`.vue`): шляхи виду
54
+ * `…/file.js/0_document.graphql` або `…/Comp.vue/…/0_document.graphql`. Фізичні `*.graphql` у проєкті не
55
+ * потрапляють сюди — їх ESLint з цим пакетом не аналізує graphql-eslint.
56
+ */
57
+ const GRAPHQL_EXTRACTED_DOCUMENT_FILES = [
58
+ '**/*.vue/**/*.graphql',
59
+ '**/*.js/*.graphql',
60
+ '**/*.mjs/*.graphql',
61
+ '**/*.cjs/*.graphql'
62
+ ]
51
63
 
52
64
  /**
53
65
  * Правила для витягнутих GraphQL-блоків: пресет operations-recommended (поля, типи, змінні).
@@ -55,6 +67,7 @@ const GRAPHQL_EXTRACTED_DOCUMENT_FILES = ['**/*.graphql']
55
67
  */
56
68
  const graphqlExtractedDocumentLint = {
57
69
  files: GRAPHQL_EXTRACTED_DOCUMENT_FILES,
70
+ ignores: GRAPHQL_EXTRACTED_IGNORES,
58
71
  languageOptions: {
59
72
  parser: graphqlParserWithConfigAnchor
60
73
  },
@@ -74,6 +87,7 @@ const graphqlExtractedDocumentLint = {
74
87
  */
75
88
  const graphqlExtractedDocumentLintVueUniqueOperationOverride = {
76
89
  files: ['**/*.vue/**/*.graphql'],
90
+ ignores: GRAPHQL_EXTRACTED_IGNORES,
77
91
  rules: {
78
92
  '@graphql-eslint/unique-operation-name': 'off'
79
93
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitra/eslint-config",
3
- "version": "3.6.3",
3
+ "version": "3.6.6",
4
4
  "description": "An ESLint shareable config for projects using Vue and Node",
5
5
  "keywords": [
6
6
  "eslint",