Skip to content

Prevent IDE unused CSS selector warning #5

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

Closed
micantoine opened this issue Sep 19, 2020 · 6 comments
Closed

Prevent IDE unused CSS selector warning #5

micantoine opened this issue Sep 19, 2020 · 6 comments

Comments

@micantoine
Copy link
Owner

micantoine commented Sep 19, 2020

When using css module classname $style.myClassName on a html element. The svelte IDE extension does not recognize it and highlight the class .myClassName as an unused selector.

<div class="$style.myClassName">
  My html element using cssmodules
</div>

<style>
  /* Unused CSS selector warning */
  .myClassName { display: flex; }
   ~~~~~~~~~~
</style>
@micantoine micantoine changed the title Prevent svelte unused CSS selector warning Prevent IDE Warning unused CSS selector warning Sep 24, 2020
@micantoine micantoine changed the title Prevent IDE Warning unused CSS selector warning Prevent IDE unused CSS selector warning Sep 24, 2020
@micantoine
Copy link
Owner Author

Fixed in v2

@gamelaster
Copy link

image
this still happens to me ☹️

@micantoine
Copy link
Owner Author

It seems that the warning you're having is correct: .login-form input.email does not exist.

You do not have a <input> element but a component name <Input>.

you may change your css selector to:

<style lang="scss" module>
.login-form {
  ...
 .email {
  ...
 }
}
</style>

Also, I don't know if the Input component from Sveltestrap takes into consideration the class attribute. Please double check, if not you may have to use the :global() selector.

<style lang="scss" module>
.login-form {
  ...
 :global(input) {
  ...
 }
}
</style>

@gamelaster
Copy link

Hi @micantoine

My SCSS works good, just VS Code shows error. This means it's IDE plugin issue most likely.

@micantoine
Copy link
Owner Author

Yes, your code works as cssModules prevents non class selectors to be scoped (native mode). So if the Input component generates an <input> element, your rule will find a match.

Still, the IDE is telling you the truth. Your rule doesn’t exist within the component because <input> is part of a child component. Only the global() selector will let the IDE knows that this is the case.

At the end, I would recommend not to use input in your css rule. Your class .email is largely enough. Also, it does not necessary need to be nested.

.login-form { … }
.email { … }

@gamelaster
Copy link

Oh! This is giving a sense, thank you very much for explanation and solution. (and generally for whole package, it's life saver!.

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

2 participants