Skip to content

Commit 83d89b6

Browse files
committed
chore(lint): missing-metadata
1 parent 440da36 commit 83d89b6

11 files changed

+182
-253
lines changed

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default [
6565
},
6666
// Override rules for test files to disable JSDoc rules
6767
{
68-
files: ['src/**/*.test.mjs'],
68+
files: ['**/__tests__/**'],
6969
rules: {
7070
'jsdoc/check-alignment': 'off',
7171
'jsdoc/check-indentation': 'off',

src/linter/rules/__tests__/duplicate-stability-nodes.test.mjs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { deepStrictEqual, strictEqual } from 'node:assert';
2-
import { describe, it, mock } from 'node:test';
2+
import { describe, it } from 'node:test';
33

44
import { LINT_MESSAGES } from '../../constants.mjs';
55
import { duplicateStabilityNodes } from '../duplicate-stability-nodes.mjs';
6+
import { createContext } from './utils.mjs';
67

78
// Mock data structure for creating test entries
89
const createStabilityNode = (value, line = 1, column = 1) => ({
@@ -39,15 +40,6 @@ const createHeadingNode = (depth, line = 1, column = 1) => ({
3940
},
4041
});
4142

42-
const createContext = (nodes, path = 'file.md') => ({
43-
tree: {
44-
type: 'root',
45-
children: nodes,
46-
},
47-
path,
48-
report: mock.fn(),
49-
});
50-
5143
describe('duplicateStabilityNodes', () => {
5244
it('should not report when there are no stability nodes', () => {
5345
const context = createContext([

src/linter/rules/__tests__/invalid-change-version.test.mjs

Lines changed: 39 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { deepStrictEqual, strictEqual } from 'node:assert';
22
import { spawnSync } from 'node:child_process';
33
import { execPath } from 'node:process';
4-
import { describe, it, mock } from 'node:test';
4+
import { describe, it } from 'node:test';
55
import { fileURLToPath } from 'node:url';
66

77
import dedent from 'dedent';
88

99
import { invalidChangeVersion } from '../invalid-change-version.mjs';
10+
import { createContext } from './utils.mjs';
1011

1112
describe('invalidChangeVersion', () => {
1213
it('should not report if all change versions are non-empty', () => {
@@ -20,19 +21,12 @@ changes:
2021
- version: v5.0.0
2122
-->`;
2223

23-
const context = {
24-
tree: {
25-
type: 'root',
26-
children: [
27-
{
28-
type: 'html',
29-
value: yamlContent,
30-
},
31-
],
24+
const context = createContext([
25+
{
26+
type: 'html',
27+
value: yamlContent,
3228
},
33-
report: mock.fn(),
34-
getIssues: mock.fn(),
35-
};
29+
]);
3630

3731
invalidChangeVersion(context);
3832

@@ -50,23 +44,16 @@ changes:
5044
- version:
5145
-->`;
5246

53-
const context = {
54-
tree: {
55-
type: 'root',
56-
children: [
57-
{
58-
type: 'html',
59-
value: yamlContent,
60-
position: {
61-
start: { line: 1, column: 1, offset: 1 },
62-
end: { line: 1, column: 1, offset: 1 },
63-
},
64-
},
65-
],
47+
const context = createContext([
48+
{
49+
type: 'html',
50+
value: yamlContent,
51+
position: {
52+
start: { line: 1, column: 1, offset: 1 },
53+
end: { line: 1, column: 1, offset: 1 },
54+
},
6655
},
67-
report: mock.fn(),
68-
getIssues: mock.fn(),
69-
};
56+
]);
7057

7158
invalidChangeVersion(context);
7259

@@ -126,19 +113,12 @@ changes:
126113
- version: v5.0.0
127114
-->`;
128115

129-
const context = {
130-
tree: {
131-
type: 'root',
132-
children: [
133-
{
134-
type: 'html',
135-
value: yamlContent,
136-
},
137-
],
116+
const context = createContext([
117+
{
118+
type: 'html',
119+
value: yamlContent,
138120
},
139-
report: mock.fn(),
140-
getIssues: mock.fn(),
141-
};
121+
]);
142122

143123
invalidChangeVersion(context);
144124

@@ -156,23 +136,16 @@ changes:
156136
- version: v5.0.0
157137
-->`;
158138

159-
const context = {
160-
tree: {
161-
type: 'root',
162-
children: [
163-
{
164-
type: 'html',
165-
value: yamlContent,
166-
position: {
167-
start: { column: 1, line: 7, offset: 103 },
168-
end: { column: 35, line: 7, offset: 137 },
169-
},
170-
},
171-
],
139+
const context = createContext([
140+
{
141+
type: 'html',
142+
value: yamlContent,
143+
position: {
144+
start: { column: 1, line: 7, offset: 103 },
145+
end: { column: 35, line: 7, offset: 137 },
146+
},
172147
},
173-
report: mock.fn(),
174-
getIssues: mock.fn(),
175-
};
148+
]);
176149

177150
invalidChangeVersion(context);
178151
strictEqual(context.report.mock.callCount(), 1);
@@ -200,23 +173,16 @@ changes:
200173
- version: v5.0.0
201174
-->`;
202175

203-
const context = {
204-
tree: {
205-
type: 'root',
206-
children: [
207-
{
208-
type: 'html',
209-
value: yamlContent,
210-
position: {
211-
start: { column: 1, line: 7, offset: 103 },
212-
end: { column: 35, line: 7, offset: 137 },
213-
},
214-
},
215-
],
176+
const context = createContext([
177+
{
178+
type: 'html',
179+
value: yamlContent,
180+
position: {
181+
start: { column: 1, line: 7, offset: 103 },
182+
end: { column: 35, line: 7, offset: 137 },
183+
},
216184
},
217-
report: mock.fn(),
218-
getIssues: mock.fn(),
219-
};
185+
]);
220186

221187
invalidChangeVersion(context);
222188
strictEqual(context.report.mock.callCount(), 1);

src/linter/rules/__tests__/missing-introduced-in.test.mjs

Lines changed: 0 additions & 83 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { strictEqual } from 'node:assert';
2+
import { describe, it } from 'node:test';
3+
4+
import { createContext } from './utils.mjs';
5+
import { missingMetadata } from '../../rules/missing-metadata.mjs';
6+
7+
describe('missingMetadata', () => {
8+
it('should not report when both fields are present', () => {
9+
const context = createContext([
10+
{ type: 'html', value: '<!--introduced_in=12.0.0-->' },
11+
{ type: 'html', value: '<!--llm_description=desc-->' },
12+
]);
13+
14+
missingMetadata(context);
15+
strictEqual(context.report.mock.callCount(), 0);
16+
});
17+
18+
it('should report only llm_description when introduced_in is present', () => {
19+
const context = createContext([
20+
{ type: 'html', value: '<!--introduced_in=12.0.0-->' },
21+
]);
22+
23+
missingMetadata(context);
24+
strictEqual(context.report.mock.callCount(), 1);
25+
strictEqual(context.report.mock.calls[0].arguments[0].level, 'warn');
26+
});
27+
28+
it('should not report llm_description when paragraph fallback exists', () => {
29+
const context = createContext([
30+
{ type: 'html', value: '<!--introduced_in=12.0.0-->' },
31+
{ type: 'paragraph', children: [{ type: 'text', value: 'desc' }] },
32+
]);
33+
34+
missingMetadata(context);
35+
strictEqual(context.report.mock.callCount(), 0);
36+
});
37+
38+
it('should report both when nothing is present', () => {
39+
const context = createContext([{ type: 'heading', depth: 1 }]);
40+
41+
missingMetadata(context);
42+
strictEqual(context.report.mock.callCount(), 2);
43+
});
44+
45+
it('should report only introduced_in when llm_description is present', () => {
46+
const context = createContext([
47+
{ type: 'html', value: '<!--llm_description=desc-->' },
48+
]);
49+
50+
missingMetadata(context);
51+
strictEqual(context.report.mock.callCount(), 1);
52+
strictEqual(context.report.mock.calls[0].arguments[0].level, 'info');
53+
});
54+
});

src/linter/rules/__tests__/utils.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { mock } from 'node:test';
2+
3+
export const createContext = children => ({
4+
tree: { type: 'root', children },
5+
report: mock.fn(),
6+
getIssues: mock.fn(),
7+
});

src/linter/rules/index.mjs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22

33
import { duplicateStabilityNodes } from './duplicate-stability-nodes.mjs';
44
import { invalidChangeVersion } from './invalid-change-version.mjs';
5-
import { missingIntroducedIn } from './missing-introduced-in.mjs';
6-
import { missingLlmDescription } from './missing-llm-description.mjs';
5+
import { missingMetadata } from './missing-metadata.mjs';
76

87
/**
98
* @type {Record<string, import('../types').LintRule>}
109
*/
1110
export default {
1211
'duplicate-stability-nodes': duplicateStabilityNodes,
1312
'invalid-change-version': invalidChangeVersion,
14-
'missing-introduced-in': missingIntroducedIn,
15-
'missing-llm-description': missingLlmDescription,
13+
'missing-metadata': missingMetadata,
1614
};

src/linter/rules/missing-introduced-in.mjs

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)