Skip to content

Commit 656f355

Browse files
authored
fix: use remap instead of exclude for issue comment anchors (#58)
## Summary Fixes the lint failure in #41 (release-please PR). CLI `--exclude` overrides (rather than merges with) config file excludes in lychee. The `--exclude` added in #56 for `#issuecomment-` URLs caused the config file's `exclude` patterns (like the `compare/` URL exclusion) to be ignored. Fix: switch to `--remap` which strips the `#issuecomment-` fragment while still checking the issue/PR page itself. ## Test plan - [ ] CI passes (the release-please PR #41 should also pass after this merges) Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
1 parent 9cbe309 commit 656f355

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,12 @@ two patterns that affect ALL GitHub URLs (any repository):
237237
JS-rendered line-number fragment is skipped. This means
238238
consuming repos don't need to exclude these in their
239239
`lychee.toml`.
240-
- **Issue comment anchors** (`#issuecomment-*`): Excluded
241-
entirely. These are JS-rendered and cannot be verified by
242-
lychee.
240+
- **Issue comment anchors** (`#issuecomment-*`): The fragment
241+
is stripped so the issue/PR page is still checked, but the
242+
JS-rendered comment anchor is skipped.
243243

244244
Set `LYCHEE_SKIP_GITHUB_REMAPS=true` to disable all GitHub-specific
245-
remaps and exclusions as an escape hatch if they cause unexpected
246-
behavior.
245+
remaps as an escape hatch if they cause unexpected behavior.
247246

248247
**Environment variables:**
249248

tasks/lint/links.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ build_remap_args() {
106106
# lychee cannot verify them. We strip the fragment so the file
107107
# itself is still checked.
108108
# - Issue comment anchors (#issuecomment-*): rendered by JavaScript,
109-
# lychee cannot verify them.
109+
# lychee cannot verify them. The fragment is stripped so the
110+
# issue/PR page itself is still checked.
111+
#
112+
# We use --remap (not --exclude) because CLI --exclude overrides
113+
# config file excludes in lychee, rather than merging with them.
110114
#
111115
# Set LYCHEE_SKIP_GITHUB_REMAPS=true to skip these (same escape hatch
112116
# as for the repo-specific remaps above).
@@ -118,9 +122,13 @@ build_global_github_args() {
118122
# shellcheck disable=SC2016 # single quotes are intentional: these are regex capture groups, not shell vars
119123
echo '^https://github.com/([^/]+/[^/]+)/blob/([^/]+)/(.*?)#L[0-9]+.*$ https://github.com/$1/blob/$2/$3'
120124

121-
# Exclude issue comment anchors (JS-rendered, not in static HTML)
122-
echo "--exclude"
123-
echo '^https://github.com/.*#issuecomment-.*$'
125+
# Strip issue comment anchors (JS-rendered, not in static HTML).
126+
# The issue page is still checked, just not the fragment.
127+
# We use --remap instead of --exclude because CLI --exclude
128+
# overrides (rather than merges with) config file excludes.
129+
echo "--remap"
130+
# shellcheck disable=SC2016 # single quotes are intentional
131+
echo '^https://github.com/([^/]+/[^/]+)/(issues|pull)/([0-9]+)#issuecomment-.*$ https://github.com/$1/$2/$3'
124132
}
125133

126134
run_lychee() {

tests/test-links.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ but the JS-rendered fragment is skipped.
3333
<!-- editorconfig-checker-enable -->
3434
- [lychee main.rs#L1](https://github.com/lycheeverse/lychee/blob/master/lychee-bin/src/main.rs#L1)
3535

36-
## Issue comment anchors — excluded globally
36+
## Issue comment anchors — fragment stripped globally
3737

3838
Issue comment anchors are rendered by JavaScript and cannot be
39-
verified by lychee.
39+
verified by lychee. The fragment is stripped so the issue/PR page
40+
is still checked.
4041

4142
- [example issue comment](https://github.com/grafana/flint/issues/1#issuecomment-1)

0 commit comments

Comments
 (0)