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

Migrate the repo to ESLint #31777

Merged
merged 155 commits into from Sep 11, 2019
Merged

Conversation

a-tarasyuk
Copy link
Contributor

@a-tarasyuk a-tarasyuk commented Jun 5, 2019

Fixes #30553


  1. TSLint Rules from scripts/tslint are located here - scripts/eslint
    - TODO: no-increment-decrement -> no-plusplus (completely disallows ++, --, however, custom no-increment-decrement rule behaves differently. maybe better to implement no-increment-decrement as it was)
    I added debug information to no-increment-decrement, for both cases: case ts.SyntaxKind.PrefixUnaryExpression: and case ts.SyntaxKind.PostfixUnaryExpression:. and the result was empty.
    Does the TypeScript project not contain the code that will be processed by this rule? Is this rule still applied?
  2. TSLint Formatter autolinkableStylishFormatter - is located here - eslint-formatter-autolinkable-stylish

  1. TSLint rules which don't have alternatives in ESLint
  • align not used/disabled
  • import-spacing
  • no-reference-import - change to @typescript-eslint/triple-slash-reference
  • typedef not used/disabled
  • whitespace
  • prefer-conditional-expression not used/disabled

  1. TSLint rules which can be replaced by ESLint external plugins

cc @DanielRosenwasser

@typescript-bot
Copy link
Collaborator

Thanks for the PR! It looks like you've changed the TSServer protocol in some way. Please ensure that any changes here don't break consumers of the current TSServer API. For some extra review, we'll ping @sheetalkamat, @amcasey, @mjbvz, @minestarks for you. Feel free to loop in other consumers/maintainers if necessary

@amcasey
Copy link
Member

amcasey commented Jun 5, 2019

FYI @uniqueiniquity @jessetrinity

@uniqueiniquity
Copy link
Contributor

uniqueiniquity commented Jun 11, 2019

Hi @a-tarasyuk, thanks so much for taking this project on!
This PR represents a significant chunk of work that we've been meaning to do, but we haven't quite had the bandwidth to tackle yet.

In order to be able to review this PR, I think it's best to set out a couple guiding principles on what we value in this conversion:

  1. Using ESLint, we would like to run the same set of rules that are currently running in TSLint, on the same set of files.
  2. We would like there to be as minimal a set of changes to the code resulting from the conversion as possible.

In a perfect world, these principles would require there to be an exact equivalent in ESLint of every TSLint rule we run. However, as we found and you pointed out, this isn't exactly the case, and the number of changes in your PR certainly demonstrates this.

In order to make sure everyone's on the same page about these changes, I think the best plan will be to enable as many rules as possible that don't require code changes, and then for those that do, leave them commented out in the eslint config. We can then start a review thread rooted on that line to decide whether we want to make the necessary changes, fix the rule, or drop the rule entirely. I can do one to start off, since I know that the no-fallthrough ESLint rule handles comments differently than TSLint's no-switch-case-fallthrough. Ultimately, I just want to make sure there is full visibility into what's changing, why, and why it's necessary.

Regarding the set of rules and the formatter from scripts/tslint, I think the best plan is to keep them hosted in this repo just as before, in a scripts/eslint folder, for example; we can even use eslint-plugin-rulesdir so that they can just stay in a folder as before without the extra structure of their own plugin.

Furthermore, it's difficult for us to take on external dependencies for these because they're very specific to this particular repo, and we definitely do not want to give the impression that we are suggesting a particular style guide for TypeScript code (for an example of just how much we want to avoid that impression, see this page). I think the best course of action for the two packages you created is to deprecate them and move the code into this repo as mentioned above.

Please let me know if you have any questions about my recommendations.
Thanks again for working on this!

CC: @DanielRosenwasser @RyanCavanaugh

.eslintrc Outdated Show resolved Hide resolved
@a-tarasyuk
Copy link
Contributor Author

a-tarasyuk commented Jun 12, 2019

@uniqueiniquity Thanks for the feedback. 👍

Correct me if I'm wrong

  1. Need to revert all changes related to src/** / scripts/**
  2. Need to disable rules which behave differently than in TSLint and cause code changes
  3. Need to move eslint-plugin-microsoft-typescript/eslint-formatter-autolinkable-stylish to TypeScript repository

I think the best course of action for the two packages you created is to deprecate them and move the code into this repo as mentioned above.

Maybe that makes sense only for me and need to drop this public repository.

To port the script / tslint / rules need to understand what each rule does. For script / tslint / rules there are no tests/examples in order to understand cases which each rule has to handle. To cover as much as possible cases and make future maintaining more reliable, I added tests to each rule and it provided me the way to develop/test rules much easier and quicker. Also, there are rules, which does not make sense to publish to @typescript-eslint/eslint-plugin and TypeScript uses them, these rules related to some options in TSLint rules, for instance, variable-name has option ban-keywords - id-blacklist, id-match cannot handle that case - for that reason I created the rule no-keywords., etc. We can move only rules (without tests) to the scripts folder and then I'll think about the deprecation of this package.

About eslint-formatter-autolinkable-stylish, it just formatter, and I think it can be public as it is now. If you prefer to have it in TypeScript repo we can copy the code from it to the scripts folder.

@uniqueiniquity
Copy link
Contributor

@a-tarasyuk Sure thing!
Yes, your understanding is correct. I would add a number 4: For each disabled rule that caused code changes, start a discussion thread explaining the changes so we can decide what to do about it.

Regarding the ported rules from script/tslint/rules, I understand your point about needing tests. I'm not strictly against having them in a plugin now that we have tests for them. The concern that I have is more about having them published as a separate package, since users might assume that we're recommending that people use them.

The formatter might actually be ok as it is. I'll talk to some others on the team and decide what makes the most sense for that piece.

@a-tarasyuk
Copy link
Contributor Author

a-tarasyuk commented Jun 13, 2019

TODO:

  • Revert all changes related to src/** / scripts/**
  • Disable rules which behave differently than in TSLint and cause code changes
  • Move eslint-plugin-microsoft-typescript to TypeScript repository?
  • For each disabled rule that caused code changes, start a discussion thread explaining the changes
  • Update @typescript-eslint/* to the stable 2.0.0 version
  • Update @typescript-eslint/* to the stable 2.1.0 version

TODO:
NOTE: Some of these rules cause changes only in files related to scripts or have to be disabled in code (i.e. need to replace tslint-disable -> eslint-disable)

  • @typescript-eslint/semi
  • @typescript-eslint/no-this-alias
  • @typescript-eslint/no-inferrable-types
  • @typescript-eslint/prefer-interface
  • @typescript-eslint/type-annotation-spacing
  • @typescript-eslint/class-name-casing
  • @typescript-eslint/no-unnecessary-qualifier
  • @typescript-eslint/prefer-namespace-keyword
  • @typescript-eslint/adjacent-overload-signatures
  • @typescript-eslint/camelcase
  • @typescript-eslint/no-unnecessary-type-assertion
  • @typescript-eslint/unified-signatures
  • @typescript-eslint/prefer-function-type
  • @typescript-eslint/interface-name-prefix
  • indent
  • @typescript-eslint/indent
  • @typescript-eslint/triple-slash-reference
  • @typescript-eslint/array-type
  • @typescript-eslint/quotes

  • no-empty
  • no-restricted-globals
  • no-eval
  • space-in-parens
  • no-new-func
  • object-shorthand
  • dot-notation
  • brace-style
  • no-throw-literal
  • linebreak-style
  • no-trailing-spaces
  • no-template-curly-in-string
  • no-unused-expressions
  • prefer-const
  • no-var
  • no-fallthrough
  • no-redeclare
  • no-plusplus

  • microsoft-typescript/debug-assert
  • microsoft-typescript/boolean-trivia
  • microsoft-typescript/object-literal-surrounding-space
  • microsoft-typescript/type-operator-spacing
  • microsoft-typescript/no-double-space
  • microsoft-typescript/no-in-operator
  • microsoft-typescript/no-keywords
  • microsoft-typescript/only-arrow-functions
  • microsoft-typescript/simple-indent

  • import/no-extraneous-dependencies

  • no-null/no-null

  • jsdoc/check-alignment

Ignored folders

/built/local/**
/tests/**
/lib/**

tslint.json(`tslint.json` + `tslint:latest` + `built/local/tslint/rules`)
{
  "adjacent-overload-signatures": true,
  "align": false,
  "array-type": [
    true,
    "array"
  ],
  "arrow-parens": false,
  "arrow-return-shorthand": false,
  "ban-types": false,
  "callable-types": true,
  "class-name": true,
  "comment-format": [
    true,
    "check-space"
  ],
  "curly": [
    true,
    "ignore-same-line"
  ],
  "cyclomatic-complexity": false,
  "eofline": false,
  "forin": false,
  "import-spacing": true,
  "indent": [
    true,
    "spaces"
  ],
  "interface-name": [
    true,
    "never-prefix"
  ],
  "interface-over-type-literal": true,
  "jsdoc-format": true,
  "label-position": true,
  "max-classes-per-file": false,
  "max-line-length": false,
  "member-access": false,
  "member-ordering": false,
  "new-parens": true,
  "no-angle-bracket-type-assertion": false,
  "no-any": false,
  "no-arg": true,
  "no-bitwise": false,
  "no-conditional-assignment": false,
  "no-consecutive-blank-lines": false,
  "no-console": false,
  "no-construct": true,
  "no-debugger": false,
  "no-duplicate-super": true,
  "no-empty": true,
  "no-empty-interface": false,
  "no-eval": true,
  "no-internal-module": true,
  "no-invalid-this": false,
  "no-misused-new": true,
  "no-namespace": false,
  "no-parameter-properties": false,
  "no-reference": false,
  "no-reference-import": true,
  "no-shadowed-variable": false,
  "no-string-literal": true,
  "no-string-throw": true,
  "no-switch-case-fall-through": true,
  "no-trailing-whitespace": [
    true,
    "ignore-template-strings"
  ],
  "no-unnecessary-initializer": true,
  "no-unsafe-finally": true,
  "no-unused-expression": true,
  "no-use-before-declare": false,
  "no-var-keyword": true,
  "no-var-requires": false,
  "object-literal-key-quotes": [
    true,
    "consistent-as-needed"
  ],
  "object-literal-shorthand": true,
  "object-literal-sort-keys": false,
  "one-line": [
    true,
    "check-open-brace",
    "check-whitespace"
  ],
  "one-variable-per-declaration": false,
  "only-arrow-functions": {
    "options": [
      "allow-declarations",
      "allow-named-functions"
    ]
  },
  "ordered-imports": false,
  "prefer-const": true,
  "prefer-for-of": true,
  "quotemark": [
    true,
    "double",
    "avoid-escape"
  ],
  "radix": false,
  "semicolon": [
    true,
    "always",
    "ignore-bound-class-methods"
  ],
  "space-before-function-paren": false,
  "trailing-comma": false,
  "triple-equals": true,
  "typedef": false,
  "typedef-whitespace": [
    true,
    {
      "call-signature": "nospace",
      "index-signature": "nospace",
      "parameter": "nospace",
      "property-declaration": "nospace",
      "variable-declaration": "nospace"
    },
    {
      "call-signature": "onespace",
      "index-signature": "onespace",
      "parameter": "onespace",
      "property-declaration": "onespace",
      "variable-declaration": "onespace"
    }
  ],
  "typeof-compare": false,
  "unified-signatures": true,
  "use-isnan": true,
  "variable-name": [
    true,
    "ban-keywords",
    "check-format",
    "allow-leading-underscore"
  ],
  "whitespace": [
    true,
    "check-branch",
    "check-decl",
    "check-operator",
    "check-module",
    "check-separator",
    "check-type"
  ],
  "no-invalid-template-strings": true,
  "no-sparse-arrays": true,
  "no-object-literal-type-assertion": false,
  "prefer-conditional-expression": false,
  "prefer-object-spread": true,
  "no-duplicate-variable": {
    "options": "check-parameters"
  },
  "no-this-assignment": true,
  "no-duplicate-imports": true,
  "space-within-parens": true,
  "no-submodule-imports": false,
  "ban-comma-operator": false,
  "no-duplicate-switch-case": true,
  "no-implicit-dependencies": [
    true,
    "dev"
  ],
  "no-return-await": true,
  "function-constructor": true,
  "unnecessary-bind": true,
  "no-unnecessary-type-assertion": true,
  "ban": [
    true,
    "setInterval",
    "setTimeout"
  ],
  "linebreak-style": [
    true,
    "CRLF"
  ],
  "next-line": [
    true,
    "check-catch",
    "check-else"
  ],
  "no-bom": true,
  "no-increment-decrement": true,
  "no-inferrable-types": true,
  "no-null-keyword": true,
  "no-unnecessary-qualifier": true,

  "boolean-trivia": true,
  "debug-assert": true,
  "no-double-space": true,
  "no-in-operator": true,
  "no-type-assertion-whitespace": true,
  "object-literal-surrounding-space": true,
  "type-operator-spacing": true
}

@a-tarasyuk a-tarasyuk changed the title WIP: Migrate the repo to ESLint Migrate the repo to ESLint Sep 2, 2019
Copy link
Contributor

@uniqueiniquity uniqueiniquity left a comment

Choose a reason for hiding this comment

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

I think it's ready!

@uniqueiniquity uniqueiniquity merged commit d7c83f0 into microsoft:master Sep 11, 2019
@a-tarasyuk a-tarasyuk deleted the feature/eslint branch September 11, 2019 06:53
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.

Migrate the repo to ESLint
10 participants