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

chore: set up eslint-plugin-simple-import-sort and eslint-plugin-import #2086

Merged
merged 2 commits into from
Aug 3, 2022
Merged

chore: set up eslint-plugin-simple-import-sort and eslint-plugin-import #2086

merged 2 commits into from
Aug 3, 2022

Conversation

faustbrian
Copy link
Contributor

@faustbrian faustbrian commented Aug 1, 2022

@faustbrian faustbrian marked this pull request as ready for review August 1, 2022 01:19
@codecov
Copy link

codecov bot commented Aug 1, 2022

Codecov Report

Merging #2086 (58ab847) into master (6967774) will decrease coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

Flag Coverage Δ
block 83.81% <100.00%> (ø)
blockchain 80.54% <100.00%> (ø)
client 78.28% <100.00%> (-0.02%) ⬇️
common 95.00% <100.00%> (ø)
devp2p 82.49% <100.00%> (-0.11%) ⬇️
ethash 90.81% <100.00%> (ø)
evm 40.94% <100.00%> (-0.03%) ⬇️
rlp 90.47% <ø> (ø)
statemanager 84.55% <100.00%> (ø)
trie 81.35% <100.00%> (-0.12%) ⬇️
tx 92.20% <ø> (+0.01%) ⬆️
util 87.22% <ø> (ø)
vm 78.40% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@acolytec3 acolytec3 requested a review from gabrocheleau August 1, 2022 02:21
@acolytec3
Copy link
Contributor

I haven't looked into either this one or #2085 yet but I'm inferring there's a fair amount of overlap since @gabrocheleau referenced your list from #2073. Assuming these two PRs cover the same territory, can y'all consolidate?

@gabrocheleau
Copy link
Contributor

I haven't looked into either this one or #2085 yet but I'm inferring there's a fair amount of overlap since @gabrocheleau referenced your list from #2073. Assuming these two PRs cover the same territory, can y'all consolidate?

Indeed, they both overlap significantly but this one covers some additional rules, so I suggest we keep this one. I'll review.

config/eslint.js Outdated
Comment on lines 60 to 84
'@typescript-eslint/strict-boolean-expressions': ['error'],
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
'import/default': 'error',
'import/export': 'error',
'import/exports-last': 'off', // TODO: set to `warn` for fixing and then `error`
'import/extensions': 'off',
'import/first': 'error',
'import/group-exports': 'off',
'import/namespace': 'error',
'import/no-absolute-path': 'error',
'import/no-anonymous-default-export': 'error',
'import/no-cycle': 'off', // TODO: set to `warn` for fixing and then `error`
'import/no-deprecated': 'off', // TODO: set to `warn` for fixing and then `error`
'import/no-duplicates': 'error',
'import/no-dynamic-require': 'off',
'import/no-extraneous-dependencies': 'error',
'import/no-mutable-exports': 'error',
'import/no-namespace': 'off',
'import/no-restricted-paths': 'error',
'import/no-self-import': 'error',
'import/no-unresolved': 'off',
'import/no-unused-modules': 'error',
'import/no-useless-path-segments': 'error',
'import/no-webpack-loader-syntax': 'error',
'import/order': 'error',
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we actually need all those additional rules? My intuition would be to only include rules that currently result in an update when applied for performance and general simplicity. I haven't looked up what each of these rules does in detail but here's a couple examples of rules that I suspect don't result in changes:

    'import/no-absolute-path': 'error',
    'import/no-anonymous-default-export': 'error',
    'import/no-restricted-paths': 'error',
    'import/no-self-import': 'error',
    
    Curious to hear your thoughts on that, and more generally, I personally feel like it'd be great if the additional rule was justified, so that we avoid bloating up our linting configuration. 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I generally treat linting as a preventative measure rather than applying rules when an issue pops up so I would say it depends on your stance on that. People use dozens of different editors and IDEs and each of them has their own ways of generating imports and exports and handling monorepos which makes rules like the absolute path and anonymous default export rules useful. The self-import rule is a rather odd rule but automatic refactoring in certain tools can generate code that triggers that rule.

