Skip to content

fix: disable rule options schema validation in eslint 9, fix https://github.com/Stuk/eslint-plugin-header/issues/57#58

Open
tonyganchev wants to merge 172 commits intoStuk:mainfrom
tonyganchev:main
Open

fix: disable rule options schema validation in eslint 9, fix https://github.com/Stuk/eslint-plugin-header/issues/57#58
tonyganchev wants to merge 172 commits intoStuk:mainfrom
tonyganchev:main

Conversation

@tonyganchev
Copy link

@tonyganchev tonyganchev commented Jun 10, 2024

Temporary fix to allow the header rule options to pass schema validation introduced in eslint 9 as per https://eslint.org/blog/2024/04/eslint-v9.0.0-released/#changes-to-how-you-write-rules

Fixes #57

@tonyganchev tonyganchev changed the title fix: disable rule options schema validation in eslint 9 fix: disable rule options schema validation in eslint 9, fix https://github.com/Stuk/eslint-plugin-header/issues/57 Jun 10, 2024
@tonyganchev
Copy link
Author

I've published a fork at https://www.npmjs.com/package/@tony.ganchev/eslint-plugin-header containing my fix.

tonyganchev and others added 22 commits June 20, 2025 22:35
In the process, upgraded all  dependencies
Original logic was expecting the third argument of the header rule to always be the number of empty lines expected. Unfortunately, after line-ending character settigns were added as an optional config argument, the logic no longer stands true.
Goal is to use the header rule itself to lint its codebase.
# Why?
Most unit invalid test cases did not pass when running under Windows because test cases expected fixes to use LF and not CR+LF.

# The Fix
Modify node's line ending property using testdouble to ensure the test cases are executed in a POSIX-compatible/simulated environment.

# Upcomming Fix
A subsequent PR will add a good representation of both POSIX and Windows in the test cases.
# The Problem
There was a bug in `genCommentsRange()` where only one character is checked after the comment for an EOL character. Since on Windows we need two characters, the check failed and the wrong number of empty lines was added on windows (desired+1) which caused both tests to fail and the autofix to give different results from POSIX.

# The Fix
_N_ number of characters are tested, where _N_ is the length of the current EOL string.
This would help the IDE give better autocompletion suggestion. The changes are only tested with VS Code.
- Perf fix: bail on first line in a header comment not matching.
- added constants for comment-style and line-ending overrides.
This is a step toward matching leading comments allowed to preempt the header license / copyright comment.
* feat: leadingComments schema

* feat: leadingComments normalization in rule

* test: leadingComments test-cases

* style: leading + on wrapped strings

* refactor: simplified regex

* refactor: get all comments before the first line of code

* refactor: remove hasHeader() check

* test: restore code coverage

* feat: match tolerated leading comments.

* feat: report missing header when all leading comments match to allowed leading comments.

* feat: distinct error reporting

* docs: updating documentation
…mments.

The issue, the logic that grouped leading comments for testign allowed leading comments before the header were treated as line comments and not block comments meaning they were considered one and the same comment as a line-comment header. This failed validation for such sources. Adding an empty line triggered a separate check that the header is on line 2 if there is a shebang - with an empty line it started from line 3.

The issue affected only v3.3.0
To support the plugin being run by oxlint, there is a specific problem where oxlint expect the default configuration to pass schema validation which is not possible since the header-matching rule cannot have a default value. The solution: remove all default settings which are in any way added in the code.
oxlint was picky about validating the default option of the rule so I had to remove all default options from the rule definition and only rely on runtime validation in the code of the rule itself.

Added a smoke test to confirm the oxlint support is not broken - and fixed the existing smoke tests as their asserts had become too basic.
Fixes: #151

The Issue
---------
_@typescript-eslint/parser_ treats shebangs differently
depending on the effective _tsconfig.json_ it uses. Under some
configurations it silently drops the shebang comments when building the
AST, and with other configurations it treats them as special comment
type _Shebang_ - similar to the standard JavaScript parser. Adding an
auto-configration setting to `parserOptions` object eliminates the issue
but since older versions of the rule worked without any new
configuration we have to fix this.

But why omitting the shabng comment is the issue if the first comment
matches the expected header?! The reason is that we inherited a rigid
expectation from _eslint-plugin-header_ that there is no empty line
before the header. We explicitly enforce this rule for the first comment
by not testing the first comment starting on line that is not the first
therefore reporting a missing header violation. In our particular case
the header starts from line 2 because line 1 is taken up by the
"non-existent" shbang comment.

The Fix
-------
Instead of relying on the parser to detect the shebang, we check if the
first two symbols of the code are `#!`. We then ensure the first comment
is no longer a shebang by removing it from the `leadingComments` array
if it exists. This covers for the three cases:

- JS parser.
- Misconfigured TS parser.
- Correclty configured TS parser.

Added a new unit test section that uses the TypeScript parser.
* ci: improve actions

- split linting, unit-, and e2e testing to separate steps executed in parallel
- have test workflow run as prerequisite to npm-publish

* fixup! ci: improve actions
* test: ecosystem test for angular-cli

* fixup! test: ecosystem test for angular-cli
* ci: more ecosystem tests

- wireapp/wire-webapp
- wppconnect-team/wa-js
- online-go/online-go.com
- forcedotcom/salesforcedx-vscode
- Azure/azure-dev
- xdan/jodit

* fixup! ci: more ecosystem tests

* fixup! fixup! ci: more ecosystem tests
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.

Error: Key "rules": Key "header/header": should NOT have more than 0 items.

2 participants