Skip to content

feat: improve changes issues positions #313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/linter/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const LLM_DESCRIPTION_REGEX = /<!--\s?llm_description=.*-->/;

export const LINT_MESSAGES = {
missingIntroducedIn: "Missing 'introduced_in' field in the API doc entry",
invalidChangeProperty: 'Invalid change property type',
missingChangeVersion: 'Missing version field in the API doc entry',
invalidChangeVersion: 'Invalid version number: {{version}}',
duplicateStabilityNode: 'Duplicate stability node',
Expand Down
245 changes: 196 additions & 49 deletions src/linter/rules/__tests__/invalid-change-version.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import { invalidChangeVersion } from '../invalid-change-version.mjs';
describe('invalidChangeVersion', () => {
it('should not report if all change versions are non-empty', () => {
const yamlContent = dedent`
<!-- YAML
changes:
- version:
- v15.7.0
- v14.18.0
- version: v6.4.0
- version: v5.0.0
-->`;
<!-- YAML
changes:
- version:
- v15.7.0
- v14.18.0
- version: v6.4.0
- version: v5.0.0
-->`;

const context = {
tree: {
Expand All @@ -41,14 +41,11 @@ changes:

it('should report an issue if a change version is missing', () => {
const yamlContent = dedent`
<!-- YAML
changes:
- version:
- v15.7.0
- v14.18.0
- version: v6.4.0
- version:
-->`;
<!-- YAML
changes:
- version:
- pr-url: https://github.com/nodejs/node/pull/1
-->`;

const context = {
tree: {
Expand All @@ -70,17 +67,27 @@ changes:

invalidChangeVersion(context);

strictEqual(context.report.mock.callCount(), 1);
strictEqual(context.report.mock.callCount(), 2);

const call = context.report.mock.calls[0];
const callArguments = context.report.mock.calls.flatMap(
call => call.arguments
);

deepStrictEqual(call.arguments, [
deepStrictEqual(callArguments, [
{
level: 'error',
message: 'Missing version field in the API doc entry',
position: {
start: { line: 3 },
end: { line: 3 },
},
},
{
level: 'error',
message: 'Missing version field in the API doc entry',
position: {
start: { line: 1, column: 1, offset: 1 },
end: { line: 1, column: 1, offset: 1 },
start: { line: 4 },
end: { line: 4 },
},
},
]);
Expand Down Expand Up @@ -117,14 +124,14 @@ changes:

it('should not report if all change versions are valid', () => {
const yamlContent = dedent`
<!-- YAML
changes:
- version:
- v15.7.0
- v14.18.0
- version: v6.4.0
- version: v5.0.0
-->`;
<!-- YAML
changes:
- version:
- v15.7.0
- v14.18.0
- version: v6.4.0
- version: v5.0.0
-->`;

const context = {
tree: {
Expand All @@ -147,14 +154,14 @@ changes:

it('should report an issue if a change version is invalid', () => {
const yamlContent = dedent`
<!-- YAML
changes:
- version:
- v13.9.0
- INVALID_VERSION
- version: v6.4.0
- version: v5.0.0
-->`;
<!-- YAML
changes:
- version:
- v13.9.0
- INVALID_VERSION
- version: v6.4.0
- version: v5.0.0
-->`;

const context = {
tree: {
Expand Down Expand Up @@ -182,23 +189,23 @@ changes:
level: 'error',
message: 'Invalid version number: INVALID_VERSION',
position: {
start: { column: 1, line: 7, offset: 103 },
end: { column: 35, line: 7, offset: 137 },
start: { line: 11 },
end: { line: 11 },
},
},
]);
});

it('should report an issue if a change version contains a REPLACEME and a version', () => {
const yamlContent = dedent`
<!-- YAML
changes:
- version:
- v24.0.0
- REPLACEME
- version: v6.4.0
- version: v5.0.0
-->`;
<!-- YAML
changes:
- version:
- v24.0.0
- REPLACEME
- version: v6.4.0
- version: v5.0.0
-->`;

const context = {
tree: {
Expand Down Expand Up @@ -226,10 +233,150 @@ changes:
level: 'error',
message: 'Invalid version number: REPLACEME',
position: {
start: { column: 1, line: 7, offset: 103 },
end: { column: 35, line: 7, offset: 137 },
start: { line: 11 },
end: { line: 11 },
},
},
]);
});

it('should report an issue if changes is not a sequence', () => {
const yamlContent = dedent`
<!-- YAML
changes:
abc:
def:
-->`;

const context = {
tree: {
type: 'root',
children: [
{
type: 'html',
value: yamlContent,
position: {
start: { column: 1, line: 7, offset: 103 },
end: { column: 35, line: 7, offset: 137 },
},
},
],
},
report: mock.fn(),
getIssues: mock.fn(),
};

invalidChangeVersion(context);
strictEqual(context.report.mock.callCount(), 1);
const call = context.report.mock.calls[0];
deepStrictEqual(call.arguments, [
{
level: 'error',
message: 'Invalid change property type',
position: {
start: { line: 8 },
end: { line: 8 },
},
},
]);
});

it('should report an issue if version is not a mapping', () => {
const yamlContent = dedent`
<!-- YAML
changes:
version:
- abc
- def
-->`;

const context = {
tree: {
type: 'root',
children: [
{
type: 'html',
value: yamlContent,
position: {
start: { column: 1, line: 7, offset: 103 },
end: { column: 35, line: 7, offset: 137 },
},
},
],
},
report: mock.fn(),
getIssues: mock.fn(),
};

invalidChangeVersion(context);
strictEqual(context.report.mock.callCount(), 1);
const call = context.report.mock.calls[0];
deepStrictEqual(call.arguments, [
{
level: 'error',
message: 'Invalid change property type',
position: {
start: { line: 8 },
end: { line: 8 },
},
},
]);
});

it("should skip validations if yaml root node isn't a mapping", () => {
const yamlContent = dedent`
<!-- YAML
- abc
- def
-->`;

const context = {
tree: {
type: 'root',
children: [
{
type: 'html',
value: yamlContent,
position: {
start: { column: 1, line: 7, offset: 103 },
end: { column: 35, line: 7, offset: 137 },
},
},
],
},
report: mock.fn(),
getIssues: mock.fn(),
};

invalidChangeVersion(context);
strictEqual(context.report.mock.callCount(), 0);
});

it('should skip validations if changes node is missing', () => {
const yamlContent = dedent`
<!-- YAML
added: v0.1.91
-->`;

const context = {
tree: {
type: 'root',
children: [
{
type: 'html',
value: yamlContent,
position: {
start: { column: 1, line: 7, offset: 103 },
end: { column: 35, line: 7, offset: 137 },
},
},
],
},
report: mock.fn(),
getIssues: mock.fn(),
};

invalidChangeVersion(context);
strictEqual(context.report.mock.callCount(), 0);
});
});
Loading
Loading