Skip to content

Commit feb8482

Browse files
committed
Extended eslint.js config with prettier plugin
1 parent 7ff0c6e commit feb8482

File tree

6 files changed

+404
-172
lines changed

6 files changed

+404
-172
lines changed

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"eslint.enable": true
3+
}

README.md

+23-18
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
---
88

9-
> For now you can find `tslint` and `tsconfig` configurations, but I'm willing to add more tools and scripts in the future e.g. `jest`, `babel`, `eslint`, npm scripts etc.
9+
> For now you can find `eslint`, `tslint` and `tsconfig` configurations, but I'm willing to add more tools and scripts in the future e.g. `jest`, `babel`, npm scripts etc.
1010
11-
> I'm open to suggestion on improvements like adding or changing the rules (especially for ESLint), please feel free to open an issue.
11+
> I'm open to suggestion on improvements like adding or changing default rules so please feel free to open an issue.
1212
1313
---
1414

@@ -34,13 +34,14 @@
3434

3535
## Installation
3636

37-
This package is distributed via npm and
38-
should be installed as one of your project's `devDependencies`:
37+
1. This package is distributed via npm and should be installed as `devDependencies`:
3938

4039
```
4140
npm i -D react-redux-typescript-scripts
4241
```
4342

43+
2. You should also install optional dependencies depending on
44+
4445
## Usage
4546

4647
You can find usage instructions for each tool in it's onw section below.
@@ -57,18 +58,18 @@ You can find usage instructions for each tool in it's onw section below.
5758
```
5859

5960
### TSLint
60-
> NOTE: This package will install all the necessary dependencies except `tslint` so please include it in your project dependencies.
61+
> WARNING: When using this config you need to install `tslint` as dependency in your project.
6162
62-
Following configs are available to extend (you can use one or all by declaring an array in `extends` config property):
63-
- `react-redux-typescript-scripts/tslint.json` - best default config - based on recommended tslint built-in config.
64-
- `react-redux-typescript-scripts/tslint-react.json`- for react projects - based on `tslint-react`.
63+
There are few configs available (you can use one or all by declaring an array in `extends` config property):
64+
- `react-redux-typescript-scripts/tslint.json` - mandatory base config - based on recommended rules.
65+
- `react-redux-typescript-scripts/tslint-react.json`- include react rules - based on `tslint-react`.
6566

6667
#### tslint.json
6768
```ts
6869
{
6970
"extends": [
7071
"react-redux-typescript-scripts/tslint.json",
71-
"react-redux-typescript-scripts/tslint-react.json"
72+
"react-redux-typescript-scripts/tslint-react.json" // optional
7273
],
7374
"rules": {
7475
// you can further customize options here
@@ -77,13 +78,18 @@ Following configs are available to extend (you can use one or all by declaring a
7778
```
7879

7980
### ESLint
80-
> NOTE: This package will install all the necessary dependencies for you except `eslint` so please include it in your project dependencies.
81+
> WARNING: When using this config you need to install `eslint` as dependency in your project.
82+
83+
There are few configs available (you can use one or all by declaring an array in `extends` config property):
84+
- `./node_modules/react-redux-typescript-scripts/eslint.json` - mandatory base config - based on recommended rules.
85+
- `./node_modules/react-redux-typescript-scripts/eslint-prettier.json`- disable eslint formatting rules conflicting with prettier - based on `eslint-config-prettier` _(**WARNING:** Should be the last one in `extends` array)_.
8186

8287
#### .eslintrc
8388
```ts
8489
{
8590
"extends": [
86-
"./node_modules/react-redux-typescript-scripts/eslint.js"
91+
"./node_modules/react-redux-typescript-scripts/eslint.js",
92+
"./node_modules/react-redux-typescript-scripts/eslint-prettier.js" // optional
8793
],
8894
"rules": {
8995
// you can further customize options here
@@ -92,15 +98,14 @@ Following configs are available to extend (you can use one or all by declaring a
9298
```
9399

94100
#### create-react-app
95-
This single change will fully integrate `@typescript-eslint` config with your `create-react-app`:
101+
To fully integrate `@typescript-eslint` with your `create-react-app` add below snippet to your `.eslintrc` or `package.json` under the `eslintConfig` key:
96102
```ts
97103
{
98-
"eslintConfig": {
99-
"extends": [
100-
"react-app",
101-
"./node_modules/react-redux-typescript-scripts/eslint.js"
102-
],
103-
}
104+
"extends": [
105+
"react-app",
106+
"./node_modules/react-redux-typescript-scripts/eslint.js",
107+
"./node_modules/react-redux-typescript-scripts/eslint-prettier.js" // optional
108+
],
104109
}
105110
```
106111

eslint-prettier.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ['prettier', 'prettier/@typescript-eslint'],
3+
};

eslint.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,20 @@ module.exports = {
55
tsconfigRootDir: '.',
66
},
77
plugins: ['@typescript-eslint'],
8-
rules: {},
8+
extends: ['plugin:@typescript-eslint/recommended'],
9+
rules: {
10+
'@typescript-eslint/explicit-function-return-type': 'off',
11+
'@typescript-eslint/no-explicit-any': 'off',
12+
'@typescript-eslint/no-unused-vars': 'off',
13+
},
14+
overrides: [
15+
{
16+
// Disable some rules in unit tests.
17+
files: ['test/**/*.ts', 'test/**/*.tsx', '**/*.spec.ts', '**/*.spec.tsx'],
18+
rules: {
19+
'@typescript-eslint/no-non-null-assertion': 'off',
20+
'@typescript-eslint/no-object-literal-type-assertion': 'off',
21+
},
22+
},
23+
],
924
};

0 commit comments

Comments
 (0)