Skip to content

Commit bff2b9b

Browse files
authored
fix(lint): hardcode ignored invalid change versions (#246)
1 parent 9be11fd commit bff2b9b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { LINT_MESSAGES } from '../constants.mjs';
2-
import { valid } from 'semver';
2+
import { valid, parse } from 'semver';
33
import { env } from 'node:process';
44

55
const NODE_RELEASED_VERSIONS = env.NODE_RELEASED_VERSIONS?.split(',');
@@ -14,6 +14,21 @@ const NODE_RELEASED_VERSIONS = env.NODE_RELEASED_VERSIONS?.split(',');
1414
const isValidReplaceMe = (version, length) =>
1515
length === 1 && version === 'REPLACEME';
1616

17+
/**
18+
* Checks if a given semantic version should be ignored.
19+
* A version is considered ignored if its major version is 0 and minor version is less than 2.
20+
*
21+
* These versions are extremely old, and are not shown in the changelog used to generate
22+
* `NODE_RELEASED_VERSIONS`, so they must be hardcoded.
23+
*
24+
* @param {string} version - The version to check.
25+
* @returns {boolean} Returns true if the version is ignored, false otherwise.
26+
*/
27+
const isIgnoredVersion = version => {
28+
const { major, minor } = parse(version) || {};
29+
return major === 0 && minor < 2;
30+
};
31+
1732
/**
1833
* Determines if a given version is invalid.
1934
*
@@ -26,6 +41,7 @@ const isInvalid = NODE_RELEASED_VERSIONS
2641
? (version, _, { length }) =>
2742
!(
2843
isValidReplaceMe(version, length) ||
44+
isIgnoredVersion(version) ||
2945
NODE_RELEASED_VERSIONS.includes(version.replace(/^v/, ''))
3046
)
3147
: (version, _, { length }) =>

src/linter/tests/fixtures/invalidChangeVersion-environment.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const issues = invalidChangeVersion([
77
...assertEntry,
88
changes: [
99
...assertEntry.changes,
10-
{ version: ['SOME_OTHER_RELEASED_VERSION'] },
10+
{ version: ['SOME_OTHER_RELEASED_VERSION', 'v0.1.2'] },
1111
],
1212
},
1313
]);

0 commit comments

Comments
 (0)