@7n/rules 1.49.15 → 1.49.16
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/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@ type: JS Module
|
|
|
3
3
|
title: run-detectors.mjs
|
|
4
4
|
resource: npm/scripts/lib/lint-surface/run-detectors.mjs
|
|
5
5
|
docgen:
|
|
6
|
-
crc:
|
|
6
|
+
crc: 9f044303
|
|
7
7
|
model: openai-codex/gpt-5.4-mini
|
|
8
8
|
tier: cloud-min
|
|
9
9
|
score: 100
|
|
@@ -19,7 +19,7 @@ docgen:
|
|
|
19
19
|
|
|
20
20
|
DEFAULT_RULES_DIR задає базовий корінь правил, від якого стартує discovery, коли споживач не передав власні каталоги.
|
|
21
21
|
|
|
22
|
-
buildDetectPlan спочатку визначає набір rules-каталогів,
|
|
22
|
+
buildDetectPlan спочатку визначає набір rules-каталогів, відбирає concern-и за capability і застосовує опційний rule-level `applies` gate. Лише після цього він будує план виконання за режимом прогону: scoped, delta, full або repo-wide. Сам план фіксує, які concern-и запускаються whole-repo, а які лише по перетину з файлами, щоб detect і fix-pipeline працювали з однаковою картиною.
|
|
23
23
|
|
|
24
24
|
loadEnabledLintRules використовує той самий discovery-ланцюжок, але повертає не план, а повну мапу concern-и за rule-id разом із множиною активних правил. Це потрібно зовнішнім споживачам, які мають знати, що реально доступно для прогону, не запускаючи сам detector-цикл.
|
|
25
25
|
|
|
@@ -42,6 +42,8 @@ concern тригериться на цих файлах (та сама табл
|
|
|
42
42
|
full-scope перевірки — справа `--repo-wide`).
|
|
43
43
|
- detectAll — Запускає detect-only прохід. Повертає всі violations і похідний exitCode.
|
|
44
44
|
|
|
45
|
+
Rule-level `applies` у `<rule>/applies/main.mjs` може повернути `false`, щоб виключити всі concern-и правила з плану для поточного репозиторію.
|
|
46
|
+
|
|
45
47
|
## Гарантії поведінки
|
|
46
48
|
|
|
47
49
|
- Власних операцій запису (ФС/БД) у файлі немає; виклики імпортованих модулів можуть писати.
|
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
* @typedef {import('../concern-meta.mjs').ConcernMeta} ConcernMeta
|
|
10
10
|
* @typedef {{ ruleId: string, concern: ConcernMeta }} LintEntry
|
|
11
11
|
*/
|
|
12
|
+
import { existsSync } from 'node:fs'
|
|
12
13
|
import { dirname, join } from 'node:path'
|
|
13
14
|
import { env } from 'node:process'
|
|
14
|
-
import { fileURLToPath } from 'node:url'
|
|
15
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
15
16
|
|
|
16
17
|
import picomatch from 'picomatch'
|
|
17
18
|
|
|
@@ -126,6 +127,46 @@ async function filterByCapabilities(byRule, opts) {
|
|
|
126
127
|
return out
|
|
127
128
|
}
|
|
128
129
|
|
|
130
|
+
/**
|
|
131
|
+
* Застосовує опційний rule-level gate з `<rule>/applies/main.mjs` до всіх
|
|
132
|
+
* concern-ів правила. Це потрібно для доменних правил, чий канон має сенс
|
|
133
|
+
* лише за наявності конкретної topology в репозиторії: один gate не дає
|
|
134
|
+
* policy- й JS-concern-ам розійтися у власних евристиках застосовності.
|
|
135
|
+
*
|
|
136
|
+
* @param {Record<string, ConcernMeta[]>} byRule concerns за rule-id.
|
|
137
|
+
* @param {string} cwd корінь репозиторію, який лінтиться.
|
|
138
|
+
* @returns {Promise<Record<string, ConcernMeta[]>>} лише застосовні правила.
|
|
139
|
+
*/
|
|
140
|
+
async function filterByRuleApplies(byRule, cwd) {
|
|
141
|
+
/** @type {Record<string, ConcernMeta[]>} */
|
|
142
|
+
const out = {}
|
|
143
|
+
for (const [ruleId, concerns] of Object.entries(byRule)) {
|
|
144
|
+
const firstConcern = concerns[0]
|
|
145
|
+
if (!firstConcern) continue
|
|
146
|
+
const appliesPath = join(dirname(firstConcern.dir), 'applies', 'main.mjs')
|
|
147
|
+
if (!existsSync(appliesPath)) {
|
|
148
|
+
out[ruleId] = concerns
|
|
149
|
+
continue
|
|
150
|
+
}
|
|
151
|
+
let applies
|
|
152
|
+
try {
|
|
153
|
+
const mod = await import(pathToFileURL(appliesPath).href)
|
|
154
|
+
applies = mod.applies
|
|
155
|
+
} catch (error) {
|
|
156
|
+
throw new Error(`rule ${ruleId}: не вдалося завантажити applies gate: ${error.message}`)
|
|
157
|
+
}
|
|
158
|
+
if (applies === undefined) {
|
|
159
|
+
out[ruleId] = concerns
|
|
160
|
+
continue
|
|
161
|
+
}
|
|
162
|
+
if (typeof applies !== 'function') {
|
|
163
|
+
throw new Error(`rule ${ruleId}: applies/main.mjs має експортувати applies(cwd)`)
|
|
164
|
+
}
|
|
165
|
+
if (await applies(cwd)) out[ruleId] = concerns
|
|
166
|
+
}
|
|
167
|
+
return out
|
|
168
|
+
}
|
|
169
|
+
|
|
129
170
|
/**
|
|
130
171
|
* Мердж concerns кількох rules-каталогів: правила зливаються за id, концерни — за іменем
|
|
131
172
|
* (перший власник виграє: ядро → плагіни у порядку списку). Плагін може ДОДАВАТИ концерни
|
|
@@ -267,7 +308,8 @@ export async function buildDetectPlan(opts) {
|
|
|
267
308
|
*/
|
|
268
309
|
export async function loadEnabledLintRules(opts) {
|
|
269
310
|
const rulesDirs = await effectiveRulesDirs(opts)
|
|
270
|
-
const
|
|
311
|
+
const capable = await filterByCapabilities(await readLintConcernsByRuleMulti(rulesDirs), opts)
|
|
312
|
+
const byRule = await filterByRuleApplies(capable, opts.cwd)
|
|
271
313
|
const enabledSet = new Set(await enabledRuleIds(byRule, opts.cwd, rulesDirs))
|
|
272
314
|
return { byRule, enabledSet }
|
|
273
315
|
}
|
|
@@ -618,7 +660,8 @@ export async function detectAll(opts) {
|
|
|
618
660
|
const baseLog = opts.log ?? (s => process.stdout.write(s))
|
|
619
661
|
|
|
620
662
|
const rulesDirs = await effectiveRulesDirs(opts)
|
|
621
|
-
const
|
|
663
|
+
const capable = await filterByCapabilities(await readLintConcernsByRuleMulti(rulesDirs), opts)
|
|
664
|
+
const byRule = await filterByRuleApplies(capable, cwd)
|
|
622
665
|
const plan = await buildPlan({
|
|
623
666
|
byRule,
|
|
624
667
|
full,
|