-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathinvalid-change-version.mjs
More file actions
42 lines (36 loc) · 1014 Bytes
/
invalid-change-version.mjs
File metadata and controls
42 lines (36 loc) · 1014 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
34
35
36
37
38
39
40
41
42
import { LINT_MESSAGES } from '../constants.mjs';
import { valid } from 'semver';
/**
* Checks if any change version is invalid
*
* @param {ApiDocMetadataEntry[]} entries
* @returns {Array<import('../types').LintIssue>}
*/
export const invalidChangeVersion = entries => {
const issues = [];
for (const entry of entries) {
if (entry.changes.length === 0) continue;
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
);
issues.push(
...invalidVersions.map(version => ({
level: 'warn',
message: LINT_MESSAGES.invalidChangeVersion.replace(
'{{version}}',
version
),
location: {
path: entry.api_doc_source,
position: entry.yaml_position,
},
}))
);
}
return issues;
};