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

feat(@angular/cli): extend tslnit config from recommended #6507

Conversation

ValeryVS
Copy link
Contributor

no need to duplicate rules
new rules can be applied without updating, when new tslint is used

Fixes: #6179

@ValeryVS
Copy link
Contributor Author

polifills.ts edited with jsdoc-format
https://palantir.github.io/tslint/rules/jsdoc-format/

Tests files edited with arrow-parens
https://palantir.github.io/tslint/rules/arrow-parens/

@ValeryVS
Copy link
Contributor Author

Probably, some blueprints must be edited too.I will check this tomorrow. For now app generates without lint errors.

We can minimise blueprint changes and disable some rules.
And apply them in other PRs.

@clydin
Copy link
Member

clydin commented May 30, 2017

From the linked issue it looks like @cexbrayat was also working on this.
Also, the changes should ideally replicate the existing ruleset (i.e., no file changes should be necessary).

@ValeryVS ValeryVS force-pushed the feat/tslint-extend-recommended-config branch from b370d8d to c770e77 Compare May 30, 2017 20:31
@ValeryVS
Copy link
Contributor Author

ValeryVS commented May 30, 2017

@clydin

Also, the changes should ideally replicate the existing ruleset

Some rules just hasn't been used yet.
I don't think, that we should extend recommended config and disable a lot of rules from it.
But we can add support for these new rules in another PR.

@cexbrayat
Copy link
Member

I was indeed working on something similar but I didn't find the time to test my PR properly to see if the ruleset was identical. I also thought like @clydin that ideally the PR should require no changes as a first step, and wanted to offer several alternatives for the new rules and the ones where the CLI differs from the recommended config. But your PR @ValeryVS is maybe a good first step to start a discussion with the maintainers, so thank you for submitting this 👍

@ValeryVS
Copy link
Contributor Author

@clydin @cexbrayat
Summary, there are three options.

  1. Make changes in templates code to support new rules.
  2. Disable rules, that forces us to make changes in cli templates. Users, mostly, will be forced to make changes in their code if they want update tslint.json with new one. But, anyway, cli have not command to automatically update files.
  3. Disable all rules, that wasn't used in old config.

@ValeryVS
Copy link
Contributor Author

If we choose "Disable all rules, that wasn't used in old config", we should make another request with new rules support anyway.
If we just disable rules, users can think: "angular team doesn't recommend these rules".

@filipesilva Which way from comment above you prefer?

@ValeryVS
Copy link
Contributor Author

@cexbrayat
I compare config with recommended
https://github.com/palantir/tslint/blob/master/src/configs/recommended.ts
and remove all matched.
If we want to go third way, then we should disable all rules, that weren't in config now.

@ValeryVS ValeryVS force-pushed the feat/tslint-extend-recommended-config branch from c770e77 to ab17c80 Compare May 31, 2017 08:04
Copy link
Contributor

@filipesilva filipesilva left a comment

Choose a reason for hiding this comment

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

Heya @ValeryVS, good work matching these all. There just one rule that I think we should modify:

        "no-consecutive-blank-lines": [
            true,
            2
        ],

It would get rid of some of the changes needed in polyfills, and overall it's quite common to leave two empty lines as separators (we do it a lot on the CLI).

Other than that, LGTM.

@filipesilva filipesilva self-assigned this Jun 1, 2017
@cexbrayat
Copy link
Member

I tried the new config quickly on an existing project, and it raises a lot of warnings due to arrow-parens which is false in tslint:recommended and array-type which forces to use simple array for simple types and generic arrays for type T. These two rules were not enforced previously.

I don't know if this is a good or bad thing, I just wanted to point it out. Other than that, it's really close to what I had in my WIP PR for this 👍

@clydin
Copy link
Member

clydin commented Jun 1, 2017

Personally, I really don't think arrow-parens should be a recommended rule.
I think something to also keep in mind is that the recommended rule set is tslint's opinion on what should be recommended and opinions tend to vary. As an example, TypeScript itself doesn't use the rule set: https://github.com/Microsoft/TypeScript/blob/master/tslint.json

@ValeryVS ValeryVS force-pushed the feat/tslint-extend-recommended-config branch from ab17c80 to d14c312 Compare June 2, 2017 10:10
@ValeryVS
Copy link
Contributor Author

ValeryVS commented Jun 2, 2017

@filipesilva
Good point about no-consecutive-blank-lines. Changed.
There was three lines in polyfills.ts, so some changes are still there.


Also adjust no-trailing-whitespace rule. Using typescript repo as reference.

    "no-trailing-whitespace": [
      true,
      "ignore-template-strings"
    ],

@cexbrayat
I'm too must make some changes to support array-type, but it is useful

export interface Entity {
  users: {
    id: number;
    name: string;
    photo: string;
    birthDate: string;
  }[]; // <-- Pst... I'm array. Don't tell any one!
}

@clydin
arrow-parens is true in latest tslint:recommended
There are some argues about arrow-parens in eslint and tslint. ESLint has explanation:

if (a => 2) {
  return true;
}

This usage case is madness, but somtmies I swap lettres when tpying fast. So, it make sense.
http://eslint.org/docs/rules/arrow-parens

Anyway, the final word is for consumers. I, personally, add few more strict rules to this config for my projects.


I want to add semicolon rule, but, probably in second PR. I think in will require some changes in templates.

"semicolon": [true, "always", "ignore-bound-class-methods"]

We can discuss what else we could enable or disable in followup requests.

@ValeryVS ValeryVS force-pushed the feat/tslint-extend-recommended-config branch 3 times, most recently from 3d9e5cc to d698b1c Compare June 2, 2017 12:42
@@ -30,7 +30,6 @@ function check(val: any, fxState: any) {
fxState.num = val + "";
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was fail Exceeds the 2 allowed consecutive blank lines which not fixed with lint --fix command.
We can change no-consecutive-blank-lines to 3, if we want to avoid this change.

@@ -29,7 +29,6 @@ function check(val: any, fxState: any) {
fxState.num = val + "";
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was fail Exceeds the 2 allowed consecutive blank lines which not fixed with lint --fix command.
We can change no-consecutive-blank-lines to 3, if we want to avoid this change.

@clydin
Copy link
Member

clydin commented Jun 2, 2017

The arrow-parens rule doesn't actually address the underlying issue with your example. The example conditional is just always true. The presence or lack of parenthesis wouldn't change that. The rule warning might cause the developer to re-examine the statement but the quick fix is to add parenthesis (which gives a false sense of correctness and bad information as to the actual problem). Also anyone using a lint with auto-fix setup (pre-commit hook, CI, etc.) would still have the underlying error of an always true conditional.
The arrow-parens rule is really a stylistic rule. To catch and handle the situation in the above example, strict-boolean-expressions is the appropriate rule to enable. It actually warns the user as to the actual problem. It is TS only and is best used in combination with strict null checks.

@clydin
Copy link
Member

clydin commented Jun 2, 2017

Also, the fact that there is debate here regarding various rules essentially proves my earlier point that even a recommended rule set is highly opinionated.

My overall view for the default rule set for the CLI is that it should encourage best practices especially in regards to the use of Angular but should not be overtly strict in general and especially in the realm of stylistic concerns. Ideally new users of the CLI shouldn't be turned off to the tool because their preferred code style immediately results in numerous errors.

With that said, I think a strict option for ng new could be interesting. This could enable a more opinionated tslint ruleset as well as some of TypeScript's addition settings (strictNullChecks, etc.).

@ValeryVS ValeryVS force-pushed the feat/tslint-extend-recommended-config branch from d698b1c to a0b477f Compare June 8, 2017 06:41
@filipesilva
Copy link
Contributor

Imho arrow-parens makes sense to have turned on in TS projects because of typings, since you can't do add them without the parenthesis (a: bool => {} does not work).

This, together with #6568 makes me think linting config in general needs to be reviewed... I'll try to bring this up and get it sorted one way or another.

Meanwhile, @ValeryVS can you rebase please? It's failing on stuff unrelated to your PR.

no need to duplicate rules
new rules can be applied without updating, when new tslint is used

Fixes: angular#6179
@ValeryVS ValeryVS force-pushed the feat/tslint-extend-recommended-config branch from a0b477f to a4aeca7 Compare July 26, 2017 09:58
@ValeryVS
Copy link
Contributor Author

@filipesilva
PR is rebased. Sorry for delay.

@filipesilva
Copy link
Contributor

Heya @ValeryVS, wanted to give you an update. I escalated this up so that we come up with a better set of defaults instead of just trying to keep the current ones up to date.

The current set of defaults was based on something we used in the Angular.io examples a long time ago. Meanwhile a lot of changes have been introduced to tslint and codelyzer, including defaults.

We might end up making an angular default, from which projects would extend. I'm monitoring progress on this but have no estimate currently. Because of that I marked this as blocked.

@rafaelss95
Copy link

@filipesilva What's the status on this PR?

@hansl
Copy link
Contributor

hansl commented Feb 22, 2018

Closing this; it changes blueprints which we don't support anymore. Please submit a PR on devkit if you want us to consider this.

@hansl hansl closed this Feb 22, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[lint] tslint.json could extend tslint:recommended
7 participants