Skip to content

Commit c6e637b

Browse files
joyenjoyerclaude
andcommitted
fix: require the oxlint notice-plugin to match the full copyright header
Replace the loose mustMatch: 'The MIT License' substring check with an exact match against the full COPYRIGHT_NOTICE text. The old check only looked for that one phrase in the first 1000 characters, so a header with the phrase present but other lines altered, wrong, or missing was accepted as valid. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 729de12 commit c6e637b

1 file changed

Lines changed: 5 additions & 15 deletions

File tree

scripts/oxlint/notice-plugin.mjs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,12 @@
2727
* (https://oxc.rs/docs/guide/usage/linter/js-plugins.html) for this repo's exact config:
2828
*
2929
* ```js
30-
* 'notice/notice': ['error', { mustMatch: 'The MIT License', template: COPYRIGHT_NOTICE }]
30+
* 'notice/notice': ['error', { template: COPYRIGHT_NOTICE }]
3131
* ```
3232
*
33-
* `eslint-plugin-notice`'s default behavior (see its `utils.js#resolveOptions`) that this
34-
* mirrors:
35-
* - `chars` defaults to 1000: only the first 1000 characters of the file are checked.
36-
* - a string `mustMatch` is compiled into a `RegExp` and tested against those characters.
37-
* - `onNonMatchingHeader` defaults to "prepend": the fixer always inserts the template at the
38-
* very start of the file, regardless of whether a (non-matching) header comment exists.
33+
* this requires the file to start with the exact `COPYRIGHT_NOTICE` text - a
34+
* header that merely resembles the real one (e.g. a subtly reworded clause)
35+
* is treated as missing.
3936
*
4037
* Usage (in `.oxlintrc.json`):
4138
* ```json
@@ -70,15 +67,11 @@ export const COPYRIGHT_NOTICE = '/*\n' +
7067
' * SOFTWARE.\n' +
7168
' */'
7269

73-
const MUST_MATCH = 'The MIT License'
74-
const CHARS = 1000
75-
7670
/**
7771
* Pure rule logic, independent of oxlint's context/AST shape, so it can be unit-tested directly.
7872
*/
7973
export function hasNoticeHeader(sourceText) {
80-
const leading = String(sourceText).replace(/\r\n/g, '\n').slice(0, CHARS)
81-
return new RegExp(MUST_MATCH).test(leading)
74+
return String(sourceText).replace(/\r\n/g, '\n').startsWith(COPYRIGHT_NOTICE)
8275
}
8376

8477
/**
@@ -89,9 +82,6 @@ export function insertNoticeHeader(sourceText) {
8982
return COPYRIGHT_NOTICE + '\n' + sourceText
9083
}
9184

92-
// `meta.name` becomes the rule namespace prefix oxlint derives for a bare jsPlugins path entry,
93-
// chosen here as "notice" so the resulting rule id ("notice/notice") matches the original
94-
// `notice/notice` rule id from `eslint-plugin-notice` used in eslint.config.mjs.
9585
const plugin = {
9686
meta: {
9787
name: 'notice',

0 commit comments

Comments
 (0)