Skip to content

Add eslint-recommended #488

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

Merged
merged 4 commits into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/eslint-plugin/src/configs/README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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,
},
};