@nitra/eslint-config 3.6.3 → 3.6.4
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/graphql-eslint-anchor.js +42 -1
- package/index.js +5 -0
- package/package.json +1 -1
package/graphql-eslint-anchor.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
|
@@ -55,6 +58,7 @@ const GRAPHQL_EXTRACTED_DOCUMENT_FILES = ['**/*.graphql']
|
|
|
55
58
|
*/
|
|
56
59
|
const graphqlExtractedDocumentLint = {
|
|
57
60
|
files: GRAPHQL_EXTRACTED_DOCUMENT_FILES,
|
|
61
|
+
ignores: GRAPHQL_EXTRACTED_IGNORES,
|
|
58
62
|
languageOptions: {
|
|
59
63
|
parser: graphqlParserWithConfigAnchor
|
|
60
64
|
},
|
|
@@ -74,6 +78,7 @@ const graphqlExtractedDocumentLint = {
|
|
|
74
78
|
*/
|
|
75
79
|
const graphqlExtractedDocumentLintVueUniqueOperationOverride = {
|
|
76
80
|
files: ['**/*.vue/**/*.graphql'],
|
|
81
|
+
ignores: GRAPHQL_EXTRACTED_IGNORES,
|
|
77
82
|
rules: {
|
|
78
83
|
'@graphql-eslint/unique-operation-name': 'off'
|
|
79
84
|
}
|