Skip to content
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

Add jscs to check style #1565

Merged
merged 1 commit into from
Apr 23, 2015
Merged

Add jscs to check style #1565

merged 1 commit into from
Apr 23, 2015

Conversation

hzoo
Copy link
Contributor

@hzoo hzoo commented Mar 26, 2015

@ryanseddon
from #1551 (comment).

I just copied the format from jshint so it will run it in on the same files (and same ignores).

I didn't know what the rules should be (so we can start discussing that now based on the code) so I just picked the google preset as a start (using the jscs autoconfigure option (jscs --autoconfigure src/ lib/ feature-detects/)

One option is to use it as a base or just copy the rules from the preset and add/remove as needed. If there isn't a written style guide or another one to follow we can just look at what's the majority.

Another thing would be how to go about fixing the styles after determining rules.
We can use the autofix setting jscs --auto-fix (only in master branch) to fix most of the whitespace changes and everything else would be manual. I went ahead and did the autofix changes in a seperate commit so the potential changes of using the google preset can be seen. I can remove the 2nd commit or make a new PR to actually fix the changes later.

And then adding it to the grunt test task after all that's fixed? Maybe that should be a separate issue? Right now you can do grunt jscs though after an npm install.

@patrickkettner
Copy link
Member

@hzoo thank you so much for this!
Would you be able to rebase against master? A single commit for all of these changes would be best.

thanks again!

@@ -25,7 +25,7 @@ define(['Modernizr', 'createElement'], function( Modernizr, createElement ) {
try {
div.style.fontSize = '3rem';
}
catch( er ) {}
catch ( er ) {}
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a rule here to make it drop the whitespace inside the parenthesis too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure - I'm just using the google preset as a base/start so yeah feel free for more suggestions in rules to add/remove.

Copy link
Member

Choose a reason for hiding this comment

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

believe that would be "disallowSpacesInsideParentheses": true

Copy link
Member

Choose a reason for hiding this comment

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

looks like google aligns pretty closely with our own style. it generates the least amount of style changes from all of the presets (crockford is 7k haha).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I think I picked the one with the least errors (forgot)

Copy link
Member

Choose a reason for hiding this comment

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

Yep let's set that to true as we're pretty inconsistent on that front looking at the files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting.. I don't know why but I had nulled the disallowSpacesInsideParentheses rule in the PR haha.

Copy link
Member

Choose a reason for hiding this comment

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

while we are at it, requireCurlyBraces should be true as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok so with that if (elem === false) return props[i];

would be

if (elem === false) {
  return props[i];
}

Copy link
Member

Choose a reason for hiding this comment

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

correctamundo

@ryanseddon
Copy link
Member

Another thing we would want to add is a lint task that runs jshint & jscs much like the task in jQuery

@patrickkettner
Copy link
Member

@ryanseddon you mean something like grunt.registerTask('lint', ['jshint', 'jscs'])?

@patrickkettner
Copy link
Member

hah - didn't notice the link. agreed

@ryanseddon
Copy link
Member

Yes exactly like that and our test task just calls lint

@hzoo
Copy link
Contributor Author

hzoo commented Apr 23, 2015

grunt.registerTask('lint', ['jshint', 'jscs'])

Ok so in the current Gruntfile

grunt.registerTask('default', [ 'jshint', 'build' ]);

There's already the test and default tasks that run jshint. Should I change the references to run lint instead?

@patrickkettner
Copy link
Member

we would want to change that from jshint to lint, after creating the above mentioned lint task

@@ -49,6 +49,16 @@ module.exports = function( grunt ) {
]
}
},
jscs: {
src: [
'Gruntfile.js',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are the same a jshint - any changes needed?

Copy link
Member

Choose a reason for hiding this comment

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

should be good

@hzoo
Copy link
Contributor Author

hzoo commented Apr 23, 2015

Autofix is great! Changed the requireCurly's manually since autofix only does whitespace currently (so those shouldn't break anything). Ran gulp lint with no issues. Going to check tomorrow and update if there's any more issues/comments.

@patrickkettner
Copy link
Member

since this commit modified the Grunt file, saucelabs won't run. I am running them locally just to confirm (I can't imagine it would break anything, but weirder crap has come up previously). Once it goes green I am good to merge 👍

@@ -0,0 +1,9 @@
{
"preset": "google",
Copy link
Member

Choose a reason for hiding this comment

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

Can you make this 2 spaces to match other rc files

@patrickkettner
Copy link
Member

sall good.

great work, @hzoo!

patrickkettner added a commit that referenced this pull request Apr 23, 2015
@patrickkettner patrickkettner merged commit 3cad259 into Modernizr:master Apr 23, 2015
@patrickkettner
Copy link
Member

ugh, sorry @ryanseddon. I'll update real quick

@ryanseddon
Copy link
Member

no problem it's not a huge one

@hzoo
Copy link
Contributor Author

hzoo commented Apr 23, 2015

Cool! - I guess editorconfig didn't catch that since I must of copied another file with 4 spaces. There's also a validateIndentation rule although it seems to have some bugs - probably the most difficult rule jscs has.

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

Successfully merging this pull request may close these issues.

None yet

3 participants