Let me know if you want me to remove those rules and I'll push that.

Copy link
Contributor

@gabrocheleau gabrocheleau Aug 1, 2022

Choose a reason for hiding this comment

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

Yeah I can totally get behind the preventative approach, I guess my main concern is I'd like to make sure that the added rules are relevant, mostly because I don't currently have a clear view on why some of these rules were added to start with.

I think it's worth thinking about what our criteria for adding new rules should be. Some examples that I have doubts about:

  • we are adding 'import/default' (which ensures that default imports are coupled with exports) but not 'import/named' (which ensures that named imports are coupled with exports).
  • group-exports and exports-last, is this something we actually want? I tend to lean in favor, but it requires a non-trivial amount of work, and I wouldn't consider it a no-brainer.
  • no-restricted-paths, from what I understand this is only useful in the context where "restricted zones" are defined, but I don't think we have those

I've ran into situations, on other repos, where an excessive amount of resource-intensive linting rules led to performance issues for some contributors, hence my preoccupation with ensuring that additional rules serve a useful purpose.

Tagging the rest of the team in case they'd like to voice an opinion on that. @holgerd77 @acolytec3 @jochem-brouwer @ScottyPoi @g11tech

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • Added the import/named rule
  • The group-exports and exports-last rules I'll take care of in subsequent PRs.
  • Removed the no-restricted-paths rule

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have past experience with complex linting setups beyond the monorepo so can't comment on performance, but I don't notice any differences between running the linter on master vs this PR on my VSCode setup.

As far as individual rules in this set go, the only one we'll have to revisit is the import/extensions if/when we add ESM support. Otherwise, this list looks good to me and I like having all the imports organized.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If performance ever becomes an issue you should consider something like https://turborepo.org/ to speed up execution compared to how npm handles workspaces.

Copy link
Contributor Author

@faustbrian faustbrian Aug 1, 2022

Choose a reason for hiding this comment

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

@gabrocheleau just to give you a bit of a better idea about eslint on a bigger repo. I have a monorepo with turborepo and that repo has 103 packages with over 2000 files, which takes roughly 5s to lint for the whole repo with 4 times the amount of rules.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks guys for the additional comments! Looks great @faustbrian, I'm on board with the remaining eslint rules! Good to know that there are solutions if we ever run into performance issues.

Copy link
Contributor

@gabrocheleau gabrocheleau left a comment

Choose a reason for hiding this comment

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

Great work! Really satisfying to see the monorepo get tidied up :) Left a couple comments

packages/evm/src/precompiles/index.ts Outdated Show resolved Hide resolved
packages/statemanager/tests/stateManager.spec.ts Outdated Show resolved Hide resolved
packages/trie/test/index.spec.ts Show resolved Hide resolved
packages/vm/tests/api/index.spec.ts Outdated Show resolved Hide resolved
@faustbrian
Copy link
Contributor Author

@gabrocheleau think I addressed all of them.

@gabrocheleau
Copy link
Contributor

@gabrocheleau think I addressed all of them.

Looks good, thanks for the quick fixes! I'll wait for additional input from some other team members on the discussion above, and give it another review later this week :)

@acolytec3
Copy link
Contributor

@holgerd77 Any thoughts on this before we move forward?

gabrocheleau
gabrocheleau previously approved these changes Aug 2, 2022
Copy link
Contributor

@gabrocheleau gabrocheleau left a comment

Choose a reason for hiding this comment

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

Approving, looks good to me. Left two minor comments. Also, this should be rebased on latest!

Let's still wait for @holgerd77 's input before merging however.

config/eslint.js Outdated Show resolved Hide resolved
packages/vm/tests/api/index.spec.ts Outdated Show resolved Hide resolved
Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

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

Ok. 🙂

@holgerd77 holgerd77 merged commit afead41 into ethereumjs:master Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants