Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(linter): major improvements to ESLint support#3763

Closed
JamesHenry wants to merge 1 commit intonrwl:masterfrom
JamesHenry:lint-updates
Closed

feat(linter): major improvements to ESLint support#3763
JamesHenry wants to merge 1 commit intonrwl:masterfrom
JamesHenry:lint-updates

Conversation

@JamesHenry
Copy link
Collaborator

@JamesHenry JamesHenry commented Sep 18, 2020

This PR includes some major improvements to how ESLint is supported in Nx and paves the way for much better Angular + ESLint support, in particular, in a follow up PR.


SPLIT OUT AND MERGED AS #3834

## New builder for ESLint

The current ESLint builder that ships with Nx is a port of a port of the TSLint builder from angular-devkit. This originally made sense as a starting point to get things working.

However, that initial implementation has shown its limitations and it is doing a bunch of work that, whilst appropriate in the TSLint case, is not appropriate in the ESLint case.

This PR adds a new builder implementation alongside the existing one. This will give us the easiest path to providing the new functionality without requiring users to migrate straight away (although this PR will also provide an automated migration). By having two separate implementations, we can avoid having a single, complex implementation with a messy and hard to validate schema definition for the builder.

This new builder should resolve:

- #3310
- #2784

## Updated dependencies and ESLint config file type

- Currently Nx is using an outdated version of ESLint and therefore missing out on bug fixes and performance improvements. This PR updates to the latest major version of ESLint (v7).

- Currently Nx is using heavily outdated versions of @typescript-eslint dependencies, and therefore missing out on bug fixes and performance improvements. This PR updates those deps to the latest we can whilst still matching the supported TypeScript version (3.x).

Fixes:
- #3715


SPLIT OUT AND MERGED AS #3847

## ESLint config file type

- Currently Nx creates .eslintrc files which are deprecated by ESLint. In that file they supported YAML and JSON, but Nx only ever uses JSON, so this PR moves to use .eslintrc.json files, and has an automated migration for any old .eslintrc that contain JSON.

Fixes:
- #2833


SPLIT OUT AND MERGED AS #3852

## Root ESLint Config does not trigger affected logic for projects

- Currently changes to the root .eslintrc/.eslintrc.json file does not cause anything to be affected when it should be a very high potential impact change for the lint taget.

Fixes:
- #2858


ESLint config itself

  • Currently Nx is not able to support more advanced use-cases out of the box (such as fully supporting Angular by linting HTML files) because of the way it creates flat ESLint configs. This puts a lot of burden on the user to figure out everything for themselves, and it is easy to create a broken setup.

This PR updates how ESLint is fundamentally configured to lean on overrides for each type of file that needs to be supported.


Other notes:

  • Opening as Draft PR per request for Nrwl folks to start playing with it before it is ready for full review.

@nx-cloud
Copy link
Contributor

nx-cloud bot commented Sep 18, 2020

Nx Cloud Report

CI ran the following commands. Click to see the status, the terminal output, and the build insights.

Status Command Start Time
#000000 nx run-many --target=e2e --projects=e2e-workspace,e2e-cli 9/25/2020, 9:24:34 AM

Sent with 💌 from NxCloud.

@pf1gura
Copy link

pf1gura commented Sep 26, 2020

@JamesHenry what do you think about using JavaScript versions of eslint config instead of JSON? I like to comment in those config files and from what I read on this internet I am not alone.

@JamesHenry
Copy link
Collaborator Author

JamesHenry commented Sep 28, 2020

@pf1gura JSON ESLint config files support comments, both in editors and when included in a lint run via the command line (whether directly or wrapped in a builder). So that major pro of JS is already covered.

The major con of JS files is that they are incredibly difficult to support from an automated tooling perspective. With JSON we can easily statically analyse them and write migrations to update them automatically when you upgrade Nx. With JS we can't and so you will need to support making any recommended changes yourself. So, in summary, you can use JS files if you want to, they will work, but they come at a cost.

@pf1gura
Copy link

pf1gura commented Sep 28, 2020

@JamesHenry Your comment makes a lot of sense. Comments in config files were my only argument to use JS files (and I did not know that JSON config supports comments 🤦). That makes things a lot easier 😄

Disregard my message then. I looked at the PR and everything else looks great. Awesome work. Hope it gets merged soon.

@JamesHenry
Copy link
Collaborator Author

@pf1gura No problem - it's not the common case for comments to be supported in JSON of course, so it is a natural assumption for you to make, but the ESLint team decide to support comments in their JSON config files so that is something we can leverage!

@JamesHenry
Copy link
Collaborator Author

Going to close this as there is now only one major part of this PR that needs to be tackled separately (config changes towards overrides) - everything else has been successfully split out and merged already

@JamesHenry JamesHenry closed this Oct 2, 2020
@JamesHenry JamesHenry deleted the lint-updates branch October 2, 2020 16:29
@JamesHenry JamesHenry restored the lint-updates branch October 2, 2020 16:29
@github-actions
Copy link
Contributor

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants