cletusw / eslint-plugin-local-rules

A plugin for ESLint that allows you to use project-specific rules
MIT License
158 stars 9 forks source link

Bug: Failed to load plugin 'eslint-plugin-local-rules' #16

Closed dimahinev closed 1 year ago

dimahinev commented 1 year ago
Oops! Something went wrong! :(

ESLint: 8.30.0

Error: Failed to load plugin 'eslint-plugin-local-rules' declared in '.eslintrc.js': eslint-plugin-local-rules: Cannot find "eslint-local-rules{.js,.cjs} or eslint-local-rules/index.js (checked all ancestors of "/Users/dh/code/eslint-test/node_modules/eslint-plugin-local-rules").
    at Object.<anonymous> (/Users/dh/code/eslint-test/node_modules/eslint-plugin-local-rules/index.js:10:9)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32)
    at Module._load (node:internal/modules/cjs/loader:878:12)
    at Module.require (node:internal/modules/cjs/loader:1061:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at ConfigArrayFactory._loadPlugin (/Users/dh/code/eslint-test/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3411:42)
    at /Users/dh/code/eslint-test/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3283:33
    at Array.reduce (<anonymous>)
// ./src/rules/no-console-log.js

module.exports = {
  "no-console-log": {
    create: function(context) {
      return {
        CallExpression: function(node) {
          if (
            node.callee.name === "console" &&
            node.callee.property.name === "log"
          ) {
            context.report({
              node: node,
              message: "Unexpected console.log() call",
            });
          }
        },
      };
    },
  },
};
// ./.eslintrc.js
/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-var-requires */

module.exports = {
  env: {
    browser: true,
    es2021: true,
  },
  extends: [
    "eslint:recommended",
    "plugin:react/recommended",
    "plugin:@typescript-eslint/recommended",
  ],
  overrides: [],
  parser: "@typescript-eslint/parser",
  parserOptions: {
    ecmaVersion: "latest",
    sourceType: "module",
  },
  plugins: ["react", "@typescript-eslint", "eslint-plugin-local-rules"],
  rules: {
    indent: ["warn", 2],
    "linebreak-style": ["error", "unix"],
    quotes: ["error", "double"],
    semi: ["error", "always"],

    "no-unused-vars": "off",
    "@typescript-eslint/no-unused-vars": "error",
    "no-var-requires": "off",
    "local-rules/no-console-log": "error",
  },
};
// package.json
{
  "name": "eslint-test",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "@types/jest": "^27.5.2",
    "@types/node": "^16.18.10",
    "@types/react": "^18.0.26",
    "@types/react-dom": "^18.0.9",
    "eslint-plugin-local-rules": "^1.3.2",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "^2.1.3",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "lint": "eslint . --ext .js,.jsx,.ts,.tsx --rulesdir ./src/rules",
    "lint:fix": "npm run lint -- --fix"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^5.46.1",
    "@typescript-eslint/parser": "^5.46.1",
    "eslint": "^8.30.0",
    "eslint-config-standard-with-typescript": "^24.0.0",
    "eslint-plugin-import": "^2.26.0",
    "eslint-plugin-local": "^1.0.0",
    "eslint-plugin-n": "^15.6.0",
    "eslint-plugin-promise": "^6.1.1",
    "eslint-plugin-react": "^7.31.11",
    "typescript": "^4.9.4"
  }
}
cletusw commented 1 year ago

Hello! Sorry the plugin isn't working for you. Thanks for posting the relevant files.

Correct me if I'm wrong, but it looks like your rules are stored in a file called "./src/rules/no-console-log.js", however this plugin only supports rules in a file called ./eslint-local-rules.js or ./eslint-local-rules/index.js, usually stored in the project root.

If you're not able to change the filename, try one of these other solutions that may work for your case.

Closing for now. Feel free to re-open with additional information if needed. Thanks!

pm0u commented 1 year ago

~I am also having this issue. I copied the example in the readme directly. I would imagine this is related to the fact that it seems to be checking the install directory of eslint-plugin-local-rules for the file eslint-local-rules.js as you can see from the logs shared.~

Nevermind my issue is related to yarn workspaces.

cletusw commented 1 year ago

@pm0u Just added yarn/npm/pnpm workspace support. Check out v2.0.0 and let me know if you're still having issues!