Skip to content

[@typescript-eslint/indent] Use config of ESLint built-in "indent" rule when no config exists for typescript counterpart #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
evangalen opened this issue Feb 13, 2019 · 1 comment
Labels
duplicate This issue or pull request already exists package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@evangalen
Copy link

In our .eslintrc.js we use the configuration of 'airbnb-base' that enables and configures the ESLint built-in rules of "camelcase", "indent", "no-array-constructor" and "no-unused-vars".

To ensure that we don't get double rule violations (on for the ESLint build-in and the TypeScript counterpart),
we deliberately place 'plugin:@typescript-eslint/recommended' after 'airbnb-base':

module.exports = {
  extends: [
    'eslint:recommended',
    'airbnb-base',

    // placed after 'airbnb-base' so that enabled rules are replaced with TypeScript specific ones
    'plugin:@typescript-eslint/recommended',
  ],
  // ...
};

Problem with this approach is that @typescript-eslint/eslint-plugin will use a different configuration as the for the ESLint built-in rules of "camelcase", "indent", "no-array-constructor" and "no-unused-vars".

So I was wondering if it wouldn't be possible that @typescript-eslint/eslint-plugin uses the configuration of ESLint built-in rules in case no explicit configuration exists for the TypeScript counterparts.

Right now, we had to work around the problem by explicitlty require-ing the rules of the "eslint-config-airbnb-base" module and then re-configure them using the imported rule config:

const airbnbImportsRules = require('eslint-config-airbnb-base/rules/imports').rules;
const airbnbStyleRules = require('eslint-config-airbnb-base/rules/style').rules;
const airbnbVariablesRules = require('eslint-config-airbnb-base/rules/variables').rules;

module.exports = {
  extends: [
    'eslint:recommended',
    'airbnb-base',

    // placed after 'airbnb-base' so that enabled rules are replaced with TypeScript specific ones
    'plugin:@typescript-eslint/recommended',
  ],
  plugins: ['@typescript-eslint'],
  settings: {
    'import/resolver': {
      'webpack': {
        config: path.join(__dirname, 'webpack.config.prod.js'),
      }
    },
  },
  env: {
    browser: true,
    es6: true,
  },
  parser: '@typescript-eslint/parser',
  parserOptions: {
    'project': './tsconfig.json'
  },
  rules: {
    // ...

    // configure TypeScript counterpart rules with the original airbnb rule configuration
    '@typescript-eslint/camelcase': airbnbStyleRules.camelcase,
    '@typescript-eslint/indent': airbnbStyleRules.indent,
    '@typescript-eslint/no-array-constructor': airbnbStyleRules['no-array-constructor'],
    '@typescript-eslint/no-unused-vars': airbnbVariablesRules['no-unused-vars'],

    // ...
  },
};
@evangalen evangalen added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Feb 13, 2019
@bradzacher bradzacher added duplicate This issue or pull request already exists and removed triage Waiting for team members to take a look labels Feb 13, 2019
@bradzacher
Copy link
Member

Duplicate of #265

@bradzacher bradzacher marked this as a duplicate of #265 Feb 13, 2019
@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators Feb 21, 2020
Luckeu pushed a commit to Luckeu/typescript-eslint that referenced this issue Jun 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

2 participants