Skip to content

ESLint Plugin: strip prerelease tags from resolved min Grafana version#2520

Merged
tolzhabayev merged 1 commit into
mainfrom
fix/semver-match
Mar 10, 2026
Merged

ESLint Plugin: strip prerelease tags from resolved min Grafana version#2520
tolzhabayev merged 1 commit into
mainfrom
fix/semver-match

Conversation

@tolzhabayev
Copy link
Copy Markdown
Collaborator

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.
  • Use semver.coerce() to strip prerelease/build metadata, so the rule resolves to the correct stable package version (e.g. 11.0.0).
  • Add unit tests for getMinSupportedVersionFromPackageJson and getMinSupportedGrafanaVersion.

Fixes the CI failure seen in https://github.com/grafana/clock-panel/actions/runs/22856422998/job/66297907427?pr=507

Test plan

  • Existing importIsCompatible tests pass
  • New minGrafanaVersion tests cover prerelease stripping (>=11.0.0-011.0.0, >=11.1.0-beta.111.1.0), standard ranges, and error cases

…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.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 9, 2026

Hello! 👋 This repository uses Auto for releasing packages using PR labels.

✨ This PR can be merged and will trigger a new patch release.
NOTE: When merging a PR with the release label please avoid merging another PR. For further information see here.

@tolzhabayev tolzhabayev added the no-changelog Don't include in changelog and version calculations label Mar 9, 2026
@tolzhabayev tolzhabayev self-assigned this Mar 9, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 stable x.y.z version via semver.coerce() in getMinSupportedVersionFromPackageJson.
  • 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.

Comment on lines +34 to +36
vi.spyOn(fs, 'existsSync').mockReturnValue(true);
vi.spyOn(semver, 'minVersion').mockReturnValue(semver.minVersion(range));

Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +55 to +57
vi.spyOn(fs, 'existsSync').mockReturnValue(true);
vi.spyOn(semver, 'minVersion').mockReturnValue(semver.minVersion('>=11.0.0'));

Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@grafana-plugins-platform-bot grafana-plugins-platform-bot Bot moved this from 📬 Triage to 🔬 In review in Grafana Catalog Team Mar 9, 2026
Copy link
Copy Markdown
Contributor

@sunker sunker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@tolzhabayev tolzhabayev merged commit 6a21920 into main Mar 10, 2026
32 of 33 checks passed
@tolzhabayev tolzhabayev deleted the fix/semver-match branch March 10, 2026 11:07
@github-project-automation github-project-automation Bot moved this from 🔬 In review to 🚀 Shipped in Grafana Catalog Team Mar 10, 2026
@jackw jackw added patch Increment the patch version when merged release Create a release when this pr is merged and removed no-changelog Don't include in changelog and version calculations labels Mar 11, 2026
@grafana-plugins-platform-bot
Copy link
Copy Markdown
Contributor

@grafana-plugins-platform-bot grafana-plugins-platform-bot Bot added the released This issue/pull request has been released. label Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch Increment the patch version when merged release Create a release when this pr is merged released This issue/pull request has been released.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants