Skip to content

chore(lint): missing-metadata #311

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 2 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
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default [
},
// Override rules for test files to disable JSDoc rules
{
files: ['src/**/*.test.mjs'],
files: ['**/__tests__/**'],
rules: {
'jsdoc/check-alignment': 'off',
'jsdoc/check-indentation': 'off',
Expand Down
2 changes: 1 addition & 1 deletion src/linter/constants.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

export const INTRDOCUED_IN_REGEX = /<!--\s?introduced_in=.*-->/;
export const INTRODUCED_IN_REGEX = /<!--\s?introduced_in=.*-->/;

export const LLM_DESCRIPTION_REGEX = /<!--\s?llm_description=.*-->/;

Expand Down
12 changes: 2 additions & 10 deletions src/linter/rules/__tests__/duplicate-stability-nodes.test.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { deepStrictEqual, strictEqual } from 'node:assert';
import { describe, it, mock } from 'node:test';
import { describe, it } from 'node:test';

import { LINT_MESSAGES } from '../../constants.mjs';
import { duplicateStabilityNodes } from '../duplicate-stability-nodes.mjs';
import { createContext } from './utils.mjs';

// Mock data structure for creating test entries
const createStabilityNode = (value, line = 1, column = 1) => ({
Expand Down Expand Up @@ -39,15 +40,6 @@ const createHeadingNode = (depth, line = 1, column = 1) => ({
},
});

const createContext = (nodes, path = 'file.md') => ({
tree: {
type: 'root',
children: nodes,
},
path,
report: mock.fn(),
});

describe('duplicateStabilityNodes', () => {
it('should not report when there are no stability nodes', () => {
const context = createContext([
Expand Down
112 changes: 39 additions & 73 deletions src/linter/rules/__tests__/invalid-change-version.test.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { deepStrictEqual, strictEqual } from 'node:assert';
import { spawnSync } from 'node:child_process';
import { execPath } from 'node:process';
import { describe, it, mock } from 'node:test';
import { describe, it } from 'node:test';
import { fileURLToPath } from 'node:url';

import dedent from 'dedent';

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

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

const context = {
tree: {
type: 'root',
children: [
{
type: 'html',
value: yamlContent,
},
],
const context = createContext([
{
type: 'html',
value: yamlContent,
},
report: mock.fn(),
getIssues: mock.fn(),
};
]);

invalidChangeVersion(context);

Expand All @@ -50,23 +44,16 @@ changes:
- version:
-->`;

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

invalidChangeVersion(context);

Expand Down Expand Up @@ -126,19 +113,12 @@ changes:
- version: v5.0.0
-->`;

const context = {
tree: {
type: 'root',
children: [
{
type: 'html',
value: yamlContent,
},
],
const context = createContext([
{
type: 'html',
value: yamlContent,
},
report: mock.fn(),
getIssues: mock.fn(),
};
]);

invalidChangeVersion(context);

Expand All @@ -156,23 +136,16 @@ changes:
- version: v5.0.0
-->`;

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 },
},
},
],
const context = createContext([
{
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);
Expand Down Expand Up @@ -200,23 +173,16 @@ changes:
- version: v5.0.0
-->`;

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 },
},
},
],
const context = createContext([
{
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);
Expand Down
83 changes: 0 additions & 83 deletions src/linter/rules/__tests__/missing-introduced-in.test.mjs

This file was deleted.

54 changes: 54 additions & 0 deletions src/linter/rules/__tests__/missing-metadata.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { strictEqual } from 'node:assert';
import { describe, it } from 'node:test';

import { createContext } from './utils.mjs';
import { missingMetadata } from '../../rules/missing-metadata.mjs';

describe('missingMetadata', () => {
it('should not report when both fields are present', () => {
const context = createContext([
{ type: 'html', value: '<!--introduced_in=12.0.0-->' },
{ type: 'html', value: '<!--llm_description=desc-->' },
]);

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

it('should report only llm_description when introduced_in is present', () => {
const context = createContext([
{ type: 'html', value: '<!--introduced_in=12.0.0-->' },
]);

missingMetadata(context);
strictEqual(context.report.mock.callCount(), 1);
strictEqual(context.report.mock.calls[0].arguments[0].level, 'warn');
});

it('should not report llm_description when paragraph fallback exists', () => {
const context = createContext([
{ type: 'html', value: '<!--introduced_in=12.0.0-->' },
{ type: 'paragraph', children: [{ type: 'text', value: 'desc' }] },
]);

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

it('should report both when nothing is present', () => {
const context = createContext([{ type: 'heading', depth: 1 }]);

missingMetadata(context);
strictEqual(context.report.mock.callCount(), 2);
});

it('should report only introduced_in when llm_description is present', () => {
const context = createContext([
{ type: 'html', value: '<!--llm_description=desc-->' },
]);

missingMetadata(context);
strictEqual(context.report.mock.callCount(), 1);
strictEqual(context.report.mock.calls[0].arguments[0].level, 'info');
});
});
7 changes: 7 additions & 0 deletions src/linter/rules/__tests__/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { mock } from 'node:test';

export const createContext = children => ({
tree: { type: 'root', children },
report: mock.fn(),
getIssues: mock.fn(),
});
6 changes: 2 additions & 4 deletions src/linter/rules/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

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

Check warning on line 5 in src/linter/rules/index.mjs

View check run for this annotation

Codecov / codecov/patch

src/linter/rules/index.mjs#L5

Added line #L5 was not covered by tests

/**
* @type {Record<string, import('../types').LintRule>}
*/
export default {
'duplicate-stability-nodes': duplicateStabilityNodes,
'invalid-change-version': invalidChangeVersion,
'missing-introduced-in': missingIntroducedIn,
'missing-llm-description': missingLlmDescription,
'missing-metadata': missingMetadata,

Check warning on line 13 in src/linter/rules/index.mjs

View check run for this annotation

Codecov / codecov/patch

src/linter/rules/index.mjs#L13

Added line #L13 was not covered by tests
};
26 changes: 0 additions & 26 deletions src/linter/rules/missing-introduced-in.mjs

This file was deleted.

Loading
Loading