From 2600a9f9892795b6193358f24ca15bbf761ac8d0 Mon Sep 17 00:00:00 2001 From: Thomas den Hollander Date: Tue, 7 May 2019 02:22:10 +0200 Subject: [PATCH] feat(eslint-plugin): Add new config "eslint-recommended" (#488) --- packages/eslint-plugin/src/configs/README.md | 13 +++++ .../src/configs/eslint-recommended.ts | 49 +++++++++++++++++++ packages/eslint-plugin/src/index.ts | 2 + 3 files changed, 64 insertions(+) create mode 100644 packages/eslint-plugin/src/configs/eslint-recommended.ts diff --git a/packages/eslint-plugin/src/configs/README.md b/packages/eslint-plugin/src/configs/README.md index c9e8d9769f9..3ba76f661e6 100644 --- a/packages/eslint-plugin/src/configs/README.md +++ b/packages/eslint-plugin/src/configs/README.md @@ -6,6 +6,19 @@ These configs exist for your convenience. They contain configuration intended to TODO when all config is added. +## eslint-recommended + +The `eslint-recommended` ruleset is meant to be used after extending `eslint:recommended`. It disables rules that are already checked by the Typescript compiler and enables rules that promote using more the more modern constructs Typescript allows for. + +```cjson +{ + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/eslint-recommended" + ] +} +``` + ## Recommended The recommended set is an **_opinionated_** set of rules that we think you should use because: diff --git a/packages/eslint-plugin/src/configs/eslint-recommended.ts b/packages/eslint-plugin/src/configs/eslint-recommended.ts new file mode 100644 index 00000000000..bef02d9e251 --- /dev/null +++ b/packages/eslint-plugin/src/configs/eslint-recommended.ts @@ -0,0 +1,49 @@ +/** + * The goal of this ruleset is to update the eslint:recommended config to better + * suit Typescript. There are two main reasons to change the configuration: + * 1. The Typescript compiler natively checks some things that therefore don't + * need extra rules anymore. + * 2. Typescript allows for more modern Javascript code that can thus be + * enabled. + */ +export default { + overrides: [ + { + files: ['*.ts', '*.tsx'], + rules: { + /** + * 1. Disable things that are checked by Typescript + */ + //Checked by Typescript - ts(2378) + 'getter-return': false, + // Checked by Typescript - ts(2300) + 'no-dupe-args': false, + // Checked by Typescript - ts(1117) + 'no-dupe-keys': false, + // Checked by Typescript - ts(7027) + 'no-unreachable': false, + // Checked by Typescript - ts(2367) + 'valid-typeof': false, + // Checked by Typescript - ts(2588) + 'no-const-assign': false, + // Checked by Typescript - ts(2588) + 'no-new-symbol': false, + // Checked by Typescript - ts(2376) + 'no-this-before-super': false, + // This is checked by Typescript using the option `strictNullChecks`. + 'no-undef': false, + /** + * 2. Enable more ideomatic code + */ + // Typescript allows const and let instead of var. + 'no-var': 'error', + 'prefer-const': 'error', + // The spread operator/rest parameters should be prefered in Typescript. + 'prefer-rest-params': 'error', + 'prefer-spread': 'error', + // This is already checked by Typescript. + 'no-dupe-class-members': 'error', + }, + }, + ], +}; diff --git a/packages/eslint-plugin/src/index.ts b/packages/eslint-plugin/src/index.ts index a69361543aa..0b63396576a 100644 --- a/packages/eslint-plugin/src/index.ts +++ b/packages/eslint-plugin/src/index.ts @@ -2,6 +2,7 @@ import requireIndex from 'requireindex'; import path from 'path'; import recommended from './configs/recommended.json'; +import eslintRecommended from './configs/eslint-recommended'; const rules = requireIndex(path.join(__dirname, 'rules')); // eslint expects the rule to be on rules[name], not rules[name].default @@ -18,5 +19,6 @@ export = { rules: rulesWithoutDefault, configs: { recommended, + eslintRecommended, }, };