forked from nodejs/doc-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvalid-change-version.mjs
More file actions
33 lines (29 loc) · 843 Bytes
/
invalid-change-version.mjs
File metadata and controls
33 lines (29 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { LINT_MESSAGES } from '../constants.mjs';
import { valid } from 'semver';
/**
* Checks if any change version is invalid
*
* @param {ApiDocMetadataEntry} entry
* @returns {Array<import('../types').LintIssue>}
*/
export const invalidChangeVersion = entry => {
if (entry.changes.length === 0) {
return [];
}
const allVersions = entry.changes
.filter(change => change.version)
.flatMap(change =>
Array.isArray(change.version) ? change.version : [change.version]
);
const invalidVersions = allVersions.filter(
version => valid(version) === null
);
return invalidVersions.map(version => ({
level: 'warn',
message: LINT_MESSAGES.invalidChangeVersion.replace('{{version}}', version),
location: {
path: entry.api_doc_source,
position: entry.yaml_position,
},
}));
};