Skip to content

Commit 5b34883

Browse files
committed
code review
1 parent fba5ee2 commit 5b34883

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,38 @@ import { env } from 'node:process';
44

55
const NODE_RELEASED_VERSIONS = env.NODE_RELEASED_VERSIONS?.split(',');
66

7+
/**
8+
* Checks if the given version is "REPLACEME" and the array length is 1.
9+
*
10+
* @param {string} version - The version to check.
11+
* @param {number} length - Length of the version array.
12+
* @returns {boolean} True if conditions match, otherwise false.
13+
*/
14+
const isValidReplaceMe = (version, length) =>
15+
length === 1 && version === 'REPLACEME';
16+
717
/**
818
* Determines if a given version is invalid.
919
*
1020
* @param {string} version - The version to check.
11-
* @returns {boolean} True if the version is invalid, false otherwise.
21+
* @param {unknown} _ - Unused parameter.
22+
* @param {{ length: number }} context - Array containing the length property.
23+
* @returns {boolean} True if the version is invalid, otherwise false.
1224
*/
1325
const isInvalid = NODE_RELEASED_VERSIONS
14-
? version =>
15-
version !== 'REPLACEME' &&
16-
!NODE_RELEASED_VERSIONS.includes(version.replace(/^v/, ''))
17-
: version => version !== 'REPLACEME' && !valid(version);
26+
? (version, _, { length }) =>
27+
!(
28+
isValidReplaceMe(version, length) ||
29+
NODE_RELEASED_VERSIONS.includes(version.replace(/^v/, ''))
30+
)
31+
: (version, _, { length }) =>
32+
!(isValidReplaceMe(version, length) || valid(version));
1833

1934
/**
20-
* Checks if any change version is invalid.
35+
* Identifies invalid change versions from metadata entries.
2136
*
22-
* @param {ApiDocMetadataEntry[]} entries - The metadata entries to check.
23-
* @returns {Array<import('../types').LintIssue>} List of lint issues found.
37+
* @param {ApiDocMetadataEntry[]} entries - Metadata entries to check.
38+
* @returns {import('../types').LintIssue[]} List of detected lint issues.
2439
*/
2540
export const invalidChangeVersion = entries =>
2641
entries.flatMap(({ changes, api_doc_source, yaml_position }) =>

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,30 @@ describe('invalidChangeVersion', () => {
6565
},
6666
]);
6767
});
68+
69+
it('should return an issue if a change version contains a REPLACEME and a version', () => {
70+
const issues = invalidChangeVersion([
71+
{
72+
...assertEntry,
73+
changes: [
74+
...assertEntry.changes,
75+
{ version: ['v24.0.0', 'REPLACEME'] },
76+
],
77+
},
78+
]);
79+
80+
deepEqual(issues, [
81+
{
82+
level: 'error',
83+
location: {
84+
path: 'doc/api/assert.md',
85+
position: {
86+
start: { column: 1, line: 7, offset: 103 },
87+
end: { column: 35, line: 7, offset: 137 },
88+
},
89+
},
90+
message: 'Invalid version number: REPLACEME',
91+
},
92+
]);
93+
});
6894
});

0 commit comments

Comments
 (0)