-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 lint checks for common coding issues arising in code reviews. #3905
Comments
Here is a start to the design doc, I'm not sure on the formatting/what it should have. https://docs.google.com/document/d/18VHyxIfvts5LycKOwLU6-fDT0aRx30XEl1ErafdvD18/edit?usp=sharing |
Thanks @Oishikatta! I left some feedback in the doc. |
Howdy @Oishikatta Any progress on this? |
@Oishikatta how is this going? |
Deassigning @Oishikatta due to lack of response. |
Also adding notes from @Oishikatta's doc to the issue thread, for easy reference in the future: Javascript Currently in use: eslint 3.18.0. This version is behind the current (4.x) by one major release, but uses the same rule format. Rules written for this version will not require changes if updated to 4.x in the future. Plugins already exist to cover some of the issues: https://www.npmjs.com/package/eslint-plugin-angular -- but may require eslint 4.x. It is possible to pick out specific rules and use them with the 3.x version. Suggestion: eslint appears suitably extendable with rules/plugins that it can meet the requirements. Enable built-in rules, retrieve some from open source packages, and write others. Specific issues:
Python Currently in use: pylint. Supports adding AST and raw/stream based checkers. Suggestion: Enable relevant built-in pylint checkers, and write others. Specific issues:
For both file types: |
@seanlip can I go ahead and implement custom lint checks in pre_commit_linter or does this still need for looking online available options? |
I think some of these can be solved with online available options, and some can be solved by adding custom lint checks. I'd recommend handling the former before the latter, since that might save work (e.g. adding a single line to the eslint config is better than writing a new function in the pre_commit_linter.py file). |
Hello @seanlip! I am willing to work on this issue. Can you please tell me how should I go about this? |
Hi @apb7! The instructions given above should be clear, so please follow them. Feel free to take just one of the checkboxes for your first PR. In general, here's what to do: In general I would advise picking an issue that's simple to solve for your first PR here -- it may be adding a new rule in .eslintrc or pylint, or doing some customization of an existing rule. But if you can't do that then you may need to write some kind of function that checks for these things manually. There are some examples of that in the linter script. The less code you write, the better, though. |
Hello @seanlip! For checking alphabetized imports in Python, we can use flake-8-import-order. This package will add 4 new flake8 warnings. |
@seanlip: For 'checking alphabetized imports' in Python, instead of |
isort seems reasonable to me. Could you please submit a PR? Note that, by default, it shouldn't automatically mutate the code; it should just flag the errors when being run in the linter script. (Although it's fine if you want to use the auto-fix option to clean up existing code.) Thanks! |
@seanlip: |
|
Yes, got it. Thanks! |
Hi @seanlip, I have implemented the scope check using |
Modify them to have a scope (and make sure that everything still works!).
|
Okay, understood. Thanks! |
@seanlip: For directives not having any scope, I'm adding |
By default all scopes should be One thing to be careful about is that this might break scope inheritance, in which case we'll need to find some sort of workaround. In some cases that might be simple and in other cases that might be harder, so it may be worth sorting out the easy ones first and leaving the harder ones for further discussion or a separate PR. |
@seanlip: If any directive does not have an explicitly defined scope, then it is equivalent to |
Actually, what I want to introduce is an explicit isolate scope for all directives, rather than allowing them to inherit parent scope. Hence the default of Initial PR sounds good, thanks! |
Hi @WickedBrat, I think @apb7 is working on it (As mentioned here #4592), if so then maybe you can take up another part of this issue else you can start working on this :). |
@WickedBrat, I think apurv is working on "directives should have explicit isolated scope" so yeah you can work on "All directives should ave |
Hi @WickedBrat! You can go ahead with it. I've picked up scope checks for now. Also, I suggest you go through the review comments in PR #4592 once. It would surely help! |
Hi @WickedBrat, please go through these comments in the above issue thread. Also, you don't need to write any check in pre-commit linter. You have to enable the directive-restrict rule in eslint-plugin-angular. Another important thing is to change the HTML attributes of the directives to elements in the HTML files where these directives are being used. This needs to be done without breaking any test (Also, test this manually as well). You can refer to PR #4592 and PR #4734 for the procedure. Thanks! |
* Basic parsing * Integrate directive check * Add directive name to msg * Comment out directive scope messages * Remove nesting * Lint fixes * Fix lint errors * Add explanatory comments * Remove trailing space * Review changes(1) * Review changes(2) * Review changes(3) * Disable check
…dependencies and controller function parameters (#5225) * Add check and fix problems * Change in messages
This issue has been broken down into smaller sub-issues for the remaining parts. Therefore closing this. Thanks! |
In code reviews, I've noticed a lot of the same style issues come up over and over again, and in order to conserve reviewer time and give contributors faster feedback, these issues should really be addressed by pre-review lint checks. Adding these will also help maintain consistency in our codebase, and ensure that this state of affairs continues to be preserved in the future.
We can handle some of these issues by importing third-party libraries (such as pycodestyle) that might already have support for these checks, but it might also be a good idea to have a framework for adding additional custom lint checks that are specific to our codebase and aren't easily handled by third-party libraries.
For reference, here is a partial list of the issues I've observed. Note to contributors: it is absolutely fine to submit a PR that gets rid of just one or two of these. Note that the corresponding lint errors will need to be fixed before the PR goes in; this should be a good test of the checker that you've implemented.
JavaScript
Missing semicolons at end of lines (@apb7 in Fix part of #3905: Added semi-rule #4576)
Use of ‘==’ rather than ‘===’ -- @apb7 in Fix part of #3905: Added eqeqeq rule #4573
Spurious console.log() statements (@apb7 in Fix part of #3905: Add check for console.log statement #4564)
Directives should have an explicit
scope
key and it should not bescope: true
since this leads to hard-to-maintain direct-from-parent imports -- @apb7All directives should have
restrict: 'E'
There should be exactly one directive or service per file.
For function args within parens, indent follow-on lines by 2 additional spaces, e.g.: (@apb7 in Fix part of #3905: Indent follow-on lines for FunctionExpression #4588)
Always use
templateUrl
instead oftemplate
(@ishucr7)Align line breaks of angular dependencies with those in the stringified list just below them, and check that the dependencies match exactly
Unused Angular dependencies injected into a controller (eslint doesn't catch this if the dependencies are in the middle of the argument list, but there are plugins like this one which have rules for catching this sort of thing). -- @pandeykartikey Fix part of #3905: Removes unused angular dependecies injected into controllers #4792
If something within parens extends across multiple lines, break after the opening '('. -- @apb7
Check keyword spacing (e.g. between "for" and the next open paren) -- @apb7 in Add check for keyword spacing in JS files #4697
Check for trailing whitespaces. -- @apb7 in Add check for trailing whitespaces #4699
Line breaks here should match up with the line breaks in the stringified dependencies. (See @apb7 in PR Create Topic Editor (Part 4): Added more functions to edit topics #5119)
Check for
browser.waitForAngular()
Python
"""
in single line docstrings.HTML
The text was updated successfully, but these errors were encountered: