-
Notifications
You must be signed in to change notification settings - Fork 555
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
Enforce specific style guide #951
Comments
Also I recently encountered an issue with a variable accidentally leaking into global namespace and corrupting a for loop in my code (this one case is fixed with fe26b9d). JSHint will with next release support implicit use of strict statements (see jshint/jshint#924), so we can add that and more optional features. |
Update jshint version. Enforce stricter jshint checks. Add missing Crafty references to source files. Fix leaks of vars into global namespace. fixes part of craftyjs#951.
Update jshint version. Enforce stricter jshint checks. Add missing Crafty references to source files. Fix leaks of vars into global namespace. fixes part of craftyjs#951.
Update jshint version. Enforce stricter jshint checks. Add missing Crafty references to source files. Fix leaks of vars into global namespace. fixes part of craftyjs#951.
Update jshint version. Enforce stricter jshint checks: * Add missing Crafty references to source files. * Fix leaks of vars into global namespace. * Removes unused vars. * Add more stricter checks * Switch to strict equality comparison. fixes part of craftyjs#951.
Update jshint version. Enforce stricter jshint checks: * Add missing Crafty references to source files. * Fix leaks of vars into global namespace. * Removes unused vars. * Add more stricter checks * Switch to strict equality comparison. fixes part of craftyjs#951.
JSHint's strictest opt-in options, what's currently enforced or the reason it isn't:
Footnote: |
I've heard good things about prettier, which will automatically maintain a standard format. It is more narrowly scoped (format only, e.g. it won't warn you of things like unused variables) and less configurable than linting tools, so it might be easier to start using with the existing code base. From their readme:
I might take a pass of seeing what happens when running it against crafty. |
The results seemed mostly reasonable, with some weirdness about docblock indenation. (Found a related issue in their repo, and it sounds like it is not the intended behavior.) Here's the result of running it against our src+tests directories. |
Sounds good. JSHint handles static analysis, this could compliment it well. In the long run it might be a problem that prettier doesn't offer many configuration option, but is very good due to automatic formatting. ESLint offers great config options, but can't format everything and will fail the build for every single indentation mishap. I'd suggest to tweak the options though. Imo let's try and see how something like this looks (source files are easier to read with 4 spaces indentation).
However, aside from doc blocks, it spits out monstrosities like this for example. (e: Or does this have to do with max line length?) If the effort to |
The particular monstrosity you mention is already pretty hard to read; it should probably be refactored to do less calculations in line. (e.g. |
Right, I think the way we'd want to use this is to add the git commit hook that autoformats on staging; that way the committed code is always formatted consistently. |
Recent efforts into improving our code style (e.g. #949) got me thinking. Why don't we enforce a specific code style and never worry about the code style being messed up by accident again?
There is a tool that does this exactly - JSCS. We can use a preset style guide, or customize our own according to a set of rules. There is also an accompanying grunt task.
This will probably require a lot of work in the start to fix all outstanding issues in our code, but once we overcome this initial hurdle, it should hopefully be worthwhile in the long run (since tests will fail unless style is accepted). Oh boy, it even supports automatic formatting (to some degree I guess) to match the code style we want!
We actually have a style guide we could enforce (and perhaps update it with more rules that make sense).
The text was updated successfully, but these errors were encountered: