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: introduce eslint with typescript-eslint to replace tslint #2492

Merged
merged 4 commits into from Jun 3, 2019

Conversation

raymondfeng
Copy link
Contributor

@raymondfeng raymondfeng commented Feb 26, 2019

See some background at:

Checklist

👉 Read and sign the CLA (Contributor License Agreement) 👈

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

@raymondfeng raymondfeng changed the title feat: support typescript-eslint to replace tslint [RFC] feat: support typescript-eslint to replace tslint Feb 26, 2019
@raymondfeng
Copy link
Contributor Author

See #1851

@raymondfeng raymondfeng marked this pull request as ready for review February 27, 2019 16:36
@raymondfeng raymondfeng changed the title [RFC] feat: support typescript-eslint to replace tslint [RFC] feat: introduce eslint with typescript-eslint to replace tslint Feb 27, 2019
@bajtos
Copy link
Member

bajtos commented Mar 1, 2019

Yay! Switching from tslint to eslint was on my personal todo list too.

Let me post my notes before I review the changes:

  • port linting to use renamed TS parser desktop/desktop#6684 is an example from a different project that has recently switched from tslint to eslint
  • can we use --cache option to speed up linting?
  • there are two eslint plugins to improve integration with prettier: eslint-plugin-prettier checks formatting and reports violations, eslint-config-prettier disables any eslint rules that may clash with prettier. Personally, prefer to include prettier linting in eslint run, because standalone prettier is rather slow and AFAIK it does not offer any options to cache the results (yet).
  • If we move prettier checks to eslint, we must still preserve Prettier checks for our Markdown documents! This utility may be useful: https://github.com/ikatyang/prettylint

@bajtos bajtos added refactor Internal Tooling Issues related to our tooling and monorepo infrastructore labels Mar 1, 2019
Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

My main concern is about preserving as much of the current tslint config as possible, and not enabling any additional rules now. This pull request is large enough, it's better to not make it even larger by adding extra eslint directives like "disable ban-types".

@@ -24,6 +24,15 @@
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"tslint.ignoreDefinitionFiles": true,
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove this tslint config too?

examples/hello-world/package.json Outdated Show resolved Hide resolved
packages/cli/generators/openapi/spec-helper.js Outdated Show resolved Hide resolved
node: true,
},
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
rules: {
Copy link
Member

Choose a reason for hiding this comment

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

Please don't duplicate the content of @loopback/eslint-config here, it will quickly get out of sync.

IMO, we should always extend from @loopback/eslint-config, it's a shared config that's can be used independently from @loopback/build.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1.

Copy link
Member

Choose a reason for hiding this comment

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

Please don't duplicate the content of @loopback/eslint-config here, it will quickly get out of sync.

IMO, we should always extend from @loopback/eslint-config, it's a shared config that's can be used independently from @loopback/build.

☝️ This is not addressed yet AFAICT.

packages/eslint-config/index.js Outdated Show resolved Hide resolved
packages/eslint-config/.eslintrc.js Outdated Show resolved Hide resolved
packages/metadata/src/inspector.ts Outdated Show resolved Hide resolved
packages/metadata/src/decorator-factory.ts Outdated Show resolved Hide resolved
packages/eslint-config/.eslintrc.js Outdated Show resolved Hide resolved
benchmark/src/__tests__/benchmark.integration.ts Outdated Show resolved Hide resolved
packages/context/src/binding.ts Outdated Show resolved Hide resolved
packages/context/src/binding-key.ts Outdated Show resolved Hide resolved
packages/context/src/context.ts Outdated Show resolved Hide resolved
packages/context/src/inject.ts Outdated Show resolved Hide resolved
'comma-dangle': ['error', 'always-multiline'],
'no-mixed-operators': 'error',
'no-console': 'off',
'no-undef': 'off',
Copy link
Member

Choose a reason for hiding this comment

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

What is this rule about and why are we turning it off, against the recommendations?

'no-mixed-operators': 'error',
'no-console': 'off',
'no-undef': 'off',
'no-inner-declarations': 'off',
Copy link
Member

Choose a reason for hiding this comment

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

What is this rule about and why are we turning it off, against the recommendations?

'no-inner-declarations': 'off',
// TypeScript allows method overloading
'no-dupe-class-members': 'off',
'no-useless-escape': 'off',
Copy link
Member

Choose a reason for hiding this comment

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

What is this rule about and why are we turning it off, against the recommendations?

'@typescript-eslint/no-parameter-properties': 'off',
'@typescript-eslint/no-angle-bracket-type-assertion': 'off',
'@typescript-eslint/prefer-interface': 'off',
'@typescript-eslint/no-namespace': 'off',
Copy link
Member

Choose a reason for hiding this comment

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

I see a bunch of rules that we are disabling against the recommendations. What is your reasoning for disabling them? Also why is ban-types treated differently from these rules? Is it because fixing ban-types violations is easier than fixing violations of these other rules? That seems to be a poor excuse to me.

IMO, we should add ban-type to the list of disabled rules to keep this PR smaller and then incrementally try to enable most of the recommended rules, one by one. Starting with ban-types if you like.

packages/eslint-config/.eslintrc.js Outdated Show resolved Hide resolved
@bajtos
Copy link
Member

bajtos commented Mar 8, 2019

@raymondfeng I would love to see this pull request landed soon, but unfortunately it seems to make too many changes that are very loosely related (if related at all). Can you find a way how to reduce the size of this patch so that we can land it sooner?

I like the idea of inheriting all recommended rules. For this first iteration, I prefer to disable any of these recommendations that we are not already complying with, to avoid large code changes and/or adding /* eslint-disable */ statements that we probably should want to remove in the near future anyways.

@raymondfeng
Copy link
Contributor Author

@bajtos Let's start with #2572.

@raymondfeng raymondfeng force-pushed the eslint branch 4 times, most recently from db71f7f to bde28a4 Compare May 31, 2019 00:23
Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

I am looking forward to see this change landed 🕺

Please address my comments below.

EDIT: Some of the comments are collapsed by GitHub, please make sure to review them all!

"eslint.validate": [
"javascript",
{
"language": "typescript",
Copy link
Member

Choose a reason for hiding this comment

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

I find this suspicious. Could you please explain what does it mean to validate javascript files using typescript language?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint. The setting is an array. It basically says javascript is validated and typescript is validated and auto-fixed.

Copy link
Member

Choose a reason for hiding this comment

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

Fair enough. Can you capture this in a code comment please? I believe settings.json allow comments.

packages/build/test/integration/scripts.integration.js Outdated Show resolved Hide resolved
packages/cli/generators/model/index.js Outdated Show resolved Hide resolved
* }
* ```
*/
varsIgnorePattern: 'inject|(\\w+)Bindings',
Copy link
Member

Choose a reason for hiding this comment

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

I understand why we are ignoring inject, but why (\\w+)Bindings? Should we ignore config too?

Is there a way how to ensure inject is ignored only when it's @inject, but not when it's a variable name like injectFooBar?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use @inject(RestBindings.Http.REQUEST). Both @inject and RestBindings are treated as no-used due to typescript-eslint/typescript-eslint#571.

packages/eslint-config/package.json Outdated Show resolved Hide resolved
{encodeValuesOnly: true},
);
url += `?${q}`;
{
Copy link
Member

Choose a reason for hiding this comment

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

Weird, why are we wrapping this code in a {} block?

Can you find a different solution please, one that will require less code changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

packages/rest/src/types.ts Show resolved Hide resolved
packages/testlab/should-as-function.d.ts Outdated Show resolved Hide resolved
@bajtos
Copy link
Member

bajtos commented May 31, 2019

@raymondfeng Travis CI build is failing for verify-docs step, PTAL.

https://travis-ci.org/strongloop/loopback-next/jobs/539476548

lerna bootstrap --scope @loopback/tsdocs
lerna notice cli v3.14.1
lerna info versioning independent
lerna info ci enabled
lerna notice filter including "@loopback/tsdocs"
lerna info filter [ '@loopback/tsdocs' ]
lerna WARN bootstrap Installing local packages that do not match filters from registry
lerna info Bootstrapping 1 package
lerna info Installing external dependencies
lerna ERR! npm install --no-save exited 1 in '@loopback/tsdocs'
lerna ERR! npm install --no-save stderr:
npm WARN deprecated @types/handlebars@4.1.0: This is a stub types definition. 
    handlebars provides its own type definitions, so you do not need this installed.
npm ERR! code ETARGET
npm ERR! notarget No matching version found for @loopback/eslint-config@^1.0.0
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! notarget 
npm ERR! notarget It was specified as a dependency of '@loopback/tsdocs'
npm ERR! notarget 

@raymondfeng raymondfeng force-pushed the eslint branch 2 times, most recently from 8fa0671 to cffd4f8 Compare May 31, 2019 16:04
@raymondfeng
Copy link
Contributor Author

Please don't duplicate the content of @loopback/eslint-config here, it will quickly get out of sync.
IMO, we should always extend from @loopback/eslint-config, it's a shared config that's can be used independently from @loopback/build.

Fixed.

@raymondfeng raymondfeng force-pushed the eslint branch 11 times, most recently from 152cbe0 to 91db407 Compare June 1, 2019 04:42
Copy link
Member

@bajtos bajtos left a comment

Choose a reason for hiding this comment

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

I don't have time to review the patch in all details again and unfortunately I don't see any easy way how to review only the changes made since my last review :(

I'll trust you that you have addressed all my comments well.

FWIW, LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Internal Tooling Issues related to our tooling and monorepo infrastructore refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants