Skip to content
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

Add no-invalid-position-at-import-rule #5133

Closed
kapouer opened this issue Feb 6, 2021 · 3 comments · Fixed by #5202
Closed

Add no-invalid-position-at-import-rule #5133

kapouer opened this issue Feb 6, 2021 · 3 comments · Fixed by #5202
Labels
good first issue is good for newcomers status: wip is being worked on by someone type: new rule an entirely new rule

Comments

@kapouer
Copy link

kapouer commented Feb 6, 2021

What is the problem you're trying to solve?

:root {
	--bg: white;
}
@import './some.css';

Won't load some.css in chrome 88

What solution would you like to see?

A new rule that raises an error when @import is not at the top of the stylesheet.

@jeddy3 jeddy3 changed the title error when @import rule is not at the top of the file Add no-invalid-position-at-import-rule Feb 7, 2021
@jeddy3 jeddy3 added good first issue is good for newcomers status: ready to implement is ready to be worked on by someone type: new rule an entirely new rule labels Feb 7, 2021
@jeddy3
Copy link
Member

jeddy3 commented Feb 7, 2021

@kapouer Thanks for the request and for using the template.

Sounds good to me. From the spec:

Any @import rules must precede all other valid at-rules and style rules in a style sheet (ignoring @charset), or else the @import rule is invalid.

The rule should check that @import rules are only preceded by @charset and comments.

The rule is scoped to the whole sheet, and the closest prior art is no-duplicate-at-import-rules and no-invalid-double-slash-comments.

Blue print:

  • Name: no-invalid-position-at-import-rule
  • Primary option: true
  • Secondary options: None
  • Autofixable: No
  • Message: Unexpected invalid position @import rule ${atImport}
  • Description: "Disallow invalid position @import rules within a stylesheet."
  • Section: "Possible errors" -> "General / Sheet"

I've labelled the issue as ready to implement. Please consider contributing if you have time.

There are steps on how to add a new rule in the Developer guide.

@jeddy3 jeddy3 added status: wip is being worked on by someone and removed status: ready to implement is ready to be worked on by someone labels Mar 21, 2021
@dmetzner
Copy link

dmetzner commented May 7, 2021

Unfortunately, this new rule results in breaking changes when using both @use and @import in a file.

Error: @use rules must be written before any other rules.
   ╷
46 │ @use "@material/icon-button";
   │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

To disable the check:

"no-invalid-position-at-import-rule": null

@ybiquitous
Copy link
Member

@dmetzner Because this rule is for the standard CSS spec, it does not support Sass at-rules fully.
So, you need to disable the check via .stylelintrc or stylelint-disable no-invalid-position-at-import-rule.

See also the following discussion:
#5202 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue is good for newcomers status: wip is being worked on by someone type: new rule an entirely new rule
Development

Successfully merging a pull request may close this issue.

4 participants