Skip to content

feat: add no-invalid-at-rule-placement rule #171

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

thecalamiity
Copy link
Contributor

Prerequisites checklist

What is the purpose of this pull request?

This pull request introduces a new rule no-invalid-at-rule-placement that enforces correct placement of at-rules within stylesheets.

What changes did you make? (Give an overview)

Implemented the no-invalid-at-rule-placement rule, along with documentation and tests.

Related Issues

Fixes #163
Fixes #151

Is there anything you'd like reviewers to focus on?

@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Jun 11, 2025
@lumirlumir lumirlumir added the accepted There is consensus among the team that this change meets the criteria for inclusion label Jun 12, 2025
Copy link

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

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

Nice and useful rule that plugs a gap, as CSSTree only detected misplaced declarations, e.g.:

--foo: bar; /* CSSTree parse error */
a { }

Comment on lines +1 to +7
# no-invalid-at-rule-placement

Disallow invalid placement of at-rules.

## Background

At-rules are CSS statements that instruct CSS how to behave. Some at-rules have strict placement requirements that must be followed for the stylesheet to work correctly. For example:
Copy link

Choose a reason for hiding this comment

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

@charset is no longer considered an at-rule even though it syntactically looks like one. There may be a more suitable name and wording in the documentation that better reflect this.

Copy link
Member

Choose a reason for hiding this comment

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

If it's not an at-rule, then what is it? The spec is ridiculously worded:
https://drafts.csswg.org/css-syntax/#charset-rule

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to MDN, it's not technically an at-rule but a specific byte sequence. However, I noticed it's referred to as an at-rule in no-invalid-at-rules as well. Should we add a clarifying note about this, or leave it as-is for now?

Copy link
Member

Choose a reason for hiding this comment

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

Let's leave this as-is for now. We can always circle back and do doc updates later.

@nzakas nzakas moved this from Needs Triage to Implementing in Triage Jun 12, 2025
Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

LGTM. Would like another review before merging.

@nzakas nzakas moved this from Implementing to Second Review Needed in Triage Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion contributor pool feature
Projects
Status: Second Review Needed
Development

Successfully merging this pull request may close these issues.

New Rule: no-invalid-charset-placement New Rule: no-invalid-import-position
5 participants