8000 #20: align catalogue smell titles with docs/smell-vocabulary.md by devill · Pull Request #29 · habit-hooks/habit-hooks · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/config/catalogue.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { describe, expect, it } from 'vitest';
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
import { defaultRules } from './catalogue.js';

const vocabularyPath = join(dirname(fileURLToPath(import.meta.url)), '../../docs/smell-vocabulary.md');

function parseCatalogueTitles(): Map<string, string> {
const lines = readFileSync(vocabularyPath, 'utf8').split('\n');
const titles = new Map<string, string>();
for (const line of lines) {
const match = line.match(/^\|\s*`([^`]+)`\s*\|\s*(.+?)\s*\|\s*\w+\s*\|$/);
if (match) titles.set(match[1], match[2]);
}
return titles;
}

describe('catalogue titles', () => {
const canonicalTitles = parseCatalogueTitles();

it('match the canonical titles in docs/smell-vocabulary.md', () => {
for (const rule of defaultRules) {
expect(canonicalTitles.get(rule.id), `no vocabulary entry for ${rule.id}`).toBeDefined();
expect(rule.title, `title drift for ${rule.id}`).toBe(canonicalTitles.get(rule.id));
}
});
});
8 changes: 4 additions & 4 deletions src/config/catalogue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const tier2Rules: Rule[] = [
source: 'eslint',
sourceRuleId: 'no-var',
severity: 'enforced',
title: 'var declaration',
title: '`var` declaration',
description: 'Use let or const; var hoists in surprising ways.',
},
{
Expand All @@ -89,7 +89,7 @@ const tier2Rules: Rule[] = [
source: 'eslint',
sourceRuleId: 'no-warning-comments',
severity: 'suggested',
title: 'Warning comment',
title: 'Warning comment (TODO/FIXME/…)',
description: 'TODO / FIXME / XXX / HACK markers are unfinished work in the codebase.',
},
];
Expand All @@ -101,7 +101,7 @@ const tier3Rules: Rule[] = [
sourceRuleId: '@typescript-eslint/no-explicit-any',
severity: 'suggested',
changedFilesOnly: true,
title: 'Explicit any',
title: 'Explicit `any`',
description: 'any disables the type checker; prefer a precise type or unknown plus a narrow.',
},
{
Expand Down Expand Up @@ -129,7 +129,7 @@ const customRules: Rule[] = [
source: 'custom',
severity: 'suggested',
changedFilesOnly: true,
title: 'Comment found',
title: 'Non-essential comment',
description: 'Comments indicate code that is not self-documenting.',
},
];
Expand Down
0