Comments (27)
Looks like a complex behavior. Try to split in a row of simple rules. (See current rules for examples)
from node-jscs.
@markelog is this something you could look into? Would be useful to get this into the jQuery preset.
from node-jscs.
@jzaefferer yes, it's on my list, although there is couple more issues with jscs
and grunt plugin that has to be fixed before i can work on this ticket.
from node-jscs.
@markelog are you prepared to take this one on? If not, I can jump in on it later this week unless you'd like to continue on it. Just let me know. Thanks!
from node-jscs.
@mikesherov hey! i want to do cool things too you know :-).
I also wanted to work on this in this week, how about if i fail to get time on it, you would pick it up?
from node-jscs.
@markelog take your time! I was just trying to triage everything that remains open. Glad to have you take it on and I'll wait patiently :-)
from node-jscs.
array = [ a, b ];
object = { a: b };
Already supported by requireSpacesInsideObjectBrackets
and requireSpacesInsideArrayBrackets
rules.
But there should be abilities to check for cases like these:
if(...)
, for(...)
, while(...)
, catch(...)
, switch(...)
, case(...)
, with(...)
, FE, FD and etc; plus function calls.
Which would be easy enough to implement as antonim of disallowSpacesInsideParentheses
, like requireSpacesInsideParentheses
.
But problem with it, is that parentheses could also be used for grouping, for that case it's preferable to check for absence of extra spaces, i.e. this case –
for ( ; (elem = elems[ i ]) != null; i++ ) {
should be valid, but this one shouldn't –
for ( ; ( elem = elems[ i ] ) != null; i++ ) {
In style guide mentioned above, this case is not explicitly included, but it will be, if it could be automatically checked.
So all that could be done with rules like these –
"requireSpacesInsideParenthesesForKeywords": ["for", "function"],
"requireSpacesInsideParenthesesForFunctionsCalls": true
// or with possible object value like this –
"requireSpacesInsideParenthesesForFunctionsCalls": {
"exceptForClosestPunctuators": ["{", "}"],
},
"disallowSpacesInsideGroupingParethenses": true
Or something less verbose or contrariwise?
But such tactic (especially with disallowSpacesInsideParentheses
rule at hand and possible future opposite rules for those above) would contribute to bloatedness of current options.
@mikesherov, @mdevils thoughts?
from node-jscs.
Oh, yes, empty parentheses should be treated tolerably, similar to requireSpacesInsideObjectBrackets
and requireSpacesInsideArrayBrackets
.
from node-jscs.
The jQuery style guide used to have exceptions for nested parens, those were removed. So in your two for
examples, the first one is invalid, the second one valid.
Do requireSpacesInsideObjectBrackets
etc. accept []
and {}
as valid?
from node-jscs.
Only allows no spaces if you use "allButNested".
My 2 cents is that the jQuery nested spacing rules belongs as a custom rule in the jQuery preset because it has enough caveats to cause a "generic" rule to have too many options.
This would require us to use my proposal for presets, which not only allows preset configuration, but also custom rules for that "standard".
jQuery would be able to distribute their own JSCS standard, or we could have JSCS-standard-jQuery and go the grunt route of npm based plugins.
Mike
On Sun, Jan 12, 2014 at 2:21 PM, Jörn Zaefferer [email protected]
wrote:
The jQuery style guide used to have exceptions for nested parens, those were removed. So in your two
for
examples, the first one is invalid, the second one valid.Do
requireSpacesInsideObjectBrackets
etc. accept[]
and{}
as valid?Reply to this email directly or view it on GitHub:
#92 (comment)
from node-jscs.
The jQuery style guide used to have exceptions for nested parens, those were removed
it's not about nested parentheses, it's about parentheses that used for grouping and grouping only, nested parentheses still require spaces.
@mikesherov custom rules and custom presets are nice, but i think it would be cooler if jscs
would at least support
google, ours and idiomatic code styles right from the start, as they are most used code styles as far as i know.
And they could be a good examples for what you can do with jscs
.
from node-jscs.
Only allows no spaces if you use "allButNested".
No actually :-)
from node-jscs.
Do requireSpacesInsideObjectBrackets etc. accept [] and {} as valid?
Yep.
from node-jscs.
@markelog does this issue get solved by #333 If not, I'll take a stab at implementing this rule soon.
from node-jscs.
No, we need something that can separate grouping parentheses from all other ones also we need an exception mechanism so we could do:
// Function with a callback, object, or array as the first argument:
// No space before the first argument
foo(function() {
// Do stuff
}, options );
from node-jscs.
@markelog I think this is a perfect example of a rule that needs to come with JSCS but exists in the jQuery preset only (perhaps even living in that subdir so the preset loads its own special rules). This would help lay groundwork for jQuery specific rules like chaining style as well.
Thoughts?
from node-jscs.
I think this is a perfect example
This exceptions are exist in idiomatic and jQuery code styles, mediawiki probably could use that to in some way, so i wouldn't say so.
What rules are redundant? What rules are needed? What rules should be added to jscs
and what rules should be used only as plugins?
Those are difficult questions, right now, we're subjective about it - we might think some rules are needles or otherwise, but we don't know for sure, we don't know how much people using them or how much people would be using some perspective new rule.
I guess the best way to differentiate them and be objective, is to judge if some popular preset needed it, if it does, then it should be added. No? Use a plugin then.
Pretty simple and easy to understand for rule writers. I would employ this strategy for any new possible rule that could be proposed to jscs
core.
@mdevils thoughts?
from node-jscs.
I guess the best way to differentiate them and be objective, is to judge if some popular preset needed it, if it does, then it should be added. No? Use a plugin then.
Not saying it belongs in a jQuery plugin. I was saying it belongs in the jQuery preset as an additionalRule
.
from node-jscs.
Not saying it belongs in a jQuery plugin. I was saying it belongs in the jQuery preset as an additionalRule.
perhaps even living in that subdir so the preset loads its own special rules
Basically, what i'm proposing that if you can't include rule in some of the presets then it shouldn't be in jscs
, but if some preset is incomplete without some rule then it should be available in jscs
, because it's definitely needed, whereas we can't use phrase "definitely needed" for rule that is not used by one of presets.
from node-jscs.
So you see, presets could be a measure of importance/popularity of the rule
from node-jscs.
@mikesherov I guess this should not be a different rule but extension of *SpacesInsideParentheses
from node-jscs.
OK, so then for right now, I think we only need to add rules to cover call expression argument spacing to match the written jQuery style guide. @markelog are you going to tackle this or should I?
from node-jscs.
Will definitely cover #406 and #402
That is pretty bad-ass problem (grouping parentheses i mean), try it do before, but didn't get anywhere, if you like, you can take a swing at this.
from node-jscs.
But I mean, the jQuery rule is for call expressions seems simple: always space after open parens and before close parens unless the argument is a function expression, array literal, or object literal
, right? Or am I missing something?
from node-jscs.
I may be missing something, but the commit that closed that issue doesn't make any changes to the jQuery preset. Is that intended? Seems like new options would need to be added to the preset...
from node-jscs.
No, it was a mistake, that commit addressed that issue only partially
from node-jscs.
The saga of this issue has now been resolved by simplifying the jQuery style guide. I'm going to close this issue and file another one just for adding existing rules to the jQuery style guide.
from node-jscs.
Related Issues (20)
- jscs exlucdeFiles not Work! HOT 1
- Should have exception for disallowSpacesInFunction for anonymous generators HOT 1
- not possible to include extensions with multiple "." characters HOT 7
- Error running rule requirePaddingNewLinesBeforeLineComments HOT 1
- not possible to ignore '.js' files with fileExtensions #2273
- Destructuring with default values in parameters throws an error. HOT 1
- Cannot find module 'babel-runtime/core-js/object/keys' HOT 8
- Error: Symbol is not defined (first character of file) HOT 3
- Add `templateStrings` as an option for the `allExcept` property of the `maximumLineLength` rule HOT 2
- requireSpaceBeforeDestructuredValues does not work in vanilla JS HOT 3
- maximumLineLength should optionally allow string literals to break the rule HOT 2
- validateIndentation should enforce endbrace at the same indentation as the line containing it's corresponding startbrace HOT 2
- Error running rule requireDollarBeforejQueryAssignment HOT 3
- JSCS goes into infinite loop HOT 2
- About jsx curly braces variable HOT 1
- JSCS crashes due to decorators HOT 1
- requireSpaceBetweenArguments doesn't work in constructor of es6. HOT 4
- How to write a rule which makes "case" align to "switch" in switch statement? HOT 1
- jscs.info offline HOT 3
- Disabling Specific Rules For a Single Line not working HOT 1
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 node-jscs.