Preserve advisory detector settings

AI assistance was used to reproduce and fix automated review feedback, add regression coverage, and run validation.
This commit is contained in:
Paul Bakaus
2026-08-03 09:38:02 -07:00
parent dd0279b6bd
commit 3125864d1a
2 changed files with 20 additions and 1 deletions
+7 -1
View File
@@ -166,7 +166,7 @@ function readRawConfigFile(filePath) {
}
}
const DETECTOR_CONFIG_KEYS = new Set(['ignoreRules', 'ignoreFiles', 'ignoreValues', 'designSystem']);
const DETECTOR_CONFIG_KEYS = new Set(['ignoreRules', 'ignoreFiles', 'ignoreValues', 'designSystem', 'advisoryRules']);
function hookSection(unified) {
return unified && typeof unified === 'object' && !Array.isArray(unified) && unified.hook && typeof unified.hook === 'object' && !Array.isArray(unified.hook)
@@ -259,12 +259,18 @@ function mergeDetectorConfig(existing, seed = null) {
if (seed?.designSystem && typeof seed.designSystem === 'object' && !Array.isArray(seed.designSystem)) {
out.designSystem = { ...seed.designSystem };
}
if (seed?.advisoryRules === 'include' || seed?.advisoryRules === 'exclude') {
out.advisoryRules = seed.advisoryRules;
}
if (base.designSystem && typeof base.designSystem === 'object' && !Array.isArray(base.designSystem)) {
out.designSystem = {
...(out.designSystem || {}),
enabled: base.designSystem.enabled === false ? false : true,
};
}
if (base.advisoryRules === 'include' || base.advisoryRules === 'exclude') {
out.advisoryRules = base.advisoryRules;
}
if (Array.isArray(base.ignoreRules)) {
out.ignoreRules = Array.from(new Set([...out.ignoreRules, ...base.ignoreRules.map(String)]));
}
+13
View File
@@ -994,6 +994,19 @@ describe('hook-admin.mjs', () => {
assert.match(out, /local detector\.ignoreFiles/);
});
it('ignore-file --local preserves the local advisory-rule preference', () => {
fs.mkdirSync(path.dirname(getLocalConfigPath(cwd)), { recursive: true });
fs.writeFileSync(getLocalConfigPath(cwd), JSON.stringify({
detector: { advisoryRules: 'include' },
}));
runAdmin(['ignore-file', '/abs/path/personal.html', '--local']);
const local = JSON.parse(fs.readFileSync(getLocalConfigPath(cwd), 'utf-8')).detector;
assert.equal(local.advisoryRules, 'include');
assert.deepEqual(local.ignoreFiles, ['/abs/path/personal.html']);
});
it('ignore-file refuses unsupported reasons and unknown flags', () => {
assert.throws(
() => runAdmin(['ignore-file', 'src/legacy/**', '--reason', 'machine-local path']),