-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
f0335e9
to
8ae1074
Compare
See #1851 |
d9938bf
to
c0f474f
Compare
Yay! Switching from tslint to eslint was on my personal todo list too. Let me post my notes before I review the changes:
|
There was a problem hiding this 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".
.vscode/settings.json
Outdated
@@ -24,6 +24,15 @@ | |||
"files.insertFinalNewline": true, | |||
"files.trimTrailingWhitespace": true, | |||
"tslint.ignoreDefinitionFiles": true, |
There was a problem hiding this comment.
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?
node: true, | ||
}, | ||
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'], | ||
rules: { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1.
There was a problem hiding this comment.
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/http-caching-proxy/src/__tests__/integration/http-caching-proxy.integration.ts
Outdated
Show resolved
Hide resolved
packages/eslint-config/.eslintrc.js
Outdated
'comma-dangle': ['error', 'always-multiline'], | ||
'no-mixed-operators': 'error', | ||
'no-console': 'off', | ||
'no-undef': 'off', |
There was a problem hiding this comment.
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?
packages/eslint-config/.eslintrc.js
Outdated
'no-mixed-operators': 'error', | ||
'no-console': 'off', | ||
'no-undef': 'off', | ||
'no-inner-declarations': 'off', |
There was a problem hiding this comment.
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?
packages/eslint-config/.eslintrc.js
Outdated
'no-inner-declarations': 'off', | ||
// TypeScript allows method overloading | ||
'no-dupe-class-members': 'off', | ||
'no-useless-escape': 'off', |
There was a problem hiding this comment.
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?
packages/eslint-config/.eslintrc.js
Outdated
'@typescript-eslint/no-parameter-properties': 'off', | ||
'@typescript-eslint/no-angle-bracket-type-assertion': 'off', | ||
'@typescript-eslint/prefer-interface': 'off', | ||
'@typescript-eslint/no-namespace': 'off', |
There was a problem hiding this comment.
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.
@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 |
db71f7f
to
bde28a4
Compare
There was a problem hiding this 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", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
examples/todo-list/src/__tests__/unit/controllers/todo-list-todo.controller.unit.ts
Show resolved
Hide resolved
packages/booter-lb3app/fixtures/lb3app/common/models/coffee-shop.js
Outdated
Show resolved
Hide resolved
* } | ||
* ``` | ||
*/ | ||
varsIgnorePattern: 'inject|(\\w+)Bindings', |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
{encodeValuesOnly: true}, | ||
); | ||
url += `?${q}`; | ||
{ |
There was a problem hiding this comment.
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?
There was a problem hiding this 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 due to https://eslint.org/docs/rules/no-case-declarations
@raymondfeng Travis CI build is failing for https://travis-ci.org/strongloop/loopback-next/jobs/539476548
|
8fa0671
to
cffd4f8
Compare
Fixed. |
152cbe0
to
91db407
Compare
There was a problem hiding this 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.
See some background at:
Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated