ESLint Plugin: strip prerelease tags from resolved min Grafana version#2520
Conversation
…ersion
semver.minVersion(">=11.0.0-0") returns "11.0.0-0" which doesn't exist
on npm. Use semver.coerce() to strip prerelease/build metadata so the
rule downloads the correct stable package version.
There was a problem hiding this comment.
Pull request overview
Adjusts the eslint-plugin rule’s resolved minimum Grafana version to avoid prerelease/build tags (e.g. 11.0.0-0) that don’t map to published npm versions, and adds unit tests for the version-resolution helpers.
Changes:
- Coerce
semver.minVersion(...)results to a stablex.y.zversion viasemver.coerce()ingetMinSupportedVersionFromPackageJson. - Add Vitest unit tests covering prerelease stripping and option-vs-fallback behavior for
getMinSupportedGrafanaVersion.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/eslint-plugin-plugins/src/rules/minGrafanaVersion.ts | Coerces resolved minimum Grafana version to remove prerelease/build metadata. |
| packages/eslint-plugin-plugins/src/rules/minGrafanaVersion.test.ts | Adds unit tests for min-version resolution and context option fallback behavior. |
You can also share your feedback on Copilot code review. Take the survey.
| vi.spyOn(fs, 'existsSync').mockReturnValue(true); | ||
| vi.spyOn(semver, 'minVersion').mockReturnValue(semver.minVersion(range)); | ||
|
|
There was a problem hiding this comment.
vi.spyOn(semver, 'minVersion').mockReturnValue(semver.minVersion(range)) calls semver.minVersion(range) after the spy is installed (argument evaluation happens after spyOn), so it will invoke the mocked function and typically return undefined. This makes the test fail (the implementation will treat it like a missing minVersion). Compute the real minVersion before installing the spy, or return a constructed SemVer instance (e.g. new semver.SemVer(...)) instead of calling semver.minVersion inside mockReturnValue.
| vi.spyOn(fs, 'existsSync').mockReturnValue(true); | ||
| vi.spyOn(semver, 'minVersion').mockReturnValue(semver.minVersion('>=11.0.0')); | ||
|
|
There was a problem hiding this comment.
Same issue as above: vi.spyOn(semver, 'minVersion').mockReturnValue(semver.minVersion('>=11.0.0')) will evaluate semver.minVersion(...) after minVersion has been spied on, so it will call the mock instead of the real implementation and likely return undefined. Compute the value before spying (or return a SemVer instance) so the fallback-path test is deterministic.
|
🚀 PR was released in |
Summary
semver.minVersion(">=11.0.0-0")returns"11.0.0-0", which doesn't exist on npm. The eslint rule then fails when trying to download Grafana types for that version.semver.coerce()to strip prerelease/build metadata, so the rule resolves to the correct stable package version (e.g.11.0.0).getMinSupportedVersionFromPackageJsonandgetMinSupportedGrafanaVersion.Fixes the CI failure seen in https://github.com/grafana/clock-panel/actions/runs/22856422998/job/66297907427?pr=507
Test plan
importIsCompatibletests passminGrafanaVersiontests cover prerelease stripping (>=11.0.0-0→11.0.0,>=11.1.0-beta.1→11.1.0), standard ranges, and error cases