schematics icon indicating copy to clipboard operation
schematics copied to clipboard

nest-cli new will generate an scaffolding with eslint V9.9.0

Open Byron2016 opened this issue 1 year ago • 8 comments

Is there an existing issue that is already proposing this?

  • [X] I have searched the existing issues

Is your feature request related to a problem? Please describe it

Currently when we run pnpx @nestjs/cli new it is generated a nestjs scaffolding with "eslint": "^8.42.0" and eslintrc.js file, it is necessary to update to new FLAT FILE WITH "eslint": "^9.9.0"

Describe the solution you'd like

to update to new FLAT FILE WITH "eslint": "^9.9.0"

Teachability, documentation, adoption, migration strategy

.

What is the motivation / use case for changing the behavior?

to make use of new eslint's FLAT file simplicity

Byron2016 avatar Aug 24 '24 01:08 Byron2016

What is that flat file? 🤔 I never saw this expression before sorry

micalevisk avatar Aug 24 '24 01:08 micalevisk

@micalevisk ESLint made a breaking change with V9. Now it works with eslint.config.js that named flat file / flat config instead of .eslintrc.js Start Using Flat Config Files. This new configuration has some ventages because ESLint is trying to made more easy its configuration and integration with other plugings, configs, formarters, etc.

Byron2016 avatar Aug 24 '24 16:08 Byron2016

@Byron2016 would you like to create a PR to address this? It should be done at https://github.com/nestjs/schematics/blob/master/src/lib/application/files/ts/package.json and related files in that directory

micalevisk avatar Aug 24 '24 23:08 micalevisk

@micalevisk I am not sure about PR because I have some dudes about eslint configuration, but here are the steps that are needed to do:

I think it is necesary to do this changes:

  • package.json

    • Add scripts:
      • "format:check": "prettier --check "src//*.ts" "test//*.ts"",
      • "lint:nofix": "eslint "{src,apps,libs,test}/**/*.ts" ",
      • "lint:inspect": "eslint --inspect-config",
    • update devDependencies
      • "eslint": "^9.9.1",
      • "eslint-config-prettier": "^9.1.0",
      • "prettier": "^3.3.3",
    • add devDependencies
      • "@eslint/js": "^9.9.1",
      • "globals": "^15.9.0",
      • "typescript-eslint": "^8.3.0"
      • "eslint-plugin-jest": "^28.8.0",
    • remove devDependencies
      • "@typescript-eslint/eslint-plugin" and "@typescript-eslint/parser"
        • Because typescript-eslint already has devDependencies on @typescript-eslint/eslint-plugin and @typescript-eslint/parser
      • "eslint-plugin-prettier": "^5.0.0",
        • This plugin was especially useful when Prettier was new. By running Prettier inside your linters, you didn’t have to set up any new infrastructure and you could re-use your editor integrations for the linters. But these days you can run prettier --check . and most editors have Prettier support. eslint-plugin-prettier
  • tsconfig.json

    • update to true:
    • "strictNullChecks": true,
  • Eslint

    • remove .eslintrc.js
    • add eslint.config.js
    • This is eslint.config.js file content, but it is necessary to validate with another one with more experience with ESLint
const eslint = require('@eslint/js');
const globals = require('globals');

const tseslint = require('typescript-eslint');

const eslintConfigPrettier = require('eslint-config-prettier');

module.exports = [
  {
    ignores: ['**/eslint.config.js'],
  },

  eslint.configs.recommended,
  ...tseslint.configs.recommendedTypeChecked,
  ...tseslint.configs.stylisticTypeChecked,
  eslintConfigPrettier,

  {
    languageOptions: {
      globals: {
        ...globals.node,
        ...globals.jest,
      },

      parser: tseslint.parser,
      parserOptions: {
        projectService: true,
        tsconfigRootDir: __dirname,
      },
    },
    // Rules
    rules: {
      '@typescript-eslint/explicit-function-return-type': 'off',
      '@typescript-eslint/explicit-module-boundary-types': 'off',
      '@typescript-eslint/interface-name-prefix': 'off',
      '@typescript-eslint/no-explicit-any': 'off',
    },
  },
];


Byron2016 avatar Aug 25 '24 04:08 Byron2016

Also, nest cli generates code with outdated packages. Current Package Version

"dependencies": {
    "@nestjs/common": "^10.0.0",
    "@nestjs/core": "^10.0.0",
    "@nestjs/platform-express": "^10.0.0",
    "reflect-metadata": "^0.2.0",
    "rxjs": "^7.8.1"
  },
  "devDependencies": {
    "@nestjs/cli": "^10.0.0",
    "@nestjs/schematics": "^10.0.0",
    "@nestjs/testing": "^10.0.0",
    "@types/express": "^4.17.17",
    "@types/jest": "^29.5.2",
    "@types/node": "^20.3.1",
    "@types/supertest": "^6.0.0",
    "@typescript-eslint/eslint-plugin": "^8.0.0",
    "@typescript-eslint/parser": "^8.0.0",
    "eslint": "^8.42.0",
    "eslint-config-prettier": "^9.0.0",
    "eslint-plugin-prettier": "^5.0.0",
    "jest": "^29.5.0",
    "prettier": "^3.0.0",
    "source-map-support": "^0.5.21",
    "supertest": "^7.0.0",
    "ts-jest": "^29.1.0",
    "ts-loader": "^9.4.3",
    "ts-node": "^10.9.1",
    "tsconfig-paths": "^4.2.0",
    "typescript": "^5.1.3"
  },

Package versions should be

"dependencies": {
    "@nestjs/common": "^10.4.3",
    "@nestjs/core": "^10.4.3",
    "@nestjs/platform-express": "^10.4.3",
    "reflect-metadata": "^0.2.2",
    "rxjs": "^7.8.1"
  },
  "devDependencies": {
    "@nestjs/cli": "^10.4.5",
    "@nestjs/schematics": "^10.1.4",
    "@nestjs/testing": "^10.4.3",
    "@types/express": "^4.17.21",
    "@types/jest": "^29.5.13",
    "@types/node": "^22.5.5",
    "@types/supertest": "^6.0.2",
    "@typescript-eslint/eslint-plugin": "^8.6.0",
    "@typescript-eslint/parser": "^8.6.0",
    "eslint": "^9.11.0",
    "eslint-config-prettier": "^9.1.0",
    "eslint-plugin-prettier": "^5.2.1",
    "jest": "^29.7.0",
    "prettier": "^3.3.3",
    "source-map-support": "^0.5.21",
    "supertest": "^7.0.0",
    "ts-jest": "^29.2.5",
    "ts-loader": "^9.5.1",
    "ts-node": "^10.9.2",
    "tsconfig-paths": "^4.2.0",
    "typescript": "^5.6.2"
  }

For the default code generated by the nestjs new command.

shvamabps avatar Sep 21 '24 13:09 shvamabps

While the base packages are getting updated, the cli packages are not getting updated.

shvamabps avatar Sep 21 '24 13:09 shvamabps

@shvamabps we got a bunch of PRs open to address that. Those semver ranges are updates by the Renovate bot from time to time

micalevisk avatar Sep 21 '24 14:09 micalevisk

Any update? ESLint v8 version is no longer supported soon.

nesffer avatar Oct 10 '24 00:10 nesffer

We will upgrade that config file in the next major release.

I guess we should downgrade eslint to v8 in the meantime

micalevisk avatar Oct 26 '24 22:10 micalevisk

Is it possible to update the tsconfig file where it enforces and strictly type saves the entire code base. Also, the eslint and prettier config files are modified respectively with the best code practices.

shvamabps avatar Oct 27 '24 11:10 shvamabps

nest new will scaffold a project with eslint^9 but generates .eslintrc.js file which is not compatible with eslint^9.

TaeyoonKwon avatar Nov 01 '24 08:11 TaeyoonKwon

Any tentative date when the upgrade will be released.

shvamabps avatar Nov 05 '24 12:11 shvamabps

@shvamabps there is no ETA

micalevisk avatar Nov 05 '24 12:11 micalevisk

@micalevisk actually the version that is present in the nestjs is a bit old for even the nestjs related packages. The eslint, etc related dev deps and deps are behind the version.

shvamabps avatar Nov 24 '24 05:11 shvamabps

https://github.com/nestjs/schematics/pull/1945

kamilmysliwiec avatar Nov 25 '24 08:11 kamilmysliwiec