8000 Upgrade TSLint to ESLint, rename package tslint -> lint by ryanio · Pull Request #26 · ethereumjs/ethereumjs-config · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Oct 30, 2024. It is now read-only.

Upgrade TSLint to ESLint, rename package tslint -> lint #26

Merged
merged 12 commits into from
Aug 25, 2020

Conversation

ryanio
Copy link
Contributor
@ryanio ryanio commented Feb 17, 2020

TSLint is now deprecated in favor of ESLint.

This PR is a breaking change, and does the following:

How repos using this package should update

Once published in npm, update in package.json:

-    "@ethereumjs/config-tslint": "^1.1.1",
+    "@ethereumjs/config-lint": "^2.0.0",

Add .eslintrc.js with:

module.exports = {
  parserOptions: {
    project: './tsconfig.json',
  }
};

Use bin cmd:

ethereumjs-config-lint


This PR also aims to close #19 and ethereumjs/ethereumjs-monorepo#640

@holgerd77
Copy link
Member

Hi Ryan,
I think naming packages after the tools was a mistake in the first place. This should rather be named after functionality to become tool-agnostic, so names should be something like:

  • ethereumjs-config-nyc -> ethereumjs-config-coverage
  • ethereumjs-config-prettier -> ethereumjs-config-formatting
  • ethereumjs-config-tsc -> ethereumjs-config-typescript
  • ethereumjs-config-tslint -> ethereumjs-config-linting

If you agree: I think it would be worth to do the switch, maybe always along some breaking releases. So do we want to start here on this occasion with the linting package?

@ryanio
Copy link
Contributor Author
ryanio commented Feb 19, 2020

Yeah sounds great, I think it’s a good idea.

I think without the “ing” is fine so “-format” and “-lint”, if you agree.

Should we review and merge this then I’ll do a separate PR for the rest?

@ryanio
Copy link
Contributor Author
ryanio commented Feb 19, 2020

Also, for this PR, should I port over the existing rules on top of the recommended base set?

I’m not sure the history of choosing the existing rules.

@holgerd77
Copy link
Member

We can very well leave the "ing". 🙂 Review and merge this first also sounds fine.

Not sure on the rule set - this is the first time I get in touch with this TSLint -> ESLint deprecation - how much do rules differ between the two?

@ryanio
Copy link
Contributor Author
ryanio commented Feb 24, 2020

Not sure on the rule set - this is the first time I get in touch with this TSLint -> ESLint deprecation - how much do rules differ between the two?

I migrated the existing rules from tslint to eslint using this guide. Based on git blame it looks like most of the tslint file was set up by @krzkaczor and you later added no-console and no-commented-code.

This is the current tslint:

{
  "extends": "typestrict",
  "rules": {
    "no-console": {
      "severity": "warning"
    },
    "no-debugger": true,
    "mocha-avoid-only": true,
    "prefer-const": true,
    "no-var-keyword": true,
    "interface-name": [true, "never-prefix"],
    "no-commented-code": {
      "severity": "warning"
    },
    "no-use-before-declare": false
  }
}

The biggest thing we're missing in eslint is typestrict, however it looks like typescript-eslint recommended rules has done a lot of work to ensure type checking here.

I was able to convert all of the existing rules except mocha-avoid-only and no-commented-code (found someone's custom rule for no-commented-code but seems like there may be some open issues with it here).

This is the resulting eslint:

module.exports = {
  parser: "@typescript-eslint/parser",
  plugins: ["@typescript-eslint"],
  env: {
    es6: true,
    node: true
  },
  ignorePatterns: ["node_modules/**/*", "**/node_modules/**/*", "dist/**/*"],
  extends: [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:@typescript-eslint/recommended-requiring-type-checking",
    "plugin:prettier/recommended"
  ],
  rules: {
    "no-console": "warn",
    "no-debugger": "error",
    "prefer-const": "error",
    "no-var": "error",
    "@typescript-eslint/no-use-before-define": "error",
    "@typescript-eslint/interface-name-prefix": [
      "error",
      {
        prefixWithI: "never"
      }
    ]
  },
  parserOptions: {
    sourceType: "module"
  }
};

@holgerd77
Copy link
Member

Ok, great!

typestrict: I think we might be fine with the better integrated type checking then

no-commented-code: no strong feeling there, would be nice and somewhat quality-improving to have this in, but also not the end of the world to leave out

Generally: this was our very first try to have some more explicit unification and agreement on the linting rules. Don't have anything specific in mind and this generally worked well. We can nevertheless very much do some between conclusion here, improve on stuff or remove things which didn't work so well. Feel very free to add your own recommendations to the discussion. We were a limited group of people discussing this and there is very much room for change and additional voices, eventually @evertonfraga and/or @cgewecke also want to have a word here.

I wouldn't want to merge here before EthCC I think, we can let this sink in a bit further. This is also a good topic to discuss and exchange about at EthCC face-to-face. Feel free to do some continued work here though if necessary.

@krzkaczor
Copy link
Contributor

FYI: TypeStrict just migrated to ESLint! krzkaczor/TypeStrict#19

@ryanio
Copy link
Contributor Author
ryanio commented Mar 28, 2020

Amazing, thanks @krzkaczor! I will update this PR to include it 😎

@holgerd77
Copy link
Member

@ryanio just give an explicit comment once this is open again for review, might be overlooked otherwise

@ryanio ryanio force-pushed the upgradeToESLint branch 2 times, most recently from f61dc1e to 5c4f581 Compare March 31, 2020 01:32
@ryanio
Copy link
Contributor Author
ryanio commented Mar 31, 2020

@holgerd77 @krzkaczor ok, just pushed some updates and this is ready for another review!

I tried to do a test run in ethereumjs-vm/packages/vm by first running npm link in ethereumjs-config and then in the vm dir: npm link @ethereumjs/config-lint. It linted successfully so I think it worked, but I'll have to throw an error in on purpose to make sure it's working as intended :)

