EvgenyOrekhov / eslint-config-hardcore

The most strict (yet practical) ESLint config. 53 plugins. 1342 rules. React, Vue, Node, and pure JS/TS.
https://www.npmjs.com/package/eslint-config-hardcore
MIT License
416 stars 13 forks source link

Failed to load config "hardcode/ts" to extend from. #834

Closed Aplietexe closed 10 months ago

Aplietexe commented 11 months ago

package.json:

{
  "name": "webapp",
  "version": "0.1.0",
  "private": true,
  "engines": {
    "node": ">=18.18.2",
    "pnpm": ">=8.9.2",
    "npm": "please-use-pnpm",
    "yarn": "please-use-pnpm"
  },
  "scripts": {
    "build": "next build",
    "db:push": "prisma db push",
    "db:studio": "prisma studio",
    "dev": "next dev",
    "postinstall": "prisma generate",
    "lint": "next lint",
    "start": "next start"
  },
  "dependencies": {
    "@prisma/client": "^5.5.2",
    "@t3-oss/env-nextjs": "^0.7.1",
    "@tanstack/react-query": "^4.32.6",
    "@trpc/client": "^10.42.0",
    "@trpc/next": "^10.42.0",
    "@trpc/react-query": "^10.42.0",
    "@trpc/server": "^10.42.0",
    "next": "^13.5.6",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "superjson": "^1.13.1",
    "zod": "^3.22.4"
  },
  "devDependencies": {
    "@types/eslint": "^8.44.6",
    "@types/node": "^18.18.2",
    "@types/react": "^18.2.32",
    "@types/react-dom": "^18.2.14",
    "@typescript-eslint/eslint-plugin": "^6.9.0",
    "@typescript-eslint/parser": "^6.9.0",
    "autoprefixer": "^10.4.16",
    "eslint": "^8.52.0",
    "eslint-config-hardcore": "^41.3.0",
    "eslint-config-next": "^13.5.6",
    "eslint-plugin-sort-keys-fix": "^1.1.2",
    "eslint-plugin-typescript-sort-keys": "^3.1.0",
    "postcss": "^8.4.31",
    "prettier": "^3.0.3",
    "prettier-plugin-tailwindcss": "^0.5.6",
    "prisma": "^5.5.2",
    "tailwindcss": "^3.3.5",
    "typescript": "^5.1.6"
  },
  "ct3aMetadata": {
    "initVersion": "7.22.0"
  },
  "packageManager": "pnpm@8.9.2"
}

Relevant .eslintrc.cjs:

/** @type {import("eslint").Linter.Config} */
module.exports = {
  extends: [
    "hardcore",
    "hardcore/react",
    "hardcore/ts",
    "next/core-web-vitals",
  ],

  parser: "@typescript-eslint/parser",

  parserOptions: {
    project: true,
  },

  plugins: ["@typescript-eslint", "sort-keys-fix", "typescript-sort-keys"],

  rules: {
    ...generalRules,
    ...typescriptRules,
    ...componentRules,
  },
}

Upon running pnpm lint, I get

❯ pnpm lint
> webapp@0.1.0 lint /home/pietro/code/webapp
> next lint

Failed to load config "hardcode/ts" to extend from.
Referenced from: /home/pietro/code/webapp/.eslintrc.cjs
 ELIFECYCLE  Command failed with exit code 1.

Replacing hardcore/ts with ./node_modules/eslint-config-hardcore/ts.json works as a workaround.

EvgenyOrekhov commented 11 months ago

Does it work if you run npx eslint .?

EvgenyOrekhov commented 10 months ago

I'm assuming you don't have eslint as a top-level dependency, but eslint-config-hardcore is at the top level. So next lint ends up calling eslint somewhere deeper, like at node_modules/next/node_modules/eslint, and it can't see node_modules/eslint-config-hardcore/. You should try to install eslint as a top-level dependency, and call it directly: eslint . instead of next lint.

Aplietexe commented 10 months ago

npx eslint . worked, and now pnpm lint loads the config properly. I already had eslint as a top-level dependency.

EvgenyOrekhov commented 10 months ago

Must be that pnpm lint/next lint wasn't using the top-level eslint version. This might happen sometimes, when Next.js requires an older version of ESLint. In that case I recommend updating dependencies, including the deep ones (I usually do it via rm -rf node_modules package-lock.json && npm install).