objectionary / objectionary/lints

`incorrect-version` rejects `1.0.0-alpha.1` and `1.0.0+build`, which SemVer defines

Open Beginner friendly
#1,368 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
14
Forks
39
Avg merge
22h 54m
Merged PRs (30d)
90

Description

incorrect-version reports two version strings that SemVer defines, while telling the author that SemVer is what it wants.

src/main/resources/org/eolang/lints/metas/incorrect-version.xsl:18:

<xsl:if test="$meta-head='version' and not(matches($meta-tail, '^\d+\.\d+\.\d+(-[a-zA-Z0-9-]+)?$|^\d+\.\d+-SNAPSHOT$'))">

and the message it produces:

The format of the +version meta is wrong: <tail> (SemVer expected instead)

Two shapes that SemVer 2.0.0 spells out are refused by that pattern:

+version SemVer the rule
0.0.1-alpha valid accepted
0.0.1-beta-1 valid accepted
1.0.0-alpha.1 valid — §9, dot-separated pre-release identifiers reported
1.0.0+20130313144700 valid — §10, build metadata reported

The pre-release group is [a-zA-Z0-9-]+, which has no dot in it, so a numbered pre-release such as -alpha.1 or -rc.2 — the form SemVer itself uses in its examples — falls through. Build metadata is not in the pattern at all, in either alternative.

Verified as two packs under incorrect-version, each with defects: 0, both failing on master:

Tests run: 490, Failures: 2
  incorrect-version/probe-semver.yaml
  incorrect-version/probe-build.yaml

while allows-good-versions.yaml beside them keeps passing, so it is these two shapes specifically.

Root cause

The pattern was written from the common cases rather than from the grammar. The second alternative, ^\d+\.\d+-SNAPSHOT$, is a deliberate Maven exception, so the intent is "SemVer, plus the Maven two-part snapshot" — and the first alternative falls short of the SemVer half.

Suggested fix

The official SemVer regular expression, with the Maven alternative kept:

<xsl:if test="$meta-head='version' and not(matches($meta-tail, '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-((0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$|^\d+\.\d+-SNAPSHOT$'))">

That also starts rejecting a leading zero in a numeric component (01.2.3), which SemVer forbids and the current pattern allows; if that is more strictness than wanted, \d+ in the three places keeps today's behaviour.

Either way the two shapes above deserve packs, so the rule and the standard it names cannot drift apart again.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/main/resources/org/eolang/lints/metas/incorrect-version.xsl:18 and inspect the two failing packs, incorrect-version/probe-semver.yaml and incorrect-version/probe-build.yaml. Update the version pattern so the reported SemVer shapes are accepted while preserving the Maven SNAPSHOT alternative, then run those packs and confirm allows-good-versions.yaml still passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
xml
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
86/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.