-
-
Notifications
You must be signed in to change notification settings - Fork 928
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
Defining whitespace rules #40
Comments
A few notes about prior art:
Of the three above, JSCS's consistency and simplicity appeal to me; and I think that the suggestions I've made are closest to it. |
On space is fine for me for now. It was just an idea.
Good idea.
comma is fine. Maybe I was thinking about including combinators etc.
Yep
No sure what is the best. Maybe try with rules without -before/after like first proposition.
lgtm too. I think having one option with an {before/after} object is a good idea. |
Good thinking! I ended up adding a
Agreed. Lets keep it simple.
Nope.
Agreed. I think we're totally on the right track, but it doesn't feel like we've adequately addressed the mismatch of boolean options ( #38 ). How about we reserve boolean options for media-query-list-comma-space-before: "always"|"never",
selector-comma-newline-before: "always"|"never",
color-hex-shorthand: "always"|"never",
color-no-named: bool // only "true" is documented It doesn't have the cleanliness of JSCS boolean approach, but it feels like an alright compromise to tackle the mismatch of boolean options. How does that sound?
I feel that keeping the rules laser-focused to begin with is the way to go. And so, I'd prefer to keep them separate. Mainly because being laser-focused feels right, but also (to a lesser extent) because:
Thoughts? |
Or, another option is following the JSCS allow/disallow to the letter, which makes all booleans media-query-list-comma-space-before: bool // only "true" is documented
media-query-list-comma-no-space-before: bool // only "true" is documented
selector-comma-newline-before: bool // only "true" is documented
selector-comma-no-newline-before: bool // only "true" is documented
color-hex-shorthand: bool // only "true" is documented
color-hex-longhand: bool // only "true" is documented
color-no-named: bool // only "true" is documented
string-quotes: "single"|"double"|"none" Or is that too odd? |
Agree with your 1. and 2. @jeddy3. |
Ha, yes, that is a possibility :)
Me neither. Each approach seems to have its pros and cons. Thinking about it some more, perhaps the boolean options ambiguity ( #38 ), i.e. inconsistent "must be" and "must not be", isn't a big enough issue that it should force a change to @davidtheclark proposal of using booleans in whitespace rules (e.g. For example:
Does that make sense or am I just clutching at straws? :) |
As noted here #38 (comment) I think part of escaping the boolean ambiguity will be using severity levels to turn on/off. If we do that and use always/never (everyone seemed to like that) we might not really have to use booleans must at all.
I think I would prefer not splitting up require/disallow and not splitting up before/after in most cases, because looking at JSCS config files makes me want to give up and go to sleep :) --- I think the idea that we'd have a shorter, more clear config. |
So if we're in agreement that a 0-1-2 severity level thing is important, I could try to build that in next time I have a few minutes to code. We won't have it affecting any reporter yet; but we'd have it affecting on/off state of rules. Agreed? |
Yeap.
Yeap, affecting the reporter can come later.
Ooooh, now I see what you mean. SGTM.
Ha, fair point :) It was very easy configuring the eslint whitespace rules yesterday as the config was clear and short. The whole "A user might want to enforce whitespace before something, but not after something (and vice-versa)" felt like an edge-case anyway. If the need ever arises, we could always pull a few of the rules apart and offer them up too. So, going with:
Sounds great to me. The only bit I was unsure about was:
Were we going to avoid default rules and values? Or, is it odd to require options for some rules e.g. whitespace ones or things like Otherwise, it all makes sense to me. However, just to make doubly sure we're on the same page, the rules would look something like?: color-hex-shorthand: [2, "always"|"never"],
color-no-named: 2,
media-query-list-comma-space: [2, { before: "always"|"never", after: "always"|"never" }],
url-quotes: [2, "single"|"double"|"none"] |
Your example rule-configs sum up nicely. I think we're on the same page. I think that default values for specific rules that are turned on makes sense, just not having any rules turned on by default. Especially since, as you agree, for many of our cases configuring something other than the default (e.g. no space before comma, one space after) would be unusual. |
Good stuff :)
Eek, I meant I'd prefer no default values... :) I said this over in #1 (comment) about default rules:
I think this can be expanded to include the why of default values too. Take Or take I think, more often than not, the default won't be as obvious as I think we're opening ourselves up to a can of worms if we go down the default value route: additional (and subjective) initial discussions, fielding issues about the defaults, additional documentation explaining why the default etc. Being unopinionated (from no default rules down to no default values) frees us from this. Later down the line we could use the options validator to let the user know when options are required. I think, for now, we can rely on the documentation for each rule. Likewise, offering example configs for a popular styleguide or two would help. What do you think? |
I'm good with no defaults, too, to save the trouble. |
I agree with all things you agree :)
@jeddy3 example à la ESLint lgtm
+1 Great discussion. Thanks guys! |
Please review commits 64f72fe and eac5549 I didn't do separate PRs because I needed the first one merged before the second one, before the second is following up on the proof-of-concept. But I'm happy to change stuff as desired. So here's what I was thinking: We have a lot of whitespace rules that we want to treat in a standard way. There are some subtleties to the whitespace rules that we usually want to repeat, as well (e.g. enforce only one space before instead of at least one space). So I made some utils for the repeating pattern. I figure it might be better to have reusable abstractions than doing a lot of copy-pasting in order to reproduce patterns. standardWhitespaceOptions and standardWhitespaceMessages just create standardized options and messages objects with an API that standardWhitespaceChecker understands. As you can see in selector-combinator-space and declaration-bang-space, that standardWhitespaceChecker handles the bulk of the validation, reducing boilerplate and possible inconsistencies (e.g. I might have forgotten to check for double spaces in declaration-bang-space). After creating selector-combinator-space it was a matter of just a few minutes to create declaration-bang-space --- all the time went into writing tests. |
I'll wait to check off that those rules are done to see first what you think of this setup. |
You can do PR cutted from another PR and just tell which one need to be reviewed/merged before the other :) Very nice approch ! |
Agreed. It looks excellent! I'll refactor Thanks, as always, for all the great code! :) |
Sounds like you're onboard with the approach exemplified in a couple of rules now, so I'll close this. |
I have another thought about this: In the block-brace rules we still have a single-line vs. multi-line distinction which I think we glossed over ... I noticed this when looking back at #1 after @jeddy3's updates. I'm thinking that maybe the single vs. multi distinction could be made by alternative keywords. We'd add to |
Ha, yeah. That bit is littered with "(???)"'s :)
SGTM. |
I think eslint is doing that too (example: |
Ok sounds like agreement then. I'll close this again. |
Expanded from #20 (comment)
It seems that in most whitespace rules in #1 it is suggested that users will be able to enter their own whitespace values. Maybe one space, three spaces, newline, carriage return, etc. I'm worried this will add a lot of overhead and complexity in order to accommodate rare edge cases.
Personally I have not yet seen standardized CSS where the convention was to use anything other than one or no spaces in most of those places (around combinators, colons, bang, commas, parentheses). Only braces have varied, and only by adding the possibility of a newline to that of a single space.
Maybe you don't buy that, and think that we need to allow for lots of variations? Anybody feel this way?
If you agree with me, I can think of a few possible ways simplify things:
space
rules which have before and after options. So instead ofmedia-query-list-comma-before
andmedia-query-list-comma-after
we havemedia-query-list-comma-space
; and its options are either{ before: [boolean], after: [boolean] }
(where true means always and false means never) ortrue
which must provides a standard default (for commas, that would be{ before: false, after: true }
). If you don't like having before/after options, we could instead keep separate rules but make them space-specific, e.g.media-query-list-comma-space-before
andmedia-query-list-comma-space-after
.selector-delimiter-before
andselector-delimiter-after
(first of all, why not "comma" instead of "delimiter"?) ... so that might reasonably be either a space or a newline (though almost certainly not tab, carriage return, four spaces, etc.). We could makeselector-delimiter-space
andselector-delimiter-newline
with before/after options; or, alternately,selector-delimiter-space-before
andselector-delimiter-newline-before
and their-after
counterparts.The text was updated successfully, but these errors were encountered: