Commit Graph

14 Commits

Author SHA1 Message Date
Michael Kriese 59852479bf test: close branch coverage gaps outside the manager tree (#46252)
* test(versioning): cover four uncovered guards

- `cargo`: a converted range whose operators are already attached to
  their versions, so `npm2cargo` leaves the elements alone
- `hashicorp`: a widen on a complex range ending in `>=`, which the
  underlying semver implementation refuses and returns null for
- `poetry`: a version list holding an unparseable entry, for both
  `getSatisfyingVersion` and `minSatisfyingVersion`, plus the same widen
  refusal, which falls back to the current value
- `swift`: an open-ended range whose bound is not a valid semver

Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>

* refactor(versioning): drop two guards that cannot be false

- `hermit`: `major` is the only mandatory group in the version regex, so
  the `if (major)` around the first release segment always holds; the
  sibling parser already pushes it unconditionally
- `rpm`: after `c1 === c2` is ruled out, one of `c1 > c2` and `c1 < c2`
  must hold, so the second comparison becomes a ternary

Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>

* test(versioning/gradle): cover three uncovered guards

- `getMajor` on a version whose leading token is not a number
- `getSatisfyingVersion` with a later match that is not greater than the
  one already held
- `minSatisfyingVersion` with a later match that is not smaller than the
  one already held

Two branches in `compare.ts` are still open and are looked at next.

Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>

* test(versioning/ivy): cover a later match that is not the greatest

`getSatisfyingVersion` kept every matching version it walked past, so the
guard that holds on to the one already found was never taken.

Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>

* refactor(versioning): drop three guards that cannot be false

- `gradle`: `tokenCmp` compares two tokens whose only types are `Number`
  and `String`, so once both-numbers and both-strings are handled
  exactly one side is a number; the chain becomes a ternary and the
  unreachable `return 0` goes
- `ivy`: `tokenize` always yields at least one token for a non-empty
  version, so the length check around the last one always holds
- `ivy`: `rangeToStr` only returns null for a null range, which the
  `length === 1` check above it already rules out

Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>

* test(versioning/nuget): cover a later match that is not the greatest

Both loops in `getSatisfyingVersion` walked version lists that only ever
climbed, so the guard that holds on to the candidate already found was
never taken -- once for a bracket range, once for a bare version acting
as a minimum.

Also pin down that a floating range needs a major component: `-*` alone
does not parse.

Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>

* refactor(versioning): drop three more guards that cannot be false

- `maven`: the interval picked for auto-extension is only picked when the
  new value is at or past its upper bound, and that upper bound is the
  lower one incremented, so the new value never sorts below the lower
  bound
- `maven`: an interval never has both bounds open, because the parser
  only nulls one side when the other is a version
- `nuget`: a floating range always carries a major component, so neither
  the parser's NaN check nor the serializer's undefined check can fail

Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>

* refactor(versioning/pep440): drop three unreachable range paths

`updateRangeValue` handles `!=`, a `.*` prefix, `~=`, `==` and `<=`
itself, `handleUpperBound` handles `<`, and `parseCurrentRange` rejects
`===`. Only `>` and `>=` can reach `handleLowerBound`, so its operator
check always holds and it never returns null. Making it total removes
the null check at the call site as well.

This does drop the `logger.error` that followed, which was guarded by a
comment saying it could not happen unless pep440 itself changed.

`isLessThanRange` classifies the same fixed operator set, so the last
check there is the only one left and its fallback was dead.

`divideCompatibleReleaseRange` only ever sees a `~=` version, and pep440
requires at least two release components after that operator, so there
is always a component to drop. A new test pins down that `~=7` is not a
valid range.

Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>

* test(versioning): cover three more uncovered guards

- `elm`: a widen where the new version sits below the lower bound, so
  the upper bound is kept rather than extended
- `hex`: a widen on a complex range ending in `>=`, which the underlying
  semver implementation refuses and returns null for
- `rust-release-channel`: a concrete current version paired with a
  channel name as the new version, which falls through to the new
  version unchanged

Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>

* refactor(versioning): drop two more guards that cannot be false

- `composer`: `getNewValue` falls back to the new version whenever
  nothing else matched, so it never returns null and the recursive call
  in the or-range path always has a value to work with
- `docker`: a version's prerelease is always a string, so once an empty
  one on either side is handled, the remaining pair is both non-empty
  and unequal

Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>

* test(config,datasource): cover two more uncovered guards

- `config/validation`: `hostRules[].allowInternal` nested inside a
  `packageRules[]` entry, which reports a plain configuration error
  rather than a security one, because nested host rules are never applied
- `datasource/docker`: a non-list manifest whose response carries no
  `docker-content-digest` header, so the digest falls back to the hash of
  the manifest body

Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>

* refactor(config,datasource): unwind three branches v8 could not count

- `config/decrypt` and `datasource/docker/common` each picked a response
  with an `await` inside a ternary. v8 gives the branch that follows such
  a ternary a negative hit count, which the reporters read as uncovered
  even though both paths run. Spelling the choice as an if/else makes the
  count come out right; behaviour is unchanged.
- `datasource/index` and `datasource/npm/npmrc` each ended an exhaustive
  chain with an `else if` whose implicit else v8 counts but nothing can
  reach: `registryStrategy` is one of three literals, and `npmrc` starts
  as an object and is only ever reassigned to one.

Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>

* test(workers/global): cover seven uncovered guards

The config parsers rewrite legacy boolean spellings of `dryRun`,
`requireConfig` and `platformCommit`, but nothing passed a value that was
already current, so the fall-through of each chain went untaken. Cover it
from both the CLI and the environment.

Also cover a datasource env var that names no auth field, one whose value
is undefined, a default config file that cannot be read, and the error
`isLimitReached` throws when asked for a concurrent limit without a
branch config. That last one had an ignore hint saying it should not
happen; the error message documents the contract, so it is now tested and
the hint is gone.

Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>

* refactor(workers/global): drop a guard that cannot be false

`getConfig` in the additional-config-file parser returns early unless
`RENOVATE_ADDITIONAL_CONFIG_FILE` is set, so by the time a parse error is
being classified the variable is always present.

Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>

* refactor(workers/repository): drop a dead changelog file lookup

The gitea, gitlab and forgejo changelog sources each declared `files` as
an empty array and then guarded the only assignment to it with
`if (!files.length)`, which is always true one line after the
declaration. Collapse it to the filter itself.

Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>

* ci: ratchet the branch coverage threshold

A full run on this branch reports 100% statements (49471/49471), 100%
functions (7381/7381), 100% lines (48961/48961) and 99.73% branches
(25690/25759), up from 99.53% before this branch's work. The threshold
moves to 99.71, keeping the same rounding-down margin as before.

Statements, functions and lines are already pinned at 100 and stay
there.

Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>

* refactor(config,datasource): say why the ternary was unwound

Both sites now carry a comment explaining that the if/else is deliberate:
v8 gives the branch following an `await` inside a ternary a negative hit
count, which the coverage reporters read as uncovered.

`apiCheckResponse` also gets an explicit `HttpResponse<unknown>` type,
which is what the two branches have in common and what
`isECRMaxResultsResponse` already expects.

Also fix a type error in the new config file spec: the `pathExists` spy
needs the same `as never` cast the surrounding tests use.

Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>

* refactor(versioning/pep440): use a template literal in handleLowerBound

The exclude-style return is the one line this branch rewrote in that
function, so it now builds its string with a template literal instead of
the `+` operator.

Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>

* test(workers/global): drop the cast from the limits throw test

Calling the overload with a non-null assertion on the config argument
says the same thing without retyping the whole function.

Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>

---------

Co-authored-by: Claude Opus 5 <michael.kriese+claude-code@mend.io>
2026-09-16 12:03:23 +00:00
Sebastian Poxhofer 3412de84ce refactor(linters): enable oxlint rule prefer-named-capture-group (#44714)
* refactor(lint): enable oxlint prefer-named-capture-group at error

Numbered capture groups (m[1], $1) break silently when a regex is
edited and group order shifts. Named groups (?<name>...) make intent
explicit and accesses (m.groups.name) resilient to reordering.

This enables the built-in eslint rule prefer-named-capture-group,
surfacing 321 pre-existing unnamed-group violations across ~121
files to be burned down incrementally in follow-up commits.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RxHFNsSworLcv23xXk9Hk

* refactor(versioning): name capture groups for prefer-named-capture-group

Burns down all prefer-named-capture-group violations in
lib/modules/versioning/. Unused capture groups (only reachable via
.test() or whole-match) become non-capturing (?:...); groups whose
value is read become named (?<name>...), with accesses rewritten to
match.groups!.<name> (or destructured from .groups!) instead of
positional match[n]/$n so a future edit that reorders groups cannot
silently break the reader.

Two cases needed extra care to preserve behavior:
- semver/common.ts and poetry/patterns.ts split() on a regex whose
  capture group is relied upon by String.prototype.split to keep the
  separator in the output array; the group is kept capturing and
  named, not converted to non-capturing.
- hashicorp/convertor.ts's semverRegex is only ever embedded via
  .source into a named `(?<version>...)` group elsewhere and never
  matched directly, so its internal groups are safe to make
  non-capturing.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RxHFNsSworLcv23xXk9Hk

* refactor(datasource): name capture groups for prefer-named-capture-group

Burns down all prefer-named-capture-group violations under
lib/modules/datasource/. Same treatment as the versioning module:
unused groups become non-capturing, used groups get names, and
positional match[n] reads move to match.groups!.<name>.

docker/ecr.ts and pypi/common.ts keep their positional destructuring
(`const [, region] = ...`, `!!m &&`) working unchanged since a named
capture group is still addressable by its numeric index in
JavaScript — only pypi/common.ts's access was rewritten to
m.groups!.owner for clarity since it read a single group directly.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RxHFNsSworLcv23xXk9Hk

* refactor(platform): name capture groups for prefer-named-capture-group

Burns down all prefer-named-capture-group violations under
lib/modules/platform/. Uses the repo's established idiom of
`match.groups?.<name>` after an optional-chained exec()/match() (see
bitbucket/index.ts hostnameWithoutApiPrefix, gerrit/utils.ts
extractSourceBranch) and `$<name>` in String.replace replacement
strings. Unused groups (markdown/HTML massaging regexes matched only
to be stripped) become non-capturing.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RxHFNsSworLcv23xXk9Hk

* refactor(manager): name capture groups in ansible-galaxy for prefer-named-capture-group

Burns down prefer-named-capture-group violations in
lib/modules/manager/ansible-galaxy/. newBlockRegEx and blockLineRegEx
dropped their unused outer wrapping group (only the inner key/value
groups were ever read) and named the key/value groups; nameMatchRegex's
remaining unused groups (protocol/user-info/port alternatives) become
non-capturing since only source/hostname/depName/version are read via
.groups. Accesses in collections.ts and roles.ts move from
lineMatch[2]/lineMatch[3] to lineMatch.groups!.key/value.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RxHFNsSworLcv23xXk9Hk

* refactor(manager): name capture groups for prefer-named-capture-group (batch 1)

Burns down prefer-named-capture-group violations across the first
alphabetical slice of lib/modules/manager/ (ansible through mix).
Used groups get names with accesses rewritten to match.groups!.<name>
(or $<name> in replacement strings); groups whose value is never read
become non-capturing (?:...). Two String.split() call sites
(git-submodules/extract.ts, meteor/extract.ts) keep the established
"named group still readable positionally from the split() result
array" idiom instead of restructuring the destructuring.

bazel/rules/go.ts and buildpacks/extract.ts dockerRef verified
byte-for-byte equivalent before/after via a quick node script since
several nested groups collapsed to non-capturing at once.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RxHFNsSworLcv23xXk9Hk

* refactor(manager): name capture groups for prefer-named-capture-group (batch 2)

Burns down prefer-named-capture-group violations across the remaining
alphabetical slice of lib/modules/manager/ (npm through terragrunt).
Same treatment as batch 1: used groups get names with accesses moved
to match.groups!.<name> or $<name> replacement strings; unused groups
(wrapping alternations, quantifier repetition groups only consumed via
.test(), or values never read from a match) become non-capturing.

terraform/extractors/others/modules.ts and terragrunt/modules.ts share
near-identical URL-parsing regexes (github/bitbucket/git/azure-devops
ref matchers) — the same set of always-unused `depth=`/`&depth=`
query-string groups is converted to non-capturing in both files.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RxHFNsSworLcv23xXk9Hk

* refactor(config): name capture groups for prefer-named-capture-group

Burns down prefer-named-capture-group violations in lib/config/.
Used groups get names with replacement strings switched from $1/$2 to
$<name>; the unused separator group in schedule-migration.ts's
afterBeforeRegex becomes non-capturing. presets/parse.ts keeps
assigning through the already-declared `repo` variable rather than
array-destructuring the exec() result, matching this file's existing
style for the other named-group regexes just above it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RxHFNsSworLcv23xXk9Hk

* refactor(util): name capture groups for prefer-named-capture-group

Burns down prefer-named-capture-group violations across lib/util/ and
lib/logger/. Same treatment as previous batches: named groups for
values that are read (via $<name> replacement strings, .groups!.<name>,
or destructured from .groups), non-capturing groups where nothing reads
the captured value (e.g. semantic.ts's angular-commit .test()-only
regex). www-authenticate.ts's tokenizer entries each get their own
named group but keep accessing the match generically via match[1],
since a positionally-indexed named group is still readable by index.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RxHFNsSworLcv23xXk9Hk

* refactor(workers): name capture groups for prefer-named-capture-group

Burns down prefer-named-capture-group violations in lib/workers/.
Used groups get names with $<name> replacement strings; unused
wrapper/alternation groups (e.g. semantic-commit-message.ts's optional
scope/issue wrappers, release-notes.ts's date-heading and
horizontal-rule matchers that are only probed with .search()/replaced
wholesale) become non-capturing.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RxHFNsSworLcv23xXk9Hk

* refactor(test,tools): name capture groups for prefer-named-capture-group

Finishes the prefer-named-capture-group burndown: test/, tools/, and
vitest.config.mts. Groups whose value is read get names ($<name>
replacement strings or .groups.<name> access); groups only used via
.test()/.search() or that feed a .match(/…/g) call (whose return value
is the array of whole matches, not captured groups) become
non-capturing.

This is the last remaining slice of pre-existing violations, so the
rule (already enabled at error repo-wide) now passes with zero
findings across the whole codebase.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RxHFNsSworLcv23xXk9Hk

* fix prettier failure

* refactor(lint): use a named capture group in `v8-ignore-no-count`

New rule from main trips the newly enabled `prefer-named-capture-group` oxlint rule.

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-09-03 09:54:40 +00:00
Sebastian Poxhofer 58771bb183 refactor(linters): enabled oxlints func-style (#44691)
* refactor(oxlint): enable func-style

Enable the built-in func-style rule as ["warn", "declaration"] so that
named functions are written as function declarations instead of arrow or
function expressions assigned to variables, matching the convention in
docs/development/best-practices.md (Functions section). Inline arrow
callbacks are unaffected; prefer-arrow-callback continues to cover the
callback direction.

Severity is "warn" instead of "error" as a fallback: a repo-wide run
found 196 pre-existing violations (70 in spec files, 126 in production
code), exceeding the 80-violation fix threshold for this change, so no
violations were fixed here. Follow-up work can convert the offenders
(largest clusters: lib/modules/versioning/ruby, lib/util/cache/package,
lib/modules/versioning/maven, lib/modules/versioning/gradle) and then
raise the rule to "error". Note oxlint 1.72 also supports an
allowTypeAnnotation option if typed consts should remain arrows.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* ci(linter): enforce func-style at error

* refactor(func-style): convert const-arrow functions to declarations in with-cache spec and ruby versioning

* refactor(func-style): convert const-arrow functions to declarations in maven/gradle modules

* refactor(func-style): convert const-arrow functions to declarations in remaining versioning modules

* refactor(func-style): convert const-arrow functions to declarations in platform modules

Discriminated-union closures (ensureCommentRemoval byTopic/byContent
helpers in github, gitlab, bitbucket, bitbucket-server) needed the
narrowed field passed explicitly as a parameter, since function
declarations are hoisted and lose the outer if-narrowing that inline
arrow-function closures previously relied on.

* refactor(func-style): convert const-arrow functions to declarations across util/manager/datasource modules

One case (logger/renovate-logger.ts logOnceFn) is kept as an arrow
function with a documented oxlint-disable: it is stored on
this.logger.once[level] and relies on lexically-bound this, which a
hoisted function declaration would not preserve.

* refactor(func-style): convert remaining const-arrow test helpers to declarations

get-updated.spec.ts: hoisted expectPipCompilePackageAndLockFile to
module scope (it only closes over the module-level pipCompile mock)
and added a documented oxlint-disable for vitest/expect-expect on its
caller test, since oxlint's expect-expect check does not trace
assertions through an externally-defined helper function.

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-19 11:14:22 +00:00
Nahrin cc32f48c9c docs(versioning): replace bare links with descriptive markdown links in urls (#43951)
* fix(versioning): replace bare links with descriptive markdown links in urls

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: export markdownLinkRegex from common.ts and import in test

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-15 06:30:54 +00:00
Sebastian Poxhofer 73b90e958b refactor: remove string concetation for production code (#43442)
refactor: prefer templates rather than `+`
2026-05-19 13:31:27 +00:00
Florian Arens a79cddc4b9 fix(versioning/hex): handle Elixir == pin prefix in isSingleVersion (#41565)
* fix(versioning/hex): handle Elixir == pin prefix in isSingleVersion

Hex versioning inherited npm's isSingleVersion which only strips a single
= prefix. Elixir uses == for pinning, so "== 1.7.16" was not recognized
as a pinned version, causing duplicate pin PRs on every update.

Add isSingleVersion override that handles the double == prefix and add
getPinnedValue to emit the correct == prefix when pinning.

* fix: use non-null assertion instead of optional chaining in test
2026-03-01 14:42:39 +00:00
Sergei Zharinov 930cf6633c refactor: Rewrite imports with .ts extensions (#40700)
fix: Additional vi.mock path corrections and prettier formatting
2026-01-26 22:48:17 +00:00
Rhys Arkins 0d5d7a8669 refactor!: remove rangeStrategy=pin from versioning modules (#36261)
Refactors `getNewValue` logic to replace it with an optional
`getPinnedValue()` where rangeStrategy=pin. This way each versioning
module doesn't need to add and test extensive "pin" logic.

This should not be breaking, but out of an abundance of caution, we'll
mark it as such.
2025-11-06 08:07:40 +00:00
Jason Sipula 710ca6785c fix(versioning/hex): Fix Hex range widening (#34717) 2025-03-10 05:32:45 +00:00
Pierre Cavin 415f5cbb31 fix(hex): fix Elixir's special operator in list (#33325) 2024-12-29 17:29:54 +00:00
Josiah Dahl 4c3d970f5c feat(hex): support update-lockfile strategy (#27915) 2024-06-12 04:47:29 +00:00
Sergei Zharinov b69416ce17 refactor(prettier): Force trailing commas (#25631) 2023-11-07 15:50:29 +00:00
RahulGautamSingh 938a36801e refactor: replace test.each with it.each (#21859) 2023-04-28 04:33:15 +00:00
Rhys Arkins dca3418bbd refactor: lib/modules (#14488)
Moves datasource, manager, platform and versioning code from lib/ into new lib/modules/

BREAKING CHANGE: External tools must update paths to datasource, manager, platform and versioning
2022-03-04 09:04:02 +01:00