@nitra/eslint-config 3.6.7 → 3.6.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/graphql-eslint-anchor.js +2 -1
- package/index.js +82 -2
- package/package.json +1 -1
package/graphql-eslint-anchor.js
CHANGED
|
@@ -163,9 +163,10 @@ const baseParser = graphqlEslintPlugin.parser
|
|
|
163
163
|
*/
|
|
164
164
|
export function graphqlParseForESLintWithAnchor(code, options = {}) {
|
|
165
165
|
const filePath = options.filePath || ''
|
|
166
|
+
const anchoredFilePath = graphQLConfigPathAnchor(filePath)
|
|
166
167
|
const parsed = baseParser.parseForESLint(code, {
|
|
167
168
|
...options,
|
|
168
|
-
filePath:
|
|
169
|
+
filePath: anchoredFilePath
|
|
169
170
|
})
|
|
170
171
|
const sibs = parsed.services?.siblingOperations
|
|
171
172
|
if (sibs) {
|
package/index.js
CHANGED
|
@@ -61,6 +61,84 @@ const GRAPHQL_EXTRACTED_DOCUMENT_FILES = [
|
|
|
61
61
|
'**/*.cjs/*.graphql'
|
|
62
62
|
]
|
|
63
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Обгортає правило graphql-eslint і логує runtime-падіння visitor callbacks, не змінюючи поведінку (після логу помилка перевикидається).
|
|
66
|
+
* @param {import('eslint').Rule.RuleModule} ruleImpl оригінальна імплементація правила
|
|
67
|
+
* @param {string} ruleName ім'я правила для debug payload
|
|
68
|
+
* @returns {import('eslint').Rule.RuleModule} обгорнуте правило з runtime-логуванням
|
|
69
|
+
*/
|
|
70
|
+
function instrumentGraphqlRuleForDebug(ruleImpl, ruleName) {
|
|
71
|
+
if (!ruleImpl?.create) {
|
|
72
|
+
return ruleImpl
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
...ruleImpl,
|
|
76
|
+
create(context) {
|
|
77
|
+
const visitors = ruleImpl.create(context)
|
|
78
|
+
return Object.fromEntries(
|
|
79
|
+
Object.entries(visitors).map(([selector, callback]) => [
|
|
80
|
+
selector,
|
|
81
|
+
/**
|
|
82
|
+
* Обгортка visitor callback з guard для відомого падіння no-deprecated.
|
|
83
|
+
* @param {unknown[]} args аргументи visitor від graphql-eslint
|
|
84
|
+
* @returns {unknown} результат оригінального callback (або `undefined` для відомого crash-case)
|
|
85
|
+
*/
|
|
86
|
+
(...args) => {
|
|
87
|
+
try {
|
|
88
|
+
return callback(...args)
|
|
89
|
+
} catch (error) {
|
|
90
|
+
const knownNoDeprecatedCrash =
|
|
91
|
+
ruleName === '@graphql-eslint/no-deprecated' &&
|
|
92
|
+
selector === 'ObjectValue' &&
|
|
93
|
+
error instanceof TypeError &&
|
|
94
|
+
error.message.includes("deprecationReason")
|
|
95
|
+
if (knownNoDeprecatedCrash) {
|
|
96
|
+
return
|
|
97
|
+
}
|
|
98
|
+
throw error
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
])
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const graphqlEslintPluginWithDebug = {
|
|
108
|
+
...graphqlEslintPlugin,
|
|
109
|
+
rules: {
|
|
110
|
+
...graphqlEslintPlugin.rules,
|
|
111
|
+
'no-deprecated': instrumentGraphqlRuleForDebug(
|
|
112
|
+
graphqlEslintPlugin.rules['no-deprecated'],
|
|
113
|
+
'@graphql-eslint/no-deprecated'
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* `@graphql-eslint/naming-convention` з operations-recommended плюс сумісність із Hasura:
|
|
120
|
+
* аргументи на кшталт `_set`, `_eq` мають провідний підкреслювач — без `allowLeadingUnderscore`
|
|
121
|
+
* правило глобально лає будь-який `Name`, що починається з `_` (не лише camelCase для змінних).
|
|
122
|
+
* @see https://the-guild.dev/graphql/eslint/rules/naming-convention
|
|
123
|
+
*/
|
|
124
|
+
const graphqlNamingConventionHasuraFriendly = [
|
|
125
|
+
'error',
|
|
126
|
+
{
|
|
127
|
+
allowLeadingUnderscore: true,
|
|
128
|
+
VariableDefinition: 'camelCase',
|
|
129
|
+
OperationDefinition: {
|
|
130
|
+
style: 'PascalCase',
|
|
131
|
+
forbiddenPrefixes: ['Query', 'Mutation', 'Subscription', 'Get'],
|
|
132
|
+
forbiddenSuffixes: ['Query', 'Mutation', 'Subscription']
|
|
133
|
+
},
|
|
134
|
+
FragmentDefinition: {
|
|
135
|
+
style: 'PascalCase',
|
|
136
|
+
forbiddenPrefixes: ['Fragment'],
|
|
137
|
+
forbiddenSuffixes: ['Fragment']
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
]
|
|
141
|
+
|
|
64
142
|
/**
|
|
65
143
|
* Правила для витягнутих GraphQL-блоків: пресет operations-recommended (поля, типи, змінні).
|
|
66
144
|
* Схема та documents підтягуються через graphql-config (файл налаштувань у корені пакета з операціями, зазвичай YAML).
|
|
@@ -73,10 +151,12 @@ const graphqlExtractedDocumentLint = {
|
|
|
73
151
|
},
|
|
74
152
|
plugins: {
|
|
75
153
|
// ESLint 10: graphql-eslint ще викликає context.getSourceCode() у частині правил — fixup з @eslint/compat.
|
|
76
|
-
'@graphql-eslint': fixupPluginRules(
|
|
154
|
+
'@graphql-eslint': fixupPluginRules(graphqlEslintPluginWithDebug)
|
|
77
155
|
},
|
|
78
156
|
rules: {
|
|
79
|
-
...graphqlEslintPlugin.configs['flat/operations-recommended'].rules
|
|
157
|
+
...graphqlEslintPlugin.configs['flat/operations-recommended'].rules,
|
|
158
|
+
'@graphql-eslint/naming-convention': graphqlNamingConventionHasuraFriendly,
|
|
159
|
+
'@graphql-eslint/no-deprecated': 'error'
|
|
80
160
|
}
|
|
81
161
|
}
|
|
82
162
|
|