Skip to content

Commit

Permalink
feat(eslint-plugin): Add new config "eslint-recommended" (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasdenH authored and bradzacher committed May 7, 2019
1 parent c3061f9 commit 2600a9f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/eslint-plugin/src/configs/README.md
Expand Up @@ -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:
Expand Down
49 changes: 49 additions & 0 deletions 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',
},
},
],
};
2 changes: 2 additions & 0 deletions packages/eslint-plugin/src/index.ts
Expand Up @@ -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
Expand All @@ -18,5 +19,6 @@ export = {
rules: rulesWithoutDefault,
configs: {
recommended,
eslintRecommended,
},
};

0 comments on commit 2600a9f

Please sign in to comment.