@holgerd77
Copy link
Member

What is the status here?

@ryanio ryanio force-pushed the upgradeToESLint branch 2 times, most recently from de09fe6 to af26ac5 Compare May 8, 2020 20:37
@holgerd77
Copy link
Member

@ryanio Thanks for the update! 😄 Is this now ready for review?

@holgerd77
Copy link
Member

(overall status is a bit confusing since the current change request is still active and displayed)

@ryanio
Copy link
Contributor Author
ryanio commented May 9, 2020

Hm thanks yes @evertonfraga can you update your review if the updated code looks good?

I am going to try to use verdaccio or npm link to insert the package into ethereumjs-vm and see if the linting is working well, and if I can throw a lint error on purpose. After that I'd be comfortable moving ahead with merge + npm release on the new name :)

@evertonfraga
Copy link
Contributor

Sorry, I totally missed this notification. Will resume with testing tomorrow!

@ryanio
Copy link
Contributor Author
ryanio commented May 19, 2020

ok I made some updates and I got eslint successfully running on ethereumjs-vm/packages/vm.

This is what I needed to do:

  1. cd ethereumjs-config
    1. checkout branch upgradeToEslint
    2. run npm install
    3. run npm link
  2. cd ethereumjs-vm/packages/vm
    1. remove @ethereumjs/config-tslint from package.json and add dep "eslint": "^7.0.0"
    2. run npm link @ethereumjs/config-link
    3. create a .eslintrc.js file with the following:
module.exports = {
  parserOptions: {
    project: './tsconfig.json',
  }
};

and run npm run lint

I got 97 lint problems however they seem to be just import/require and var/const/let failures that can be fixed along with the upgrade in vm.

The only last thing I would like to figure out if there is a way to not need typescript,eslint, and prettier as deps in this package. there is a --resolve-plugins-relative-to flag for eslint but then all the @typescript-eslint plugin deps would need to be installed into every project.

@ryanio ryanio force-pushed the upgradeToESLint branch from 6e0be5b to 0bc7dcf Compare May 19, 2020 01:48
@ryanio ryanio changed the title Upgrade TSLint to ESLint Upgrade TSLint to ESLint, rename package tslint -> lint May 19, 2020
@evertonfraga
Copy link
Contributor
evertonfraga commented May 19, 2020

Right, thanks for the work here @ryanio! It took me a little while get the whole picture of this package and its current state.

I am testing with VM, made some changes in package.json to pretend it was a fresh package. The UX can still improve, but nothing specific to this PR.

These are the current imposed requirements to make the ethereumjs-config-lint script work:

  1. have an .eslintrc.js file
  2. add script "format": "ethereumjs-config-format" to package.json
  3. add script "tsc": "ethereumjs-config-typescript"to package.json

I made some basic error handling for (1). But I have a feeling that we must do something about the other bullet points. Suggestions:

  • Add prettier and tsc to the package, so we can just run the commands directly, instead of relying in the consumer package.json.

  • Make lint less powerful — yet more granular. It would only execute ESLint, and the consumer libraries would be able to choose the mix of tools it needs to use. Example:

"scripts": {
  "codecheck": "ethereumjs-config-lint && ethereumjs-config-format"
}

@ryanio
Copy link
Contributor Author
ryanio commented May 20, 2020

@evertonfraga looks great, thanks for the rebase!

@holgerd77
Copy link
Member

Not really able to catch up with all the developments here, but from first sight things seem to be going in a good direction, so just another 👍 to go ahead here once you are confident on the changes and merge.

@evertonfraga
Copy link
Contributor

Thanks! I'd like to make a test run on all tasks today. This series of PRs have touched every internal package.

@evertonfraga evertonfraga self-requested a review May 21, 2020 21:23
Copy link
Contributor
@evertonfraga 9E88 evertonfraga left a comment

Choose a reason for hiding this comment

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

ESLint didn't work for me.

The extends: @ethereumjs/config-lint clause in the consumer package gets transformed to @ethereumjs/eslint-config-config-lint.

According to ESLint docs:

The module name can also be customized, just note that when using scoped modules it is not possible to omit the eslint-config- prefix.

https://eslint.org/docs/developer-guide/shareable-configs#npm-scoped-modules
🤷‍♂️

Edit: unless an alternative to keep the same name is possible, we should rename @ethereumjs/config-lint to @ethereumjs/eslint-config-<something>

@evertonfraga
Copy link
Contributor

By the way, I made this little script, to help migrate the package changes. There's another one to help link the packages using file: protocol.

As anything I have to do in the monorepo is x6, this kind of thing is super handy to me.

@evertonfraga
Copy link
Contributor
evertonfraga commented May 26, 2020

@ryanio I followed your instructions from here, and I got the same result as you:

I got 97 lint problems however they seem to be just import/require and var/const/let failures that can be fixed along with the upgrade in vm.

But the 97 errors described indicate that ESLint is not configured properly, as it presents parsing errors, as it does not extend the one defined in lint package.

1:1 error Parsing error: The keyword 'const' is reserved

@evertonfraga
Copy link
Contributor

Additionally, I found some eslint plugins installation mismatch.

Can you provide updated information on how to setup this plugin?

npm WARN eslint-plugin-sonarjs@0.5.0 requires a peer of eslint@^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-plugin-import@2.2.0 requires a peer of eslint@2.x - 3.x but none is installed. You must install peer dependencies yourself.
npm WARN eslint-plugin-react@6.10.3 requires a peer of eslint@^2.0.0 || ^3.0.0 but none is installed. You must install peer dependencies yourself.```

@ryanio
Copy link
Contributor Author
ryanio commented May 26, 2020

@evertonfraga thanks for your patience with this PR 😄

This is currently working for me with latest updates to branch, if you want to give it a try:

In ethereumjs-config/packages/lint run npm link

In ethereumjs-vm/packages/account:

Run npm link @ethereumjs/eslint-config-helper

Create .eslintrc.js:

module.exports = {
  extends: '@ethereumjs/eslint-config-helper',
  parserOptions: {
    project: './tsconfig.eslint.json',
  },
}

Create tsconfig.eslint.json to include files for linting that would otherwise not be parsed and throw an error:

{
  "extends": "./tsconfig.json",
  "include": ["src/**/*.ts", "test/**/*.ts", ".eslintrc.js", "prettier.config.js", "typedoc.js"]
}

(See typescript-eslint/typescript-eslint#1723 (comment) for more on why tsconfig.eslint.json is needed.)

In account, run npm install eslint --save-dev and run something like node_modules/eslint/bin/eslint.js --config ./.eslintrc.js . --resolve-plugins-relative-to ~/dev/ethereumjs-config/packages/lint

(--resolve-plugins-relative-to is needed otherwise the consumer lib will need to install all the plugins used. I have tested adding this to lint.sh with --resolve-plugins-relative-to node_modules/@ethereumjs/config-lint, I will check if it is working as expected.)

My results:

/Users/ryanghods/dev/ethereumjs-vm/packages/account/test/index.spec.ts
  152:43  error  'err' is defined but never used                                             no-unused-vars
  152:43  error  'err' is defined but never used. Allowed unused args must match /^_/u       @typescript-eslint/no-unused-vars
  152:48  error  'codeHash' is defined but never used                                        no-unused-vars
  152:48  error  'codeHash' is defined but never used. Allowed unused args must match /^_/u  @typescript-eslint/no-unused-vars
  200:43  error  'err' is defined but never used                                             no-unused-vars
  200:43  error  'err' is defined but never used. Allowed unused args must match /^_/u       @typescript-eslint/no-unused-vars

@evertonfraga
Copy link
Contributor

Sure, I can rename it now.

I am testing it and doing a test integration to the VM.

@holgerd77
Copy link
Member
holgerd77 commented Aug 25, 2020

@evertonfraga just so that there won't stay any confusion: did you leave this for @ryanio to merge or is there anything explicitly blocking this or other reasoning to leave this open for now?

@evertonfraga
Copy link
Contributor

I am making integration tests with the monorepo and will merge this one soon

@evertonfraga evertonfraga merged commit 0bcfb66 into master Aug 25, 2020
@evertonfraga evertonfraga deleted the upgradeToESLint branch August 25, 2020 15:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TSLint not invoked on lint cli
4 participants
0