Change ESLint Version

Run the following on a component that uses your env, to get the ESLint version currently being used:

$bit
Copiedcopy

The out is similar to the following:

teambit.defender/linter

configured linter: eslint-linter (ESlint @ 7.32.0)

To provide your ESLint linter with a different version of ESLint, implement the linter env handler and replace your ESLint build task:

/* @filename: my-env.bit-env.ts */

/* your base env */
import { ReactEnv } from '@teambit/react.react-env';
import type { ReactEnvInterface } from '@teambit/react.react-env';

import { ESLintLinter, EslintTask } from '@teambit/defender.eslint-linter';
import { ESLint as ESLintLib } from 'eslint';

export class MyEnv extends ReactEnv implements ReactEnvInterface {
  constructor() {
    super();
  }

  name = 'my-env';

  /**
   * replace the default linter
   */
  linter() {
    return ESLintLinter.from({
      /**
       * use the eslint instance this env has as a dependency
       */
      eslint: ESLintLib,
    });
  }

  build() {
    return super.build().replace([
      /**
       * replace the default eslint build task with this build task
       */
      EslintTask.from({
        /**
         * use the eslint version this env has as a dependency
         */
        eslint: ESLintLib,
      }),
    ]);
  }
}

export default new MyEnv();
CopiedCopy

Install the version of ESLint you want to use:

$bit
Copiedcopy
See command synopsis

ESLint is automatically detected as a dependency of that env. By default, dependencies are resolved to the ones installed in that workspace.

Run the following to compile your env:

$bit
Copiedcopy
See command synopsis