Skip to content

Conversation

@iosh
Copy link
Contributor

@iosh iosh commented Mar 29, 2025

  • Because this PR includes a bug fix, relevant tests have been included.
  • Because this PR includes a new feature, the change was previously discussed on an Issue or with someone from the team.
  • [] I didn't do anything of this.

ESLint from v8 to v9

resolve #5568

This PR migrates the project's ESLint setup from version 8 to version 9. This includes adopting the new flat configuration format (eslint.config.cjs) and updating related dependencies.

Key Changes:

  1. New Configuration Package (config) in v-next:

    • Created a new internal package (config) to hold the shared ESLint 9 configuration.
    • Moved ESLint-related dependencies (plugins, parser, resolvers) into this package.
    • Removed these dependencies from individual workspace packages to centralize configuration management.
  2. Dependency Updates:

    • eslint -> 9.25.1
    • typescript-eslint -> 8.31.0
    • eslint-plugin-import -> v2.31.0
    • eslint-plugin-no-only-tests -> 3.3.0
  3. Configuration File Renaming:

    • Renamed .eslintrc.cjs to eslint.config.cjs across the entire workspace, including the root and individual packages.
  4. Configuration Syntax Updates (ESLint 9 Flat Config):

    • Replaced env with languageOptions. (See ESLint Docs)
    • Replaced the deprecated @typescript-eslint/ban-types rule with the recommended @typescript-eslint/no-wrapper-object-types. (See TS-ESLint Blog)
    • Updated the plugins configuration from an array (plugins: ["import"]) to an object format (plugins: { import: eslintPluginImport }). (See ESLint Docs)
    • Adapted overrides config . (See ESLint Docs)
    • The internal createConfig helper function now returns an array of configuration objects (import("eslint").Linter.Config[]) instead of a single object.
  5. Workspace Package Updates:

    • Updated ESLint config file names (.eslintrc.cjs -> eslint.config.cjs).

    • Removed the following dependencies from individual packages (now managed centrally in config-v-next):

      • @eslint-community/eslint-plugin-eslint-comments

      • @typescript-eslint/eslint-plugin

      • @typescript-eslint/parser

      • eslint-import-resolver-typescript

      • eslint-plugin-import

      • eslint-plugin-no-only-tests

      • typescript-eslint

      • eslint-config-prettier (unused)

I have run pnpm eslint in each package for both the v8 and v9 configurations. When the number of errors/warnings differed, npx eslint --print-config was used to compare the effective configurations and check the rule is same.

~~ Update 2025-4-20 ~~

  • Instead of pnpm eslint run npx eslint --rule 'no-restricted-imports: off' "src/**/*.ts" "test/**/*.ts"
  • ignore "error 'node:test' import is restricted from being used by a pattern. Use the 'node:' prefix to import built-in Node.js modules no-restricted-imports" in the results

** Update 2025-4-25: **
Fix eslint check error and warnings:

  • hardhat:

    • @typescript-eslint/switch-exhaustiveness-check: 2
      Disable errors:

      • Ignore Cases not matched: undefined
      • Ignore other platforms
    • @typescript-eslint/no-unused-vars: 8

      • Added the configuation caughtErrorsIgnorePattern: "^_", and rename the unused error to _error
    • Unused eslint-disable directive: 5 (warnings)

      • Remove all Unused eslint-disable directive
  • hardhat-errors:

    • v9: 0 error, 0 warnings
      • No changes
  • hardhat-ethers:

    • v9: 0 error, 0 warnings
      • No changes
  • hardhat-ethers-chai-matchers:

    • v9: 4 errors, 1 warning
      • @typescript-eslint/no-unused-vars: 4
        • Rename the unused error to _error
      • Unused eslint-disable directive: 1 (warnings)
        • Remove all Unused eslint-disable directive
  • hardhat-ignition:

    • v9: 0 errors, 2 warnings
      • Unused eslint-disable directive (warnings)
        • Remove all Unused eslint-disable directive
  • hardhat-ignition-core:

    • v9: 8 errors, 0 warnings

      • import/order: 4

        • Fix import order
      • @typescript-eslint/strict-boolean-expressions: 1

        • Add undefined check
      • @typescript-eslint/no-unused-vars: 1

        • Rename the unused error to _error
      • @typescript-eslint/switch-exhaustiveness-check: 2

        • Disable lint
  • hardhat-ignition-ethers:

    • v9: 0 problems
      • No changes
  • hardhat-ignition-ui:

    • v9: 0 errors, 2 warnings
      • Unused eslint-disable directive: 2 (warnings)
        • Remove all Unused eslint-disable directive
  • hardhat-ignition-viem:

    • v9: 19 errors, 0 warnings
      • @typescript-eslint/ban-ts-comment: 17
        • Add Expect an error to comment
      • @typescript-eslint/strict-boolean-expressions: 2
        • Add This function return boolean to comment
  • hardhat-keystore:

    • v9: 0 errors, 1 warning
      • Remove all Unused eslint-disable directive
  • hardhat-mocha:

    • v9: 0 error, 0 warnings
  • hardhat-network-helpers:

    • v9: 1 error, 0 warnings
      • @typescript-eslint/strict-boolean-expressions: 1
        • Add === true check
  • hardhat-node-test-reporter:

    • v9: 1 errors, 0 warnings
      • @typescript-eslint/switch-exhaustiveness-check: 1
  • hardhat-node-test-runner:

    • v9: 0 error, 0 warnings
  • hardhat-test-utils:

    • v9: 3 errors, 0 warnings
      • @typescript-eslint/no-unused-vars : 3
        • Rename the unused error to _error
  • hardhat-typechain:

    • v9: 0 errors, 5 warnings
      • Unused eslint-disable directive: 5 (warnings)
        • Remove all Unused eslint-disable directive
  • hardhat-utils:

    • v9: 6 errors, 0 warnings

      • @typescript-eslint/switch-exhaustiveness-check: 1

        • Disable and add comment
      • @typescript-eslint/no-unused-vars: 5

        • Remove all Unused eslint-disable directive
  • hardhat-viem:

    • v8: 1 error, 0 warnings
      • @typescript-eslint/strict-boolean-expressions: 1
    • v9: 0 errors, 0 warnings
  • hardhat-zod-utils:

    • v8: 2 errors, 0 warnings
      • @typescript-eslint/strict-boolean-expressions: 2
    • v9: 0 error, 0 warnings
  • template-package:

    • v8: 2 errors, 0 warnings
    • v9: 2 errors, 0 warnings
  • hardhat-toolbox-mocha-ethers

    • v8: 1 errors, 0 warnings
    • v9: 1 errors, 0 warnings
  • hardhat-toolbox-viem

  • v8: 1 errors, 0 warnings

  • v9: 1 errors, 0 warnings

@changeset-bot
Copy link

changeset-bot bot commented Mar 29, 2025

🦋 Changeset detected

Latest commit: 58adbbd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@nomicfoundation/hardhat-errors Patch
@nomicfoundation/hardhat-ethers-chai-matchers Patch
@nomicfoundation/hardhat-ethers Patch
@nomicfoundation/ignition-core Patch
@nomicfoundation/hardhat-ignition-ethers Patch
@nomicfoundation/ignition-ui Patch
@nomicfoundation/hardhat-ignition-viem Patch
@nomicfoundation/hardhat-ignition Patch
hardhat Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Mar 29, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hardhat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 1, 2025 2:00am

@iosh
Copy link
Contributor Author

iosh commented Apr 20, 2025

The eslint-config-prettier plugin was not being used, so it was removed.

Copy link
Member

@schaable schaable left a comment

Choose a reason for hiding this comment

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

Hi @iosh! Awesome work! I left some comments and questions.

@github-project-automation github-project-automation bot moved this from Backlog to In Review in Hardhat Apr 22, 2025
@iosh
Copy link
Contributor Author

iosh commented Apr 24, 2025

I saw some test tailed. let me check it.

@schaable
Copy link
Member

schaable commented Apr 24, 2025

I saw some test tailed. let me check it.

It looks like it's due to diverging versions of the eslint plugin. While you're at it, do you mind:

  • Pinning the versions of eslint and its plugins to avoid unexpected linting errors from patch version differences between local and CI
  • Bumping all eslint-related dependencies to their latest versions

EDIT: for pinning I mean use exact versions (no ^ or ~) for eslint and its plugins to avoid version mismatches

@iosh
Copy link
Contributor Author

iosh commented Apr 24, 2025

I saw some test tailed. let me check it.

It looks like it's due to diverging versions of the eslint plugin. While you're at it, do you mind:

  • Pinning the versions of eslint and its plugins to avoid unexpected linting errors from patch version differences between local and CI
  • Bumping all eslint-related dependencies to their latest versions

OK. and some eslint check failed, I need check why.

@iosh
Copy link
Contributor Author

iosh commented Apr 24, 2025

I saw some test tailed. let me check it.

It looks like it's due to diverging versions of the eslint plugin. While you're at it, do you mind:

  • Pinning the versions of eslint and its plugins to avoid unexpected linting errors from patch version differences between local and CI
  • Bumping all eslint-related dependencies to their latest versions

EDIT: for pinning I mean use exact versions (no ^ or ~) for eslint and its plugins to avoid version mismatches

I think i need to fix the error in eslint v9, but this will get lot of changes. So i will add commit for each package change to ease the review. or do you have any suggestions on this?

@iosh
Copy link
Contributor Author

iosh commented Apr 25, 2025

@schaable Hi, I have fixed the ESLint errors. Although there were a lot of changes, they were simple. So, I only made one commit and updated the PR description.

@iosh
Copy link
Contributor Author

iosh commented Apr 25, 2025

The [config-v-next] lint job failed because the config-v-next package was not in the v-next folder. I have moved the package into the v-next folder and updated the relevant references to fix this.

I tried multiple times to reproduce the error from CI locally bug couldn't, which left me puzzled. After numerous tries, i finally realized it was because i hadn't clear the build cache and rebuild the code.

@schaable
Copy link
Member

schaable commented Apr 25, 2025

@iosh we can ignore the config project in scripts/check-v-next-npm-scripts.js

EDIT: and we can probably get rid of these scripts in v-next/config/package.json:

    "eslint": "true",
    "test": "true",
    "test:only": "true",
    "test:coverage": "true",
    "pretest": "true",
    "pretest:only": "true",
    "build": "true",
    "prepublishOnly": "true",

@schaable schaable enabled auto-merge May 5, 2025 08:40
@schaable schaable added this pull request to the merge queue May 5, 2025
Merged via the queue into NomicFoundation:v-next with commit b42a8d5 May 5, 2025
131 of 132 checks passed
@github-project-automation github-project-automation bot moved this from In Review to Done in Hardhat May 5, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants