Comments (8)
There might be a bigger (and more contentious) question here about what should and shouldn't be in core. And if there is stuff outside of core, how do users plug that stuff in?
The indention options are complex because I think it is trying to support an indentation method where rule-sets are indented based on their selector. The example below includes the options for indenting rule-sets with a pseudo class by two tabs, bem elements by one and bem modifiers by none etc ...
{
"indentation": {
"default": 1, // e.g. "1" tab or "2" spaces
"char": "\t", // probably better to have a keyword here e.g. "tab"|"space"
"block": true, // indent blocks by the default amount and char.
"rule-set-by-selector-class-bem-element": true, // same with bem elements
"rule-set-by-selector-class-bem-modifier": false, // not with bem modifers
"rule-set-by-selector-pseudo-classes": 2, // indent with 2 of the char e.g. tabs
"rule-set-by-selector-pseudo-element": true // default amount and char
}
}
To support a method like:
.A { }
.A-element { }
.A-element:pseudo-class { }
.A--modifier { }
I can see the advantages to such an approach, but should this be in core? Unlike everything else we've done so far it does not feel timeless i.e. if BEM is ever replaced by a different methodology this will become redundant. Whereas everything else has been about the CSS language itself, and not an architecture methodology. Does it feel like a good candidate for a plugin or something similar?
If the code in core didn't tackle the bem stuff then I think the options could become:
{
"indentation": {
"quantity": 1, // e.g. "2" tab or "4" spaces
"char": "tab"|"space"
"block": "always"|"never", // not sure if we need these
"value": "always"|"never" // too complicated?
}
}
So, given:
{
"indentation": {
"quantity": 2,
"char": "space",
"block": "always",
"value": "always"
}
}
This is valid:
a {
color: pink;
background-image: url(x.jpg),
url(y.jpg),
url(z.jpg);
height: 0;
}
The scsslint implementation, csscomb one and the one in eslint for supporting something simpler like this looks pretty complicated to begin with.
What are you two's thoughts on getting something similar to work in core first before expanding out into, perhaps, plugins and the like?
from stylelint.
Yes, I think that building BEM into the core is too much. I say we leave it for a plugin.
I guess "block": "always"|"never"
is important, because it means some people could do:
@media print {
a { color: pink; }
b { color: orange; }
}
Right?
"value"
makes sense to me as an option, too --- but I guess I'm wondering if anybody would ever set it to "never"
? This would be pretty nasty ...
a {
color: pink;
background-image: url(x.jpg),
url(y.jpg),
url(z.jpg);
height: 0;
}
from stylelint.
Another possibility that came to mind, a little bit nonstandard but maybe fitting the scenario, would be we have boolean options like ignoreBlock
, ignoreValue
, ignoreSingleLine
. These would be simpler than an always/never pair of keywords and might get the job done, right?
from stylelint.
Not a fan of the ignore* approach.
We can have default value for the details, cause we can easily agree that most people will indent block in block and value like in your background-image example.
I must agree that having "bem" seems weird seems it's not a word from the css vocabulary.
That said I like the idea of handling a such case in core (maybe not for the start).
What about something like "class-children" and "class-variation" ? (with a way to define this patterns somewhere so people can define how to find children (eg: bem elements) and how to find variations (eg: bem modifier).
For a start we can go with minimal options. I like how eslint differentiate tab from space. Since people are unlikely to use multiple tab, eslint have one parameter to define "tab" or a number of spaces (which make sense to me).
from stylelint.
I agree that multiple tabs is not a necessary option.
So how about this to start:
{
"indentation": {
"space": 2, // or 4 or "tab"
"block": "always", // or "never"
"value": "always" // or "never"
}
}
Or "space" could be "indent"?
from stylelint.
I got a start on this rule in the branch "indentation" (f158562), which I pushed so you could look at it (but of course I don't want to merge it into master yet): https://github.com/stylelint/stylelint/tree/indentation
(I have not yet messed with the block
or value
options, and have only created enough test cases to see if I'm on the right track with the rule's implementation.)
I think one of the most significant aspects of doing this one right will be in accumulating good, thorough test cases. (Notice that the ability to use ES6 template literals makes writing these test cases nice, without the need for external fixtures!) So it would be really helpful if anybody could help churn out test cases, either adding to the branch or just posting them here.
from stylelint.
What you did seems pretty good to me.
from stylelint.
What you did seems pretty good to me.
Agreed. It's fantastic to see you tackle so many rules in a just a week!
from stylelint.
Related Issues (20)
- no-missing-end-of-source-newline false positive after upgrade to v16.4.0 (from 15.11.0) HOT 1
- SCSS: Issue with double slash comment HOT 1
- DeprecationWarning: fs.Stats constructor is deprecated HOT 6
- Node.js API should allow fixing a list of files in-place HOT 3
- Rule idea: `declaration-prefer-shorthand` HOT 2
- Fix `selector-type-no-unknown` false positive for `model`
- Release 16.6.0 HOT 11
- Missing semicolon in JSON file HOT 5
- Fix `no-descending-specificity` false positives for nested selectors HOT 2
- Release 16.6.1 HOT 5
- breaking changes for `property-no-vendor-prefix` HOT 6
- New rule: identifier-pattern HOT 12
- Remove `postcssResult.stylelint.disableWritingFix` HOT 7
- Unknown rule no-extra-semicolons. HOT 3
- `block-no-empty` false `needless-disable` in blocks with comments. HOT 2
- New rule: Disallow unconstrained `:has()` for performance reasons HOT 3
- `at-rule-no-unknown` false positive for `@view-transition` HOT 2
- `property-no-unknown` false positive for descriptor `navigation` HOT 1
- Add `junit` as a core formatter HOT 1
- Update the documentation of `isAutoprefixable` util
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 stylelint.