Skip to content

feat!: angular-eslint v18 #1830

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

Merged
merged 41 commits into from
May 29, 2024
Merged

feat!: angular-eslint v18 #1830

merged 41 commits into from
May 29, 2024

Conversation

JamesHenry
Copy link
Member

@JamesHenry JamesHenry commented May 22, 2024

As you can see this PR was a huge amount of work to add support for ESLint v9 and Flat Config while still maintaining backwards compatibility with ESLint v8 and eslintrc configs. This was done in my personal time at the expense of other things. If you are able to and feel like buying me a coffee or two to support my work, you can find my link here:

https://buymeacoffee.com/jameshenry

Thank you 🙏


As usual, we align our major release with the Angular framework/Angular CLI.

Main highlights/TODO list before merge, which will also be called out in the release notes as part of the stable release:

  • update to Angular v18, drop Angular v17
  • deprecate no-host-metadata-property rule and remove from recommended config of @angular-eslint/eslint-plugin
  • update links from angular.io to angular.dev
  • drop support for ESLint v7
  • add support for ESLint v9 (maintaining support for the final version of ESLint v8 - 8.57.0).
  • migrate test related utils out of @angular-eslint/utils into new @angular-eslint/test-utils package
  • generate new configs as the new default flat config with ESLint v9 and typescript-eslint v8 prereleases
  • add the new angular-eslint core package for use in ESLint v9 workspaces
  • Update documentation

Updating existing Angular CLI workspaces to v18

After you have updated your Angular CLI version, simply run:

ng update @angular-eslint/schematics@rc-v18

NOTE: There will not be any migration of your setup to ESLint v9 or flat configs for existing workspaces in v18.

The ESLint team are working on automigrate tooling which we will leverage in an opt-in conversion generator once it is ready in a v18 minor release and consider full automigration in v19 in six months (aligned with Angular major release schedule as always).

If you want to manually migrate your workspace to use ESLint v9, typescript-eslint v8, and flat config you are welcome to and it should be fully support in v18 (which is how the next section is possible).

If you are going to attempt this, I strongly recommended creating a fresh Angular v18 workspace and adding angular-eslint to it per the instructions below and then copying the dependencies and configs that it applies into your existing workspace

Here is an example of what the new flat config with angular-eslint v18, typescript-eslint v8, and ESLint v9 looks like:

image


Adding to New Angular Workspaces in v18

There is a decision to be made when adding to new Angular v18 workspaces.

Just as before, if you want to add angular-eslint to a workspace with no existing lint setup, you leverage ng add with the @angular-eslint/schematics package.

