Skip to content

chore: migrate to package.json-based linting package management#2576

Draft
MikeMcC399 wants to merge 3 commits into
nodejs:mainfrom
MikeMcC399:migrate/linting-npm-package
Draft

chore: migrate to package.json-based linting package management#2576
MikeMcC399 wants to merge 3 commits into
nodejs:mainfrom
MikeMcC399:migrate/linting-npm-package

Conversation

@MikeMcC399

Copy link
Copy Markdown
Contributor

Description

Move version definition of npm packages to package.json & package-lock.json:

  • doctoc
  • markdown-link-check
  • prettier

Use Node.js 24 (Active LTS).

Update linting workflows to run based on above package definitions:

Workflow
doctoc.yml
markdown-link-check.yml
prettier.yml

workflow_dispatch: event triggers are added to make it easier to check linting issue before submitting a PR.

Enable weekly npm updating through Dependabot.

Update CONTRIBUTING with prerequisites and linting instructions. Add Table of Contents.

Motivation and Context

The following workflows currently install npm dependencies on the fly. Code scanning alerts notes this as an issue.

Workflow npm Package
doctoc.yml doctoc (latest)
markdown-link-check.yml markdown-link-check@3.14.2
prettier.yml prettier@3.9.5

By moving the package version selection from GitHub Actions to npm package.json & package-lock.json files, versions can be pinned exactly and maintained regularly by Dependabot.

Setting Dependabot and npm minimum age to 5 days for updates, reduces the risk of fast supply-chain attacks:

Testing Details

Types of changes

  • Documentation
  • Version change (Update, remove or add more Node.js versions)
  • Variant change (Update, remove or add more variants, or versions of variants)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Other (none of the above)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING.md document.
  • All new and existing tests passed.

Move version definition of npm packages to
package.json & package-lock.json:
- doctoc
- markdown-link-check
- prettier

Update linting workflows.

Enable npm updating through Dependabot.
Add scripts and documentation to aid local linting.
@MikeMcC399

Copy link
Copy Markdown
Contributor Author

@MikeMcC399
MikeMcC399 marked this pull request as ready for review July 22, 2026 15:35
@MikeMcC399
MikeMcC399 requested a review from nschonni July 22, 2026 15:35
Comment thread .github/workflows/doctoc.yml
Comment thread .github/workflows/markdown-link-check.yml
Comment thread .github/workflows/markdown-link-check.yml Outdated
node-version: 'lts/*'
- name: Install markdown-link-check
run: npm i -g markdown-link-check@3.14.2
node-version-file: .node-version

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is picked up automatically and doesn't need to be configured

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If neither node-version nor node-version-file is specified, then setup-node uses the default version of the runner, in this case ubuntu-latest => ubuntu-24.04 has Node.js 22.23.1 as default.

I did try it out, just to make sure. So this needs to stay as it is.

Comment thread package.json
"name": "docker-node",
"description": "Build official Docker images for Node.js",
"private": true,
"type": "commonjs",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We have a mix of Common and Module, note sure which is better to declare

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

https://nodejs.org/docs/latest/api/packages.html#determining-module-system recommends to always include type.

Node.js always treats build-automation.mjs as module due to the mjs extension.
If type is undefined or set to commonjs then genMatrix.js and stackbrew.js are treated as commonjs
If type were to be set to module, then those files would be incorrectly treated as module, and running node stackbrew.js would trigger a ReferenceError.

The js extensions could be renamed to cjs for clarity. That could be done in a separate PR, or at some stage they could be migrated to ESM.

Anyway, the setting commonjs is correct here!

Comment thread package.json
"format:prettier": "prettier --write .",
"format:prettier:check": "prettier --check .",
"lint": "run-s format:toc format:prettier",
"check:markdown-links": "find *.md docs/*.md -print0 | xargs -0 -n1 markdown-link-check -c markdown_link_check_config.json"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The find stuff isn't cross platform portable, but I also struggled to get the globbing/ignore to work properly locally

Comment thread package.json
"private": true,
"type": "commonjs",
"scripts": {
"format:toc": "doctoc --update-only .",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Playing with this locally I needed additional parameters, but maybe it was a version issue. I had "doctoc:README": "doctoc README.md --github --title \"## Table of Contents\"", separate targets, otherwise I thing the title stuff was causing a diff

- name: Install dependencies
run: npm ci
- name: Run Prettier
run: npx prettier --check .

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
run: npx prettier --check .
run: npm run format:prettier:check

Better to call the configured target

- name: Install dependencies
run: npm ci
- name: Run doctoc
run: npx doctoc --update-only .

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
run: npx doctoc --update-only .
run: npm run format:toc

Comment thread package.json
"format:toc": "doctoc --update-only .",
"format:prettier": "prettier --write .",
"format:prettier:check": "prettier --check .",
"lint": "run-s format:toc format:prettier",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
"lint": "run-s format:toc format:prettier",
"lint": "run-s format:toc format:prettier:check",

I think you'd want the "check" versions" for this, but I also didn't know about the doctoc, if there was an equivilent.

@MikeMcC399
MikeMcC399 marked this pull request as draft July 23, 2026 09:14
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.

Manage npm packages used in workflows

2 participants