-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Whitespace #119
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
Whitespace #119
Conversation
…void repeat or non-function "use strict" statements; curly braces, upper-case (and CamelCase) constructors per JS/JSLint convention; no need for else after previous if(s) return; define var out of loops; comment out unused function param, no assignments within statement; rmv need for continue (though jslint can be configured to allow)
…efore keywords like function/if; strange rule to have space between semicolon and curly brace
I don't like how opinionated JSLint can get. I'd prefer something like JSHint instead which just catches common coding errors. It would also be good if this was built into the Grunt build process. I think the ideal build process would be:
I just ran a quick test and JSHint found 47 errors total in the source files. Once those are fixed, this build process should stop new errors from being introduced in the future. |
Sure... Well, I think JSHint just provides more tolerant customization options. I believe valid JSLint should be valid JSHint, and my first PR did not include all of the more finicky whitespace requirements. Are there specific coding practices you did not want enforced in my first PR? If so, I can see if JSHint allows disabling them. |
I'm fine with all of the default options used in https://github.com/gruntjs/grunt-contrib-jshint to start at least. From the first PR, I don't really see the need for "use strict" and wrapping each individual source file in a closure. Some things also seem like purely cosmetic changes, like changing "editor_class" to "EditorClass" and requiring curly braces around single-line if statements. I think the real benefit of this should be catching things like duplicate |
Ok, thanks. Will take a look. Did you notice my question in that PR about: validate: function(value) {
if(!this.ready) throw "JSON Editor not ready yet. Listen for 'ready' event before validating";
// Custom value
if(arguments.length === 1) {
return this.validator.validate(arguments[1]);
}
// Current value (use cached result)
else {
return this.validation_results;
}
} If |
Yeah, that looks like a typo. It should be |
It can of course be up for debate, but his rationale about curly braces is that it is too easy for people who try to add a line of code to a statement without braces, intending to add it into the block (e.g., as another statement inside an Use of CamelCase for constructors also could arguably aid development because others familiar with this convention can identify the uses of a function more quickly. But I understand everyone has their preferences, and it's of course your project! :) I'll look to make a new PR on these points. |
Also, if Grunt is using the default options of JSHint itself, then at least for the JSHint version in Notepad++ or on jshint.com, that error with If you are open to it, I can see about adding JSHint directives which act more like JSLint minus the items you already indicated you disfavored, and then you can yourself look at the new results to see whether there are still items you wish to be ignored. |
I added jshint to the Grunt build process. It checks each file before concatenation and then the dist file at the end. If it encounters any linting errors, it will exit. It's using the default JSHint options right now. I'd be open to changing the options though if there is a compelling reason to do so. |
Ok, that's cool by me, thanks! I do have three requests as far as JSHint: The version I have using a Notepad++ plugin (which isn't letting me update to the latest version of JSHint) complains now only about an issue I partially fixed in #130 (I would need to lint a few other files besides the validator) which is that in at least older ECMAScript, reserved keywords could not be used even as object properties (older IE actually will not allow execution and a lot of syntax highlighters display them differently), so since Secondly, I see in the presumably latest JSHint at JSHint.com, when I paste the jsoneditor.js code there, there are two kinds of complaints:
/*jshint noarg:false*/
Class.extend = arguments.callee;
/*jshint noarg:true*/
|
I don't want to support any build tools outside of Grunt (i.e. Notepad++). Grunt currently comes back with no linting errors. If there's a compelling reason to make JSHint more strict, I'll consider adding options in JSON Editor doesn't support old IE, so I'm aware of the For the for-in loops, again Grunt doesn't complain, so I'd like to leave them as is. No need to add jshint directives or anything. |
Ok |
So I'll redo #130 then without the reserved word changes. |
Build on the JSLint to also add whitespace checking and changes.