Skip to content

Strip inline comments and whitespace from CODEOWNERS rules - #2404

Merged
webpro merged 1 commit into
webpro-nl:mainfrom
Kernel-Hunter:fix-codeowners-inline-comments
Nov 17, 2026
Merged

webpro merged 1 commit into
webpro-nl:mainfrom
Kernel-Hunter:fix-codeowners-inline-comments

Conversation

@Kernel-Hunter

Copy link
Copy Markdown
Contributor

GitHub's CODEOWNERS docs include this line in their example file:

*.js    @js-owner #This is an inline comment.

parseCodeowners splits the whole rule on whitespace, so the owners of a.js came out as ['@js-owner', '#This', 'is', 'an', 'inline', 'comment.'], and that's what the codeowners reporter printed. Two smaller cases in the same spot: a rule with trailing spaces got an extra '' owner, and a rule indented with spaces was dropped since its path was ''.

The fix trims each line and stops reading owners at the first token that starts with #. I added a test with the docs line, a trailing-space rule and an indented rule. It fails on main and passes now. node --test test/util/*.test.ts, oxlint, oxfmt and tsc --noEmit pass, except the getInputsFromScripts (vp) case, which fails for me on main too.

`*.js @js-owner #This is an inline comment.` (from GitHub's own CODEOWNERS
example) gave the owners @js-owner, #This, is, an, inline and comment.
Trailing spaces added an empty owner, and an indented rule was ignored.

@webpro webpro left a comment

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.

Thanks, Karim. This correctly handles inline comments and surrounding whitespace while preserving ownerless overrides and rule precedence. Looks good.

@pkg-pr-new

pkg-pr-new Bot commented Nov 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/knip@2404
npm i https://pkg.pr.new/@knip/language-server@2404
npm i https://pkg.pr.new/@knip/mcp@2404

commit: e3abbd4

@webpro
webpro merged commit c793dde into webpro-nl:main Nov 17, 2026
33 checks passed
@webpro

webpro commented Nov 18, 2026

Copy link
Copy Markdown
Member

🚀 This pull request is included in v6.46.0. See Release 6.46.0 for release notes.

Using Knip in a commercial project? Please consider becoming a sponsor.

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.

2 participants