-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[@typescript-eslint/camelcase] Use config of ESLint built-in "camelcase" rule when no config exists for typescript counterpart #265
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
Comments
AFAIK this is not possible. The base eslint rule Additionally, as part of the recommended config we disable the base eslint rule so that you don't get doubled errors. This means that even if eslint provided a mechanism for us to easily interrogate the entire workspace's config, we wouldn't be able to get the setting from airbnb's config, because it's been overwritten to be off. |
This could be resolved by Airbnb providing a special TypeScript config that disables the core rules and enables ours according to their standards. |
It would be awesome if this plugin would work for all ESLint shared configs, without any configuration required. There are a lot of rules (okay, maybe not so many right now, but that can of course change in the future) that are a duplication of core rules (like It doesn't look like it's possible to override a rule in ESLint right now, but maybe it can be made possible by including such a feature in ESLint core. I think it would be most user friendly if you would only need to define a parser and plugin, and the plugin will handle the rest; as in, making sure that all the ESLint rules work, so by replacing them with a Typescript specific one if necessary. |
I'm going to close this as there's nothing we can do from within the plugin. If you have possible solutions to this problem, feel free to raise them in https://github.com/eslint/rfcs. Note that there's eslint/rfcs#9 which might help deal with this. |
I fixed it. (A temporary measure) const airbnbBaseStyleRules = require('eslint-config-airbnb-base/rules/style').rules;
const airbnbBaseVariablesRules = require('eslint-config-airbnb-base/rules/variables').rules;
const airbnbBaseStyleRules = require('eslint-config-airbnb-base/rules/style').rules;
const airbnbBaseVariablesRules = require('eslint-config-airbnb-base/rules/variables').rules;
module.exports = {
extends: ['airbnb'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
},
},
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
},
env: {
browser: true,
es6: true,
jest: true,
},
rules: {
'react/jsx-filename-extension': [1, { extensions: ['.jsx', '.tsx'] }],
},
overrides: [
{
files: ['*.ts', '*.tsx'],
rules: {
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/src/configs/recommended.json
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/array-type': 'error',
'@typescript-eslint/ban-types': 'error',
camelcase: 'off',
'@typescript-eslint/camelcase': airbnbBaseStyleRules.camelcase,
'@typescript-eslint/class-name-casing': 'error',
'@typescript-eslint/explicit-function-return-type': 'error',
'@typescript-eslint/explicit-member-accessibility': 'error',
indent: 'off',
'@typescript-eslint/indent': airbnbBaseStyleRules.indent,
'@typescript-eslint/interface-name-prefix': 'error',
'@typescript-eslint/member-delimiter-style': 'error',
'@typescript-eslint/no-angle-bracket-type-assertion': 'error',
'no-array-constructor': 'off',
'@typescript-eslint/no-array-constructor': airbnbBaseStyleRules['no-array-constructor'],
'@typescript-eslint/no-empty-interface': 'error',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-inferrable-types': 'error',
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-namespace': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/no-object-literal-type-assertion': 'error',
'@typescript-eslint/no-parameter-properties': 'error',
'@typescript-eslint/no-triple-slash-reference': 'error',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': airbnbBaseVariablesRules['no-unused-vars'],
'@typescript-eslint/no-use-before-define': 'error',
'@typescript-eslint/no-var-requires': 'error',
'@typescript-eslint/prefer-interface': 'error',
'@typescript-eslint/prefer-namespace-keyword': 'error',
'@typescript-eslint/type-annotation-spacing': 'error',
},
},
],
}; or const airbnbBaseStyleRules = require('eslint-config-airbnb-base/rules/style').rules;
const airbnbBaseVariablesRules = require('eslint-config-airbnb-base/rules/variables').rules;
module.exports = {
extends: ['airbnb', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
},
},
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
},
env: {
browser: true,
es6: true,
jest: true,
},
rules: {
'react/jsx-filename-extension': [1, { extensions: ['.jsx', '.tsx'] }],
},
overrides: [
{
files: ['*.ts', '*.tsx'],
extends: ['airbnb', 'plugin:@typescript-eslint/recommended'],
rules: {
'react/jsx-filename-extension': [1, { extensions: ['.jsx', '.tsx'] }],
complexity: ['error', { max: 10 }],
'max-lines': ['error', { max: 100, skipBlankLines: true, skipComments: true }],
'max-depth': ['error', 2],
'import/no-extraneous-dependencies': 'off',
// https://github.com/typescript-eslint/typescript-eslint/issues/265
'@typescript-eslint/camelcase': airbnbBaseStyleRules.camelcase,
'@typescript-eslint/indent': airbnbBaseStyleRules.indent,
'@typescript-eslint/no-array-constructor': airbnbBaseStyleRules['no-array-constructor'],
'@typescript-eslint/no-unused-vars': airbnbBaseVariablesRules['no-unused-vars'],
},
}
]
}; |
@vomvoru Good to hear you 'fixed' it. |
Oh, I just found out that the code is the same. |
I had an idea about this problem in another thread #36 (comment) |
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'
: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:The text was updated successfully, but these errors were encountered: