From 70e3645f2c9abaa09e2d208536413f11694ce7e0 Mon Sep 17 00:00:00 2001 From: Thomas den Hollander Date: Tue, 30 Apr 2019 12:38:46 +0200 Subject: [PATCH 1/3] Add eslint-recommended --- packages/eslint-plugin/src/configs/README.md | 13 ++++++ .../src/configs/eslint-recommended.yml | 41 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 packages/eslint-plugin/src/configs/eslint-recommended.yml 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.yml b/packages/eslint-plugin/src/configs/eslint-recommended.yml new file mode 100644 index 00000000000..610013b3f23 --- /dev/null +++ b/packages/eslint-plugin/src/configs/eslint-recommended.yml @@ -0,0 +1,41 @@ +# 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. +overrides: + - files: ['*.ts', '*.tsx'] + rules: + # + # 1. Disable things that are checked by Typescript + # + # Checked by Typescript - ts(2378) + getter-return: off + # Checked by Typescript - ts(2300) + no-dupe-args: off + # Checked by Typescript - ts(1117) + no-dupe-keys: off + # Checked by Typescript - ts(7027) + no-unreachable: off + # Checked by Typescript - ts(2367) + valid-typeof: off + # Checked by Typescript - ts(2588) + no-const-assign: off + # Checked by Typescript - ts(2588) + no-new-symbol: off + # Checked by Typescript - ts(2376) + no-this-before-super: off + # This is checked by Typescript using the option `strictNullChecks`. + no-undef: off + # + # 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 From 4c546940df84ce56d72cff07a5165a4e2a1d5230 Mon Sep 17 00:00:00 2001 From: Thomas den Hollander Date: Thu, 2 May 2019 15:56:40 +0200 Subject: [PATCH 2/3] Change yml to js --- .../src/configs/eslint-recommended.js | 52 +++++++++++++++++++ .../src/configs/eslint-recommended.yml | 41 --------------- 2 files changed, 52 insertions(+), 41 deletions(-) create mode 100644 packages/eslint-plugin/src/configs/eslint-recommended.js delete mode 100644 packages/eslint-plugin/src/configs/eslint-recommended.yml diff --git a/packages/eslint-plugin/src/configs/eslint-recommended.js b/packages/eslint-plugin/src/configs/eslint-recommended.js new file mode 100644 index 00000000000..2ccbaf27b6c --- /dev/null +++ b/packages/eslint-plugin/src/configs/eslint-recommended.js @@ -0,0 +1,52 @@ +/** + * 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. + */ +module.exports = { + "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/configs/eslint-recommended.yml b/packages/eslint-plugin/src/configs/eslint-recommended.yml deleted file mode 100644 index 610013b3f23..00000000000 --- a/packages/eslint-plugin/src/configs/eslint-recommended.yml +++ /dev/null @@ -1,41 +0,0 @@ -# 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. -overrides: - - files: ['*.ts', '*.tsx'] - rules: - # - # 1. Disable things that are checked by Typescript - # - # Checked by Typescript - ts(2378) - getter-return: off - # Checked by Typescript - ts(2300) - no-dupe-args: off - # Checked by Typescript - ts(1117) - no-dupe-keys: off - # Checked by Typescript - ts(7027) - no-unreachable: off - # Checked by Typescript - ts(2367) - valid-typeof: off - # Checked by Typescript - ts(2588) - no-const-assign: off - # Checked by Typescript - ts(2588) - no-new-symbol: off - # Checked by Typescript - ts(2376) - no-this-before-super: off - # This is checked by Typescript using the option `strictNullChecks`. - no-undef: off - # - # 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 From f3e510605198ee811c04026fc0a51f5edfc8524f Mon Sep 17 00:00:00 2001 From: Thomas den Hollander Date: Thu, 2 May 2019 22:20:41 +0200 Subject: [PATCH 3/3] feat: change js to ts --- ...t-recommended.js => eslint-recommended.ts} | 49 +++++++++---------- packages/eslint-plugin/src/index.ts | 2 + 2 files changed, 25 insertions(+), 26 deletions(-) rename packages/eslint-plugin/src/configs/{eslint-recommended.js => eslint-recommended.ts} (61%) diff --git a/packages/eslint-plugin/src/configs/eslint-recommended.js b/packages/eslint-plugin/src/configs/eslint-recommended.ts similarity index 61% rename from packages/eslint-plugin/src/configs/eslint-recommended.js rename to packages/eslint-plugin/src/configs/eslint-recommended.ts index 2ccbaf27b6c..bef02d9e251 100644 --- a/packages/eslint-plugin/src/configs/eslint-recommended.js +++ b/packages/eslint-plugin/src/configs/eslint-recommended.ts @@ -6,47 +6,44 @@ * 2. Typescript allows for more modern Javascript code that can thus be * enabled. */ -module.exports = { - "overrides": [ +export default { + overrides: [ { - "files": [ - "*.ts", - "*.tsx" - ], - "rules": { + files: ['*.ts', '*.tsx'], + rules: { /** - * 1. Disable things that are checked by Typescript - */ + * 1. Disable things that are checked by Typescript + */ //Checked by Typescript - ts(2378) - "getter-return": false, + 'getter-return': false, // Checked by Typescript - ts(2300) - "no-dupe-args": false, + 'no-dupe-args': false, // Checked by Typescript - ts(1117) - "no-dupe-keys": false, + 'no-dupe-keys': false, // Checked by Typescript - ts(7027) - "no-unreachable": false, + 'no-unreachable': false, // Checked by Typescript - ts(2367) - "valid-typeof": false, + 'valid-typeof': false, // Checked by Typescript - ts(2588) - "no-const-assign": false, + 'no-const-assign': false, // Checked by Typescript - ts(2588) - "no-new-symbol": false, + 'no-new-symbol': false, // Checked by Typescript - ts(2376) - "no-this-before-super": false, + 'no-this-before-super': false, // This is checked by Typescript using the option `strictNullChecks`. - "no-undef": false, + 'no-undef': false, /** * 2. Enable more ideomatic code */ // Typescript allows const and let instead of var. - "no-var": "error", - "prefer-const": "error", + 'no-var': 'error', + 'prefer-const': 'error', // The spread operator/rest parameters should be prefered in Typescript. - "prefer-rest-params": "error", - "prefer-spread": "error", + 'prefer-rest-params': 'error', + 'prefer-spread': 'error', // This is already checked by Typescript. - "no-dupe-class-members": "error" - } - } - ] + '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, }, };