-
-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
Write a lint rule against CSS modules #98
Comments
I got this 🐈 |
In Gatsby we added CSS Modules support only for css files with names |
@casesandberg I would use astexplorer to check the ast of the 2 forms |
We can reconsider this in a few months. But it's good to warn until/unless we commit to supporting them. |
@gaearon Should this be in a |
I'm not sure how to structure rules in eslint so whatever is simpler ;-) |
I'm not really sure either-- if there is a possibility we will have more of these in the future we should probably bundle them all together in one plugin. |
At a later point, we sure can. For now let's keep it as simple as possible. |
@gaearon is the plan to write linters against Aphrodite and Radium too? Or is CSS-in-JS okay to use? |
Both Aphrodite and Radium are fine, since they don't use any webpack-specific features, which is what we want to avoid. If we ever switch away from webpack and people are using CSS modules they won't have any chance to update because it won't work! |
CSJS is a good alternative to CSS Modules although I like the fact that you are not trying to enforce any CSS [in JS] methodology 🙏 |
I actually suggest a different approach — removing Interestingly, the whole concept of importing something from a CSS file is what I was hoping to achieve by proposing ICSS as a standard format — a minimal extension of CSS that allowed passing symbols around. This is what css-loader actually supports, everything related to So I'd love to think that any future bundler of CSS would permit some form of exporting from CSS to JS and so this kind of syntax will become more standard, but I admit that's well and truly beyond the scope of this issue :) For what it's worth, if this project did decide to "support" CSS Modules, I think the best way would be if all files ending in |
@mxstbr just wanted to doublecheck |
Meh, probably not worth it. |
Hi, I don't know if anyone care about this anymore, but today I saw one of my teammate use CSS Modules in CRA without import styles from '!style!css?modules!./background.css'; is this something "no configuration and explicit behaviour" (an alternative to the |
Yes, CSS Modules now exposes locally by default and globally by explicit declaration ( |
Please tell them it is entirely unsupported and we reserve the right to break this in any release. We don’t officially support Webpack loader syntax in import statements. If you can't find something in CRA docs then it's not supported. |
@gaearon There is an eslint-plugin-import rule forbidding Webpack syntax in the path (it basically warns if there is a I have noticed you disabled the whole plugin because of its compatibility with eslint-loader, but you could probably still use rules like these, that do not attempt to load/read other files. (I'm happy to make you a list of rules that should be fine and useful if you want) |
As much as we appreciate the pain points CSS Modules are solving, we’ve made a decision not to use them in this project. You can see some discussion on this in #90.
However Webpack currently lets you use custom
:local
syntax to “enable” them in regular CSS files. We don’t want people to do this because this limits our ability to add more CSS tools or migrate from Webpack to other bundlers in the future.This is why we should enforce that people don’t use
:local
syntax. Otherwise we’ll just randomly break their apps when we change something in how we handle CSS. This won’t be fun, and people will blame us for that even though we explicitly do not support this feature.Luckily, it is easy to fix. We should write a custom lint rule with
ERROR
level that is triggered on a statement like this:This, however, should work fine:
This semi-enforces that you don’t use CSS Modules because we just don’t support them. We can ensure your CSS stays reasonably portable in case we want to change the underlying architecture.
Reference on writing ESLint rules: http://eslint.org/docs/developer-guide/working-with-rules.
If you want to work on this, please write here so we don’t have multiple people doing it at the same time.
The text was updated successfully, but these errors were encountered: