-
-
Notifications
You must be signed in to change notification settings - Fork 21
fix: enforce strict syntax for @charset
in no-invalid-at-rules
#192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: enforce strict syntax for @charset
in no-invalid-at-rules
#192
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the no-invalid-at-rules
rule to strictly validate @charset
declarations, ensuring they use double quotes, exactly one space, and terminate with a semicolon.
- Introduced
charsetPattern
andvalidateCharsetRule
to enforce syntax in the rule implementation - Added test cases covering valid and invalid
@charset
variations - Updated documentation to detail the strict requirements and examples
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
tests/rules/no-invalid-at-rules.test.js | Added valid/invalid test cases for @charset |
src/rules/no-invalid-at-rules.js | Implemented validateCharsetRule and regex check |
docs/rules/no-invalid-at-rules.md | Added note and examples for strict @charset |
Comments suppressed due to low confidence (1)
docs/rules/no-invalid-at-rules.md:75
- [nitpick] Describing
@charset
as "not an at-rule" is misleading; consider rephrasing to clarify that it is a special at-rule requiring placement as the very first statement in a stylesheet.
Note on `@charset`: Although it begins with an `@` symbol, it is not an at-rule. It is a specific byte sequence of the following form:
context.report({ | ||
loc: prelude.loc, | ||
messageId: "invalidPrelude", | ||
data: { | ||
name, | ||
prelude: preludeText, | ||
expected: "<string>", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Currently missing semicolon errors are reported as invalidPrelude
; consider introducing a distinct messageId (e.g., missingSemicolon
) to clearly differentiate terminator errors from prelude syntax issues.
context.report({ | |
loc: prelude.loc, | |
messageId: "invalidPrelude", | |
data: { | |
name, | |
prelude: preludeText, | |
expected: "<string>", | |
const isMissingSemicolon = !nodeText.endsWith(";"); | |
context.report({ | |
loc: prelude.loc, | |
messageId: isMissingSemicolon ? "missingSemicolon" : "invalidPrelude", | |
data: { | |
name, | |
prelude: preludeText, | |
expected: isMissingSemicolon ? "; at the end" : "<string>", |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, this looks really good. What do you think about adding autofix to this rule? It seems like it should possible to just reformat the @charset
so that it's correct.
Prerequisites checklist
What is the purpose of this pull request?
To enforce strict syntax requirements for the
@charset
rule. This ensures that only valid@charset
declarations are accepted.What changes did you make? (Give an overview)
@charset
syntax. Now enforces:@charset
.@charset
usages.@charset
.Related Issues
Fixes #185
Is there anything you'd like reviewers to focus on?