Skip to content
The Chat Archive
Geminigemini-2.5-flash· Google LMArena Human Preference 140K

so, in another instance I have packages/eslint-config, do I import this config alone…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.5-flash-lite-preview-06-17-thinking’s answer.
  1. User

    so, in another instance I have packages/eslint-config, do I import this config alone into my other apps without needing to import the eslint packages and plugins if I am not modifying the existing eslint-config right?

  2. Assistant

    You've hit on a common point of confusion in monorepos, and it's a great question!

    The short answer is: Yes, you still need to install ESLint itself and any plugins/parsers that are referenced by your packages/eslint-config within your monorepo's root.

    Here's why and how:

    Why you still need to install them

    1. ESLint is the "Runner": Your packages/eslint-config simply exports a configuration object (rules, plugins to use, parsers). It doesn't contain the ESLint executable or the logic to run linting. For ESLint to run, the eslint package itself must be present and discoverable.

    2. Plugins and Parsers are separate packages: When your eslint-config says plugins: ['@typescript-eslint', 'react'] or parser: '@typescript-eslint/parser', ESLint expects to find these specific npm packages in the node_modules where it's being run. Your config package simply references them; it doesn't include their code. They are separate dependencies.

    Best approach for a Bun Monorepo

    The best practice for a monorepo is to install eslint and all the common plugins/parsers your eslint-config uses at the root level of your monorepo. This allows all your workspaces to share these dependencies, leveraging Bun's hoisting capabilities.

    1. Install ESLint and Plugins at the Monorepo Root:

    In your monorepo's root package.json, add all the ESLint-related packages as devDependencies:

    // monorepo-root/package.json
    {
      "name": "my-monorepo",
      "private": true,
      "workspaces": [
        "app/*",
        "packages/*"
      ],
      "devDependencies": {
        "eslint": "^8.x.x", // The core ESLint package
        "prettier": "^3.x.x", // If you integrate Prettier
        "@typescript-eslint/eslint-plugin": "^6.x.x", // For TypeScript rules
        "@typescript-eslint/parser": "^6.x.x",       // For parsing TypeScript
        "eslint-config-prettier": "^9.x.x",        // Disables ESLint rules that conflict with Prettier
        "eslint-plugin-prettier": "^5.x.x",        // Runs Prettier as an ESLint rule
        "eslint-plugin-react": "^7.x.x",           // For React specific rules (if app/web uses React)
        "eslint-plugin-react-hooks": "^4.x.x",     // For React Hooks rules
        "eslint-plugin-jsx-a11y": "^6.x.x",        // For accessibility rules
        // ... any other plugins your config uses
        "typescript": "^5.x.x" // TypeScript itself, as discussed previously
      }
    }
    

    Then run bun install in the root. Bun will hoist these dependencies to the root node_modules.

    2. Your packages/eslint-config:

    This package will contain your shared ESLint rules. Its package.json should declare the ESLint packages it uses as peerDependencies. This informs users (or in this case, your other workspaces) that they need to provide these dependencies themselves.

    // packages/eslint-config/package.json
    {
      "name": "@my-org/eslint-config", // Use a scope for clarity if you wish
      "version": "1.0.0",
      "main": "index.js",
      "private": true, // Since it's internal to your monorepo
      "peerDependencies": {
        "eslint": ">=8",
        "@typescript-eslint/eslint-plugin": ">=6",
        "@typescript-eslint/parser": ">=6",
        "eslint-plugin-react": ">=7",
        "eslint-plugin-react-hooks": ">=4",
        "eslint-plugin-jsx-a11y": ">=6",
        "eslint-config-prettier": ">=9",
        "eslint-plugin-prettier": ">=5",
        "prettier": ">=3"
        // List all packages your config *uses* here
      },
      "devDependencies": {
        // These are only for the eslint-config package itself to run tests or lint itself
        // You can copy them from the root devDependencies here if you want to test the config independently.
        // Otherwise, for monorepo internal usage, you might not strictly need them here if all testing is done via the root.
        "eslint": "^8.x.x",
        "@typescript-eslint/eslint-plugin": "^6.x.x",
        // ... etc.
      }
    }
    

    And your index.js (or .eslintrc.js) in packages/eslint-config:

    // packages/eslint-config/index.js (or .eslintrc.js)
    module.exports = {
      extends: [
        "eslint:recommended",
        "plugin:@typescript-eslint/recommended",
        "plugin:react/recommended",
        "plugin:react-hooks/recommended",
        "plugin:jsx-a11y/recommended",
        "prettier", // Must be last to turn off conflicting rules
      ],
      parser: "@typescript-eslint/parser",
      plugins: ["@typescript-eslint", "react", "react-hooks", "jsx-a11y", "prettier"],
      env: {
        browser: true,
        node: true,
        es2022: true,
      },
      settings: {
        react: {
          version: "detect", // Automatically detect React version
        },
      },
      rules: {
        "prettier/prettier": "error",
        // Your custom rules here
        "@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
        // ...
      },
      // Ensure rules are applied to specific file types
      overrides: [
        {
          files: ["*.ts", "*.tsx"],
          parserOptions: {
            project: ["./tsconfig.json"], // Or your specific tsconfig file if different
          },
        },
      ],
    };
    

    3. Reference the Config in your Apps/Packages:

    In app/web, app/api, packages/api-client, etc., you need to:

    • Add the eslint-config package as a devDependency:

      // app/web/package.json
      {
        "name": "app-web",
        // ...
        "devDependencies": {
          "@my-org/eslint-config": "workspace:^1.0.0" // Reference your internal package
        }
      }
      

      Run bun install in app/web (or at the root again).

    • Create a .eslintrc.js file:

      // app/web/.eslintrc.js
      module.exports = {
        root: true, // Stops ESLint from looking for configs in parent directories
        extends: [
          "@my-org/eslint-config", // This is how you reference your shared config
          // Add any workspace-specific configs or overrides here
        ],
        // Add workspace-specific settings or rules overrides
        rules: {
          // e.g., if app/web has specific React rules
        }
      };
      

      If you don't use a scope for your eslint-config package, it would be extends: ["eslint-config"] if packages/eslint-config/package.json has name: "eslint-config".

    Summary of Benefits

    • Single Source of Truth: All ESLint versions and primary plugins are managed in one place (root package.json).
    • Reduced Duplication: Bun hoists dependencies, meaning fewer node_modules folders and less disk space.
    • Consistency: All your workspaces automatically use the same ESLint configuration and versions of the tools.
    • Simplicity: Workspace package.json files are cleaner, only listing their unique dependencies and the shared config.

    This setup gives you a very robust and maintainable linting strategy for your Bun monorepo.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.