Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

requireSpaceBetweenArguments: new rule #774

Closed

Conversation

jamesallardice
Copy link
Contributor

Validates that call expression arguments have the correct spacing before and after.

Closes #771

Validates that call expression arguments have the correct spacing before and after.

Closes jscs-dev#771
@coveralls
Copy link

Coverage Status

Coverage increased (+0.07%) when pulling 82d5744 on jamesallardice:argument-space-rule into 32da403 on jscs-dev:master.

@indexzero
Copy link
Contributor

How is this different than "validateParameterSeparator"

@indexzero
Copy link
Contributor

Yeah, sorry didn't mean to be short there, just got to Paris. Super jet lagged.

This looks to be exactly the same rules though: https://github.com/jscs-dev/node-jscs/blob/master/README.md#validateparameterseparator

@jamesallardice
Copy link
Contributor Author

@indexzero This rule validates the separation of arguments in call expressions. The validateParameterSeparators validates the separation of parameters in function signatures:

function a(b, c, d) {} // validateParameterSeparators
a(1, 2, 3); // requireSpaceBetweenArguments

See #771.

The code is largely similar between the two (only difference is the error message itself) but I couldn't see a way to DRY it easily (doesn't seem to be anywhere to put code relevant to multiple rules). Open to suggestions if I've overlooked something.

@indexzero
Copy link
Contributor

Ah ok. Thanks for explaining it to me! Is the plan to move "validateParameterSeparators" to "requireSpaceBetweenParameters" in 2.0.0 then?

@jamesallardice
Copy link
Contributor Author

No problem. Yeah I believe so. At least that's what I took this to mean:

we're trying to unify rule names and values.

Rule naming seems a lot more consistent that the last time I contributed which was a good few months ago. Most rules are now disallow-* or require-*.


it('accepts valid separator', function() {
var validSeparators = [
',',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a valid separator? It's not in the list of acceptable values for this rule.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrjoelkemp I think it probably should be. I'm sure there are are people who write that way. I can remove it if you think it's not very useful or I can add it to the readme.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a "valid" separator, your rule's regex might need to be strengthened to disallow that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's useful, but the rule is meant to force a space between arguments. Forcing ',' (no spaces) is best for disallowSpaceBetweenArguments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrjoelkemp Sorry, to clarify that, it is a valid separator. It just isn't mentioned in the list of acceptable values. I will add it to the list.

@mrjoelkemp
Copy link
Member

Great job on this @jamesallardice! It's looking good except for a the ',' false positive. It seems like we also need the new rule: disallowSpaceBetweenArguments. I imagine that's simpler than the rule you implemented; would you mind giving that a go?

@jamesallardice
Copy link
Contributor Author

@mrjoelkemp Sorry, GitHub failed to notify me about half of your comments! Yes, I agree, I will remove the ',' option and add a separate rule for disallowing spaces.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.07%) when pulling d001e96 on jamesallardice:argument-space-rule into 32da403 on jscs-dev:master.

@markelog
Copy link
Member

How about true value, it should solve

doStuff(a, b, c); // valid
doStuff(a,b,c); // invalid

Whereas value would be more consistent with other rules, yes, it would be not flexible as it could have been, but really, who would write code like:

doStuff(a , b ,);

?

That would mean implementing opposite rule too.

@jamesallardice
Copy link
Contributor Author

@markelog I think that's a good idea. I based this rule off the validateParameterSeparator rule which is why it has the values it does. Since we've already established that we'll need to opposite rule I think it would be good to just have a boolean value... I guess the question is does anyone write code like this:

doStuff(a , b , c);  // I doubt it
doStuff(a ,b ,c);    // Maybe

So I also guess it depends on how flexible we want to be. Allow people to define their own separators, or just cater for a, b, c and a,b,c.

@markelog
Copy link
Member

a, b, c and a,b,c

I think those cases could be used in the presets, when others are not, so they are probably more common then others.

I would say, let's be a little less flexible and a little bit more consistent.

James Allardice added 3 commits December 1, 2014 22:18
Validates that call expression arguments have no space after the separator token
@jamesallardice
Copy link
Contributor Author

I think the solution now follows what we discussed. There are 2 rules, requireSpaceBetweenArguments and disallowSpaceBetweenArguments. This allows validation of the two common cases, a(b, c) and a(b,c).

Should the commits be squashed so it appears as it was done this way first time around or do you prefer to keep the history?

@coveralls
Copy link

Coverage Status

Coverage increased (+1.0%) when pulling 329f06e on jamesallardice:argument-space-rule into d931b4f on jscs-dev:master.

@markelog markelog closed this in 2541102 Dec 3, 2014
@markelog
Copy link
Member

markelog commented Dec 3, 2014

Should the commits be squashed so it appears as it was done this way first time around or do you prefer to keep the history?

Took care of it, thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should the validateParameterSeparator rule apply to call expressions?
5 participants