-
Notifications
You must be signed in to change notification settings - Fork 14
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 format and format-verify tasks to grunt #994
Conversation
This is a first stab at addressing phetsims/phet-info#150 |
Assigning to @ariel-phet to prioritize and assign. |
5992a1b
to
f0f6877
Compare
`grunt format` now runs js-beautify and sortImports on all js files in a given repo (or the current one if none is given). In addition, you can use `grunt format --verify` to just check that the files are formatted, but not actually modify them. This could be useful for a pre-commit hook. The `grunt format-all` variation is similar to lint-all in that it runs format on all the repos that are libraries of the supplied repo.
f0f6877
to
117f08e
Compare
Updated so you can run format and format-all as grunt tasks from any repo. After testing on a couple repos (twixt and energy-forms-and-changes) there were a couple differences. Indentation, import ordering (that comes from your existing grunt task sortImports though...), newlines were changed. I didn't actually like the end result, but it's palatable. Some tweaking still probably possible. This also only does .js files, but presumably you may want something for all file types. Possibly unibeautify would be useful? |
FYI... Merging this pull request in 6887eb5 introduced a new dependency on js-beautify (in format.js). This broke tasks like This is the kind of breaking change that should probably be announced on the Google Group, but I haven't done that. |
Sorry about that @pixelzoom! I will fix this while we are experimenting, and only add a dependency if we go down this road. |
Hey, thanks @zepumph for keeping the momentum going! This looks great. I'll add a few comments in phetsims/phet-info#150. One thing though, is I notice that |
It might be worth discussing again, because I don't recall the discussion. But turning off package-lock.json was a conscious decision by PhET. And it's an explicit step in the "Getting Started" sections of the PhET Development Overview:
|
This adds two grunt tasks, format and format-verify. The first reformats files for you, and the second just checks that files are formatted, eg for pre-commit hooks.
The
src
attribute, where the beautifuer looks for files, is wrong of course, but this is helpful for testing within the chipper repo. I still need to figure out how to make it so you can call this from any repo, since at this point when I do that I get an error becauseLocal Npm module "grunt-jsbeautifier" not found
. Do I need to add this to every repo's package.json? Somehow I doubt it, since those look really clean at this point...This uses the .jsbeautifyrc file from https://github.com/phetsims/phet-info/blob/master/ide/sublime-text/.jsbeautifyrc, so this should follow the PHET conventions.