Skip to content

Commit bc58ae3

Browse files
Simon Heatherdatho7561
authored andcommitted
Refine tests and JSDocs
1 parent c441922 commit bc58ae3

File tree

2 files changed

+6
-43
lines changed

2 files changed

+6
-43
lines changed

src/diagnostic-filter.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
* Pattern that matches a `# yaml-lint-disable` comment.
99
*
1010
* Usage in YAML files:
11-
* # yaml-lint-disable ← suppress ALL diagnostics on the next line
12-
* # yaml-lint-disable Incorrect type ← suppress diagnostics whose message contains "Incorrect type"
13-
* # yaml-lint-disable Incorrect type, not accepted ← suppress diagnostics matching any of the substrings
11+
*
12+
* - `# yaml-lint-disable` - suppress ALL diagnostics on the next line
13+
* - `# yaml-lint-disable Incorrect type` - suppress diagnostics whose message contains "Incorrect type"
14+
* - `# yaml-lint-disable Incorrect type, not accepted` - suppress diagnostics matching any of the substrings
1415
*
1516
* Capture group 1 (optional) contains the comma-separated list of message
1617
* substrings to match against. If absent, all diagnostics are suppressed.

test/diagnostic-filter.test.ts

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,6 @@ function linesOf(lines: string[]): GetLineText {
2828
// Pattern matching
2929
// ---------------------------------------------------------------------------
3030
describe('YAML_LINT_DISABLE_PATTERN', () => {
31-
it('should match a plain disable comment', () => {
32-
expect(YAML_LINT_DISABLE_PATTERN.test('# yaml-lint-disable')).to.be.true;
33-
});
34-
35-
it('should match with leading whitespace', () => {
36-
expect(YAML_LINT_DISABLE_PATTERN.test(' # yaml-lint-disable')).to.be.true;
37-
});
38-
39-
it('should match with extra spaces after #', () => {
40-
expect(YAML_LINT_DISABLE_PATTERN.test('# yaml-lint-disable')).to.be.true;
41-
});
42-
43-
it('should match with specifiers after the keyword', () => {
44-
expect(YAML_LINT_DISABLE_PATTERN.test('# yaml-lint-disable Incorrect type')).to.be.true;
45-
});
46-
4731
it('should capture specifiers in group 1', () => {
4832
const match = YAML_LINT_DISABLE_PATTERN.exec('# yaml-lint-disable Incorrect type, not accepted');
4933
expect(match).to.not.be.null;
@@ -55,22 +39,6 @@ describe('YAML_LINT_DISABLE_PATTERN', () => {
5539
expect(match).to.not.be.null;
5640
expect(match[1].trim()).to.equal('');
5741
});
58-
59-
it('should not match a regular comment', () => {
60-
expect(YAML_LINT_DISABLE_PATTERN.test('# this is a regular comment')).to.be.false;
61-
});
62-
63-
it('should not match a partial keyword', () => {
64-
expect(YAML_LINT_DISABLE_PATTERN.test('# yaml-lint-disabl')).to.be.false;
65-
});
66-
67-
it('should not match without the hash', () => {
68-
expect(YAML_LINT_DISABLE_PATTERN.test('yaml-lint-disable')).to.be.false;
69-
});
70-
71-
it('should not match an inline value that contains the phrase', () => {
72-
expect(YAML_LINT_DISABLE_PATTERN.test('key: value # yaml-lint-disable')).to.be.false;
73-
});
7442
});
7543

7644
// ---------------------------------------------------------------------------
@@ -137,7 +105,7 @@ describe('shouldSuppressDiagnostic', () => {
137105
describe('filterSuppressedDiagnostics', () => {
138106
// Use inline arrows for getStartLine and getMessage so TypeScript infers T
139107
// from the diagnostics array and preserves all properties on the result.
140-
const filter = (diagnostics: ReturnType<typeof makeDiag>[], lines: GetLineText) =>
108+
const filter = (diagnostics: ReturnType<typeof makeDiag>[], lines: GetLineText): ReturnType<typeof makeDiag>[] =>
141109
filterSuppressedDiagnostics(
142110
diagnostics,
143111
(d) => d.startLine,
@@ -234,13 +202,7 @@ describe('filterSuppressedDiagnostics', () => {
234202
});
235203

236204
it('should handle multiple disable comments for different lines', () => {
237-
const lines = linesOf([
238-
'# yaml-lint-disable',
239-
'line1: bad',
240-
'line2: ok',
241-
'# yaml-lint-disable',
242-
'line4: also-bad',
243-
]);
205+
const lines = linesOf(['# yaml-lint-disable', 'line1: bad', 'line2: ok', '# yaml-lint-disable', 'line4: also-bad']);
244206
const diagnostics = [makeDiag(1, 'error on line 1'), makeDiag(2, 'error on line 2'), makeDiag(4, 'error on line 4')];
245207

246208
const result = filter(diagnostics, lines);

0 commit comments

Comments
 (0)