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

Ignore style="..." attributes #38

Closed
james-camilleri opened this issue Feb 19, 2022 · 4 comments
Closed

Ignore style="..." attributes #38

james-camilleri opened this issue Feb 19, 2022 · 4 comments

Comments

@james-camilleri
Copy link

I couldn't find any information about this anywhere, so I might be missing something obvious - sorry if that's the case.

Is there any way to have the parser handle <style> tags but not <div style="..."> attributes? I've set this up with a Svelte project, and while the linting is working as I'd hoped in my main style tags, it seems a bit bizarre for the linter to flag things like "Expected empty line before custom property" in a single-line style attribute.

Is there an option that can be configured, or have I messed up some default? And if not, is it something that could be corrected?

Thanks!

@ota-meshi
Copy link
Owner

Thank you for posting this issue.

I'm not sure if we need to add that ignore style="..." option.
The custom-property-empty-line-before rule has an option to ignore a single line.
https://stylelint.io/user-guide/rules/list/custom-property-empty-line-before#inside-single-line-block
Why can't you use it?

Also, can't you use <!-- postcss-ignore --> comments?
https://github.com/ota-meshi/postcss-html#turning-postcss-off-from-within-your-html

@james-camilleri
Copy link
Author

james-camilleri commented Mar 1, 2022

Hi! Thanks for getting back to me on this. I didn't know about the single line rule, that will probably fix this particular scenario. I'll give it a shot. I'm not sure if there are any other scenarios where this option would come in handy, so perhaps I should close the ticket and reopen it if I run into any other scenarios?

In response to the post css ignore comments however, it would be extremely messy if they were required for every single inline style rule across all component files, so I don't really think that's a solution.

@ota-meshi
Copy link
Owner

I don't think we need the option to ignore the attribute. If you think need it, open a new issue and explain in detail why you need it.

@mattosborn
Copy link

I'm not sure if we need to add that ignore style="..." option. The custom-property-empty-line-before rule has an option to ignore a single line. https://stylelint.io/user-guide/rules/list/custom-property-empty-line-before#inside-single-line-block Why can't you use it?

It looks like these exceptions don't work correctly for inline svelte style attributes. My guess is inline css isn't being seen as a single-line-block as far as the linter is concerned. For example with the following rule config:

"custom-property-empty-line-before": "always"

This throws two errors:

image

I'd expect the following config to fix these errors (actually just the ignore should do it really?):

"custom-property-empty-line-before": [
  "always",
  {
    "except": [ "first-nested" ],
    "ignore": [ "inside-single-line-block" ]
  }
]

But it has no effect. Adding "after-custom-property" to except disables the second error, so the parser is picking up the config.

The only two options I can see for svelte projects are:

  1. Disable the rule entirely
  2. Wrap offending elements in <!-- postcss-ignore -->

Neither of which are ideal

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

No branches or pull requests

3 participants