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
Regular parameters should not come after default parameters #2904
Comments
This message was originally implemented as a JSHint "error" (meaning it could That said, it remains unclear if this warning is appropriate at all. I @rwaldron @caitp Do either of you have any thoughts on this? |
Just want to mention that such kind of signature is a part of redux code samples. Look for the line:
so, it is widely used, IMHO. |
This sort of pattern is absolutely the definition of "lint".
I strongly disagree with the implication that a pattern which appears in redux is indicative of something "widely used". I looked through redux and found examples of ...I'm tempted to file a bug.
I believe it is, and anyone that doesn't want the warning is welcome to turn it off. Feel free to close this @jugglinmike |
@rwaldron ok, actually we don't discuss redux. Can you provide a sample of error which can appear with such signature? |
The only runtime error you'll encounter is calling like: function counter(action, state = 0) {
return [action, state];
}
counter({});
counter({}, 0);
counter({}, undefined); And produce: function c(a,s=0){return[a,s]}
c({});
c({});
c({}); Whereas, putting the the default first: function counter(state = 0, action) {
return [state, action];
}
counter(0, {});
counter(undefined, {}); would produce: function c(s=0,a){return[s,a]}
c(0, {});
c(undefined, {}); That's a fairly contrived example, but still illustrates my point that it makes the use of a default parameter completely and utterly pointless.
Just because you can, doesn't mean you should. |
So, on the moment you can't explain why it's a bad design except worrying about bugs in minifiers |
Requiring all call sites to pass an explicit |
This behaviour is encouraged by React/Redux. I'm more likely to remove jshint than to remove React/Redux :/ http://redux.js.org/docs/basics/Reducers.html One neat trick is to use the ES6 default arguments syntax to write this in a more compact way: function todoApp(state = initialState, action) { |
@jugglinmike wdyt ^^ ? @txm what happens to the |
I'm still of the opinion that in the absense of a tangible hazard (and even in |
How can I disasable it..? |
@thalesfsp : Add |
Stumbled upon the same problem with Redux. Can this be disabled in the .jshintrc config file, please? |
@derwaldgeist Sure! Here's an example {
"esversion": 6,
"-W138": true
} |
(By the way, JSHint's documentation has more information about disabling specific warnings.) |
@jugglinmike Thanks. I did not know that it is possible to use the "-Wxxx" syntax in the .jshintrc file, too. I always used this at the top of a file. Great to know! |
With 'callback' being widely used as the last parameter of a function, this lint warning seems rather silly to me |
openDialog(url, name, args = {}, pos) { |
Apparently defaulting the other parameters to |
file to test the behaviour:
the result of
jshint a.js
content of
.jshintrc
:The text was updated successfully, but these errors were encountered: