Skip to content

Instantly share code, notes, and snippets.

@tabrez
Created January 29, 2022 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tabrez/080283ba5b56791a6ec320305c54aa16 to your computer and use it in GitHub Desktop.
Save tabrez/080283ba5b56791a6ec320305c54aa16 to your computer and use it in GitHub Desktop.
Microsoft Rush + ESLint + VS Code Setup

Microsoft Rush + ESLint + VS Code Setup

Use the following code in .eslintrc.js in node/backend projects:

// This is a workaround for https://github.com/eslint/eslint/issues/3458
require('@rushstack/eslint-config/patch/modern-module-resolution')

module.exports = {
  extends: [
    '@rushstack/eslint-config/profile/node',
    '@rushstack/eslint-config/mixins/friendly-locals'
  ],
  parserOptions: { tsconfigRootDir: __dirname },

  overrides: [
    /**
     * Override the parser from @rushstack/eslint-config. Since the config is coming
     * from the workspace instead of the external NPM package, the versions of ESLint
     * and TypeScript that the config consumes will be resolved from the devDependencies
     * of the config instead of from the eslint-7-test package. Overriding the parser
     * ensures that the these dependencies come from the eslint-7-test package. See:
     * https://github.com/microsoft/rushstack/issues/3021
     */
    {
      files: ['*.ts', '*.tsx'],
      parser: '@typescript-eslint/parser',
    },
  ],
}

Use the following code in .eslintrc.js in react/front-end projects:

// This is a workaround for https://github.com/eslint/eslint/issues/3458
require('@rushstack/eslint-config/patch/modern-module-resolution')

module.exports = {
  extends: [
    '@rushstack/eslint-config/profile/web-app',
    '@rushstack/eslint-config/mixins/react',
  ],
  parserOptions: { tsconfigRootDir: __dirname },

  settings: {
    react: {
      version: '17.0.2',
    },
  },
  overrides: [
    /**
     * Override the parser from @rushstack/eslint-config. Since the config is coming
     * from the workspace instead of the external NPM package, the versions of ESLint
     * and TypeScript that the config consumes will be resolved from the devDependencies
     * of the config instead of from the eslint-7-test package. Overriding the parser
     * ensures that the these dependencies come from the eslint-7-test package. See:
     * https://github.com/microsoft/rushstack/issues/3021
     */
    {
      files: ['*.ts', '*.tsx'],
      parser: '@typescript-eslint/parser',
    },
  ],
}

Run the following commands in each of the project folders where you added .eslintrc.js:

rush add --dev -p @rushstack/eslint-config
rush add --dev -p @typescript-eslint/parser

Remove/comment out the following config if present in your VS Code settings:

  "eslint.options": {
    "overrideConfigFile": "./.eslintrc.js"
  },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment