Skip to content
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

fix(lint): hardcode ignored invalid change versions #246

Merged
merged 4 commits into from
Apr 9, 2025
Merged
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
18 changes: 17 additions & 1 deletion src/linter/rules/invalid-change-version.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LINT_MESSAGES } from '../constants.mjs';
import { valid } from 'semver';
import { valid, parse } from 'semver';
import { env } from 'node:process';

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

/**
* Checks if a given semantic version should be ignored.
* A version is considered ignored if its major version is 0 and minor version is less than 2.
*
* These versions are extremely old, and are not shown in the changelog used to generate
* `NODE_RELEASED_VERSIONS`, so they must be hardcoded.
*
* @param {string} version - The version to check.
* @returns {boolean} Returns true if the version is ignored, false otherwise.
*/
const isIgnoredVersion = version => {
const { major, minor } = parse(version) || {};
return major === 0 && minor < 2;
};

/**
* Determines if a given version is invalid.
*
Expand All @@ -26,6 +41,7 @@ const isInvalid = NODE_RELEASED_VERSIONS
? (version, _, { length }) =>
!(
isValidReplaceMe(version, length) ||
isIgnoredVersion(version) ||
NODE_RELEASED_VERSIONS.includes(version.replace(/^v/, ''))
)
: (version, _, { length }) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const issues = invalidChangeVersion([
...assertEntry,
changes: [
...assertEntry.changes,
{ version: ['SOME_OTHER_RELEASED_VERSION'] },
{ version: ['SOME_OTHER_RELEASED_VERSION', 'v0.1.2'] },
],
},
]);
Expand Down
Loading