Skip to content
This repository was archived by the owner on Nov 18, 2024. It is now read-only.

Commit 83b3637

Browse files
committed
Configure ESLint
1 parent 8965e78 commit 83b3637

File tree

10 files changed

+322
-17
lines changed

10 files changed

+322
-17
lines changed

.eslintrc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"extends": [
3+
"amo",
4+
"plugin:amo/recommended",
5+
"plugin:jest/recommended",
6+
"plugin:@typescript-eslint/recommended"
7+
],
8+
"globals": {
9+
"document": true
10+
},
11+
"parser": "@typescript-eslint/parser",
12+
"rules": {
13+
// TS configuration for the `indent` rule.
14+
// https://github.com/typescript-eslint/typescript-eslint/blob/5b0b3d9edbcb3ab588a34c431037d9deece30824/packages/eslint-plugin/docs/rules/indent.md#options
15+
"indent": "off",
16+
"@typescript-eslint/indent": ["error", 2],
17+
"import/no-extraneous-dependencies": ["error", {
18+
"devDependencies": ["**/*.test.*"]
19+
}
20+
],
21+
// We use `.tsx` instead of `.jsx` for files with JSX inside.
22+
"react/jsx-filename-extension": ["error", {
23+
"extensions": [".tsx"]
24+
}
25+
],
26+
// We decided to prefer types over interfaces.
27+
"@typescript-eslint/prefer-interface": "off",
28+
"@typescript-eslint/explicit-member-accessibility": "off"
29+
},
30+
"settings": {
31+
"import/resolver": {
32+
"node": {
33+
"extensions": [".js", ".ts", ".tsx"]
34+
}
35+
}
36+
}
37+
}

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ jobs:
4040
- name: prettier
4141
<<: *node-prod
4242
script: yarn prettier-ci
43+
- name: linter (node@production)
44+
<<: *node-prod
45+
script: yarn lint

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ See the section about [deployment](https://facebook.github.io/create-react-app/d
4545

4646
This runs the [eject](https://facebook.github.io/create-react-app/docs/available-scripts#npm-run-eject) command. Hopefully we won't ever need this 😭
4747

48+
### `yarn eslint`
49+
50+
This runs [ESLint][] to discover problems within our codebase without executing it and it enforces some patterns and practices.
51+
52+
### `yarn lint`
53+
54+
This runs all the _lint_ commands at once.
55+
4856
### `yarn prettier`
4957

5058
This runs [Prettier][] to automatically format the entire codebase.
@@ -83,3 +91,4 @@ To learn React, check out the [React documentation](https://reactjs.org/).
8391

8492
[prettier]: https://prettier.io/
8593
[typescript]: https://www.typescriptlang.org/
94+
[eslint]: https://eslint.org/

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,24 @@
2525
"devDependencies": {
2626
"@types/enzyme": "^3.1.15",
2727
"@types/enzyme-adapter-react-16": "^1.0.3",
28+
"@typescript-eslint/eslint-plugin": "^1.1.1",
29+
"@typescript-eslint/parser": "^1.1.1",
2830
"codecov": "^3.1.0",
2931
"enzyme": "^3.8.0",
3032
"enzyme-adapter-react-16": "^1.7.1",
31-
"jest-enzyme": "7.0.1",
33+
"eslint": "^5.12.1",
34+
"eslint-config-amo": "^1.10.0",
35+
"eslint-plugin-amo": "^1.9.1",
36+
"jest-enzyme": "^7.0.1",
3237
"prettier": "1.16.1",
3338
"pretty-quick": "^1.8.1",
3439
"type-coverage": "^1.6.2"
3540
},
3641
"scripts": {
3742
"build": "react-scripts build",
3843
"eject": "react-scripts eject",
44+
"eslint": "eslint --ext .js --ext tsx src/",
45+
"lint": "yarn eslint",
3946
"prettier": "prettier --write '**'",
4047
"prettier-ci": "prettier --list-different '**' || (echo '\n\nThis failure means you did not run `yarn prettier-dev` before committing\n\n' && exit 1)",
4148
"prettier-dev": "pretty-quick --branch master",
@@ -45,9 +52,6 @@
4552
"type-coverage": "type-coverage",
4653
"typecheck": "tsc"
4754
},
48-
"eslintConfig": {
49-
"extends": "react-app"
50-
},
5155
"browserslist": [
5256
">0.2%",
5357
"not dead",

src/components/App/index.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React from 'react';
22
import { shallow } from 'enzyme';
33

4-
import App from '.';
54
import styles from './styles.module.scss';
65
import configureStore from '../../configureStore';
76

7+
import App from '.';
8+
89
it('renders without crashing', () => {
910
const store = configureStore();
1011
// TODO: Use shallowUntilTarget()

src/components/App/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class App extends React.Component<
3434
<button
3535
onClick={this.handleToggleClick}
3636
style={{ padding: '32px' }}
37+
type="button"
3738
>
3839
{toggledOn ? 'OFF' : 'ON'}
3940
</button>

src/configureStore.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
import { Dispatch, Action, AnyAction } from 'redux';
2-
import { Store, applyMiddleware, combineReducers, createStore } from 'redux';
1+
import {
2+
Action,
3+
AnyAction,
4+
Dispatch,
5+
Reducer,
6+
Store,
7+
applyMiddleware,
8+
combineReducers,
9+
createStore,
10+
} from 'redux';
311
import { composeWithDevTools } from 'redux-devtools-extension';
412
import { createLogger } from 'redux-logger';
513

@@ -13,7 +21,7 @@ export type ApplicationState = {
1321
example: ExampleState;
1422
};
1523

16-
const createRootReducer = () => {
24+
const createRootReducer = (): Reducer<ApplicationState> => {
1725
return combineReducers<ApplicationState>({ example });
1826
};
1927

src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* global: document */
12
import React from 'react';
23
import ReactDOM from 'react-dom';
34
import { BrowserRouter } from 'react-router-dom';

src/reducers/example.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type TogglePayload = {};
55

66
export const actions = {
77
toggle: createAction('TOGGLE', (resolve) => {
8-
return () => resolve({} as TogglePayload);
8+
return () => resolve({});
99
}),
1010
};
1111

0 commit comments

Comments
 (0)