The difference is in v18, you have the option of using either:

  • the latest version of ESLint v9, with the latest default so called "flat config" (eslint.config.js) alongside the latest prerelease of typescript-eslint v8 (https://typescript-eslint.io/blog/announcing-typescript-eslint-v8-beta)
    OR
  • the final stable version of ESLint v8, with the legacy so called "eslintrc" config (.eslintrc.json) and the latest stable version of typescript-eslint v7

The ESLint v9 option is the default scenario if you simply run ng add with no other changes. If you want to signal to angular-eslint that you instead want to go with the ESLint v8 option, simply add an eslint v8 (the exact version does not matter, it just needs to be less than 9) devDependency in your package.json before running the ng add. That's it - you don't even need to install the eslint package, it just needs to be listed there.

E.g.
image

Here are example "after" root package.json files from the two scenarios:

1. No eslint devDependency specified before running ng add, use the default ESLint v9 setup. This will use the new angular-eslint and typescript-eslint core packages, so you will see much fewer individual devDependencies added:

image

2. eslint v8 devDependency is specified before running ng-add. Use ESlint 8.57.0 and the traditional @typescript-eslint/ and @angular-eslint/ packages.

image

Copy link

nx-cloud bot commented May 22, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 8041c59. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 6 targets

Sent with 💌 from NxCloud.

@JamesHenry JamesHenry force-pushed the next-major-release/v18 branch 3 times, most recently from 40a9104 to 8672cb5 Compare May 22, 2024 20:18
@JamesHenry JamesHenry force-pushed the next-major-release/v18 branch from 8672cb5 to 76004d6 Compare May 22, 2024 20:24
Copy link

codecov bot commented May 22, 2024

Codecov Report

Attention: Patch coverage is 81.81818% with 22 lines in your changes are missing coverage. Please review.

Project coverage is 91.62%. Comparing base (05e8cf9) to head (8041c59).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1830      +/-   ##
==========================================
+ Coverage   90.46%   91.62%   +1.16%     
==========================================
  Files         179      179              
  Lines        3377     3380       +3     
  Branches      542      547       +5     
==========================================
+ Hits         3055     3097      +42     
+ Misses        186      144      -42     
- Partials      136      139       +3     
Flag Coverage Δ
unittest 91.62% <81.81%> (+1.16%) ⬆️

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

Files Coverage Δ
packages/eslint-plugin-template/src/processors.ts 76.47% <100.00%> (-0.28%) ⬇️
...lint-plugin-template/src/rules/attributes-order.ts 94.44% <ø> (ø)
.../eslint-plugin-template/src/rules/banana-in-box.ts 100.00% <ø> (ø)
...lugin-template/src/rules/conditional-complexity.ts 100.00% <ø> (ø)
...ackages/eslint-plugin-template/src/rules/eqeqeq.ts 92.68% <ø> (ø)
packages/eslint-plugin-template/src/rules/i18n.ts 91.66% <ø> (ø)
...ackages/eslint-plugin-template/src/rules/no-any.ts 89.47% <100.00%> (ø)
...nt-plugin-template/src/rules/no-call-expression.ts 100.00% <100.00%> (ø)
...ugin-template/src/rules/no-duplicate-attributes.ts 97.05% <ø> (ø)
...mplate/src/rules/no-interpolation-in-attributes.ts 100.00% <100.00%> (ø)
... and 99 more

@nicojs
Copy link

nicojs commented May 23, 2024

If you want to use angular-eslint v18 before it is stable (⚠️ SEE THE WARNING) you can run:

Thanks! You're a lifesaver! 🙏

9034725985 added a commit to mycanary/mycanary that referenced this pull request May 25, 2024
PS C:\Users\kushal\src\angular\mycanary> cd "C:\Users\kushal\src\angular\mycanary\"; date; yarn; date; yarn run ng build; date; yarn run ng update; date; yarn run ng update @angular/core @angular/cli @angular/cdk @angular/material @angular/localize rxjs; date;

Saturday, May 25, 2024 6:22:44 AM
yarn install v1.22.21
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.29s.
Saturday, May 25, 2024 6:22:44 AM
yarn run v1.22.21
$ ng build
✔ Browser application bundle generation complete.
✔ Copying assets complete.
✔ Index html generation complete.

Initial chunk files | Names         |  Raw size
vendor.js           | vendor        |   4.75 MB |
polyfills.js        | polyfills     | 138.66 kB |
main.js             | main          |  19.85 kB |
runtime.js          | runtime       |   6.34 kB |
styles.css          | styles        |   2.44 kB |

                    | Initial total |   4.91 MB

Build at: 2024-05-25T10:22:49.201Z - Hash: 0efaddec27b7259e - Time: 2270ms
Done in 4.18s.
Saturday, May 25, 2024 6:22:49 AM
yarn run v1.22.21
$ ng update
Using package manager: yarn
Collecting installed dependencies...
Found 41 dependencies.
    We analyzed your package.json, there are some packages to update:

      Name                                    Version                  Command to update
     -------------------------------------------------------------------------------------
      @angular/cdk                            17.3.10 -> 18.0.0        ng update @angular/cdk
      @angular/cli                            17.3.7 -> 18.0.1         ng update @angular/cli
      @angular/core                           17.3.9 -> 18.0.0         ng update @angular/core
      @angular/material                       17.3.10 -> 18.0.0        ng update @angular/material

    There might be additional packages which don't provide 'ng update' capabilities that are outdated.
    You can update the additional packages by running the update command of your package manager.
Done in 4.89s.
Saturday, May 25, 2024 6:22:54 AM
yarn run v1.22.21
$ ng update @angular/core @angular/cli @angular/cdk @angular/material @angular/localize rxjs
The installed Angular CLI version is outdated.
Installing a temporary Angular CLI versioned 18.0.1 to perform the update.
✔ Packages successfully installed.
Using package manager: yarn
Collecting installed dependencies...
Found 41 dependencies.
Fetching dependency metadata from registry...
                  Package "@angular-eslint/schematics" has an incompatible peer dependency to "@angular/cli" (requires ">= 17.0.0 < 18.0.0", would install "18.0.1").
× Migration failed: Incompatible peer dependencies found.
Peer dependency warnings when installing dependencies means that those dependencies might not work correctly together.
You can use the '--force' option to ignore incompatible peer dependencies and instead address these warnings later.
  See "C:\Users\kushal\AppData\Local\Temp\ng-0ncWdO\angular-errors.log" for further details.

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Saturday, May 25, 2024 6:23:12 AM

PS C:\Users\kushal\src\angular\mycanary>

see also
angular-eslint/angular-eslint#1837
angular-eslint/angular-eslint#1830
@JamesHenry
Copy link
Member Author

JamesHenry commented May 28, 2024

I have updated the PR description with guidance on how angular-eslint v18 works. Pay special attention to how it works for new workspaces.

No more breaking changes are expected at this stage, please try it out using instructions in the description and report any issues with minimal steps to reproduce.

The final known TODO is to update the main documentation.

Thanks all!

@JamesHenry JamesHenry mentioned this pull request May 28, 2024
1 task
@JamesHenry JamesHenry marked this pull request as ready for review May 28, 2024 12:59
@JamesHenry JamesHenry merged commit 7c84ab7 into main May 29, 2024
8 of 9 checks passed
@JamesHenry JamesHenry deleted the next-major-release/v18 branch May 29, 2024 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants