Skip to content

Add ESLint rule to catch broken internal links#157

Open
allgandalf wants to merge 7 commits intoPecanProject:masterfrom
allgandalf:add-eslint-internal-links-rule
Open

Add ESLint rule to catch broken internal links#157
allgandalf wants to merge 7 commits intoPecanProject:masterfrom
allgandalf:add-eslint-internal-links-rule

Conversation

@allgandalf
Copy link
Collaborator

@allgandalf allgandalf commented Feb 26, 2026

Description of Changes

Closes #156

Adds ESLint with a custom no-bad-internal-links rule to prevent the class of bugs fixed in #155 (broken internal links in JSX). The rule flags href and to attributes where:

  • Whitespace in URLs — leading/trailing spaces (e.g. href=" https://...")
  • Relative internal links — missing leading / (e.g. href="gsoc.html"href="/gsoc/")
  • .html extensions — Docusaurus uses clean URLs
  • Missing trailing slash — internal links should end with /

Also adds a GitHub Actions lint workflow that runs on every PR and push to master.

All 46 existing violations across the codebase have been fixed in this PR.

Removes yarn.lock and standardizes the project on npm, consistent with all CI workflows (publish-docs.yml and lint.yml both use npm ci).

Files added:

  • eslint-rules/no-bad-internal-links.js — the custom ESLint rule
  • .eslintrc.js — ESLint config
  • .eslintignore — ignores build artifacts
  • .github/workflows/lint.yml — CI workflow

Files modified:

  • package.json — added lint script, eslint and eslint-plugin-react devDependencies
  • package-lock.json — updated lockfile with eslint dependencies
  • src/pages/index.js — fixed missing trailing slash
  • src/pages/news.js — fixed relative link, whitespace in URLs, missing trailing slashes
  • src/pages/documentation/*.js — fixed missing trailing slash on 12 files

Files removed:

  • yarn.lock — project standardized on npm

  • I have tested my changes on both desktop and mobile views.

    • N/A — this is a linting/CI-only change, no UI impact.
  • Screenshots are attached below for desktop and mobile layouts.

    • N/A — no visual changes.

Screenshots

N/A — tooling and link-fix change only, no UI modifications.

How to Test

  1. npm install
  2. npm run lint — should pass with 0 errors
  3. The GitHub Actions workflows run automatically on this PR

Add a no-bad-internal-links ESLint rule that flags JSX href/to attributes
with relative paths, .html extensions, missing trailing slashes, or
whitespace in URLs. Includes a GitHub Actions workflow to run lint on
every PR and push to master.

Closes PecanProject#156
@allgandalf allgandalf force-pushed the add-eslint-internal-links-rule branch from 8f2c6d2 to ac4dcb6 Compare February 26, 2026 04:16
- Fix leading whitespace in URLs in news.js
- Fix relative link gsoc.html -> /gsoc/ in news.js
- Add trailing slash to /site/pecanworkflow/pecan_news/* links in news.js
- Add trailing slash to /en-US/docs/Glossary in all documentation pages
- Add trailing slash to /documentation/latest in index.js
- Regenerate package-lock.json to include new devDependencies
The build workflow (publish-docs.yml) uses npm ci, so the lint
workflow should match to keep CI consistent.
Lockfile includes eslint dependency tree and minor transitive
dep updates from npm resolution.
@github-actions
Copy link
Contributor

🚀 Preview Ready!
Your docs preview for this PR is available here:

https://PecanProject.github.io/pr-157/

run: npm ci

- name: Lint
run: npm run lint
Copy link
Member

@AritraDey-Dev AritraDey-Dev Feb 26, 2026

Choose a reason for hiding this comment

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

Instead of creating a new file for linting check for CI, can we keep this in the existing publish-docs.yaml? Basically, just add a new step npm run lint before npm run build. Ideally, it should run before npm run build. wdyt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have no personal preference here, but i think it's better to have different CI flows for checks (it's what i have been doing in different codebases) but if you insist i can surely put it in existing yml file , let me know

Copy link
Member

Choose a reason for hiding this comment

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

Then it’s fine as it is!

Copy link
Member

@AritraDey-Dev AritraDey-Dev left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines +6 to +8
* - Internal links must start with '/'
* - Internal links must not use .html extension
* - Internal links must end with '/'
Copy link
Member

Choose a reason for hiding this comment

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

Are there technical reasons for all of these? I'm OK with requiring no extensions, but I like relative links and I think of a trailing slash as an indicator this page has children (eg gsoc/ reads to me as a landing page that implies the existence of gsoc/ideas and gsoc/contributor_guidance) rather than something that should be appended everywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ESLint rule to catch broken internal links and standardize on npm

3 participants