Comments (3)
That doesn't seem to happen to me. When using [name]__[local]___[hash:base64:5]
. The name
is based on the CSS module name, not the Javascript file.
from eslint-plugin-css-modules.
We have the same problem. Rule css-modules/no-unused-class
should probably check if every defined css class is used in at least one js file, not in all js files it's imported in.
Btw, we can't split the css file to separate css files for each js file, because we reuse some css classes in multiple js files.
from eslint-plugin-css-modules.
Hi,
I have seen people following this pattern of reusing same css file and importing in multiple js files but this is an anti-pattern. I'll try to explain why.
Let's assume we have a single css file which has some classes which will be used in 2 different js files with some common class which will be reused:
.class1 {
color: red;
}
.class2 {
color: blue;
}
.commonClass {
font-size: 14px;
}
class1
is going to be used in 1.js
class2
in 2.js
and
commonClass
will be used in all the files
Let us assume the class generated by using the css-loaders with css-modules is of form: [filename]_[className]_[hash]
When you import the css file in file 1 the following classes are generated
1_class1_xxx
1_class2_yyy
1_commonClass_www
Even if you only use 1_class1_xxx
you are actually including the other unused classes also in the bundle, hence the lint error.
Even if you think that you are reusing the commonClass you are actually creating copies of it because of how css-modules creates the css class name.
The second file 2.js
will be creating the following classes:
2_class1_333
2_class2_444
2_commonClass_ppp
you will be using only 2_class2_444
but still the other classes will be bundled.
The commonClass will be having multiple copies which is redundant.
I would recommend using composes property of css-modules
to share common classes.
from eslint-plugin-css-modules.
Related Issues (20)
- Provide a fix for mistyped class names
- Unused classes Found: Bracket notation HOT 1
- css-modules/no-undef-class error HOT 3
- Bug: Memory leak causing crash when linting many (3500+) files
- Print CSS filename when warning for unused classes with no-unused-class HOT 3
- Q: Is it possible to use this with typescript? HOT 5
- 2.9.0 - Cannot read property 'content' of undefined HOT 4
- False negative with :not HOT 1
- False "css-modules/no-undef-class" with keyframes
- "Definition for rule was not found" for [email protected] HOT 2
- Support custom extension
- Why do you support classes only, no IDs? HOT 4
- eslint-plugin-css-modules does not understand :local()
- Does not play well with Node.12, Visual Code and possibly other Electron based editors HOT 1
- no-unused-class for scss mixins HOT 2
- Mark dynamically interpolated classes as used
- Parsing error: Unexpected keyword or identifier
- TypeError: Cannot set properties of null (setting '...'), when using markAsUsed comments HOT 4
- It doesn't work with path-alias
- False positive alarm on unused class when using scss & parent selector
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-plugin-css-modules.