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

Commit 257ef90

Browse files
committed
more fixes
1 parent 1e60710 commit 257ef90

File tree

12 files changed

+39
-40
lines changed

12 files changed

+39
-40
lines changed

.eslintrc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
"amo",
44
"plugin:amo/typescript",
55
"plugin:jest/recommended",
6-
"plugin:@typescript-eslint/recommended"
6+
"plugin:@typescript-eslint/recommended",
77
],
8+
"env": {
9+
"browser": true,
10+
},
811
"rules": {
912
// TS configuration for the `indent` rule.
1013
// https://github.com/typescript-eslint/typescript-eslint/blob/5b0b3d9edbcb3ab588a34c431037d9deece30824/packages/eslint-plugin/docs/rules/indent.md#options
@@ -30,6 +33,11 @@
3033
"react/jsx-one-expression-per-line": "off",
3134
// Report an error when a variable is not used.
3235
"@typescript-eslint/no-unused-vars": "error",
36+
// The beauty of TS is that it infers types quite well, so let's not write
37+
// too much code.
38+
"@typescript-eslint/explicit-function-return-type": "off",
39+
// TODO: re-enable this rule once https://github.com/mozilla/addons-code-manager/issues/85 lands.
40+
"amo/only-log-strings": "off",
3341
},
3442
"settings": {
3543
"import/resolver": {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"bootstrap": "4.2.1",
1515
"express": "4.16.4",
1616
"http-proxy-middleware": "0.19.1",
17-
"http-proxy-response-rewrite": "^0.0.1",
17+
"http-proxy-response-rewrite": "0.0.1",
1818
"node-sass": "4.11.0",
1919
"react": "16.7.0",
2020
"react-bootstrap": "1.0.0-beta.5",
@@ -57,7 +57,7 @@
5757
"build": "react-scripts build",
5858
"dev": "cat .env.common-local .env.dev > .env.local && yarn start-dev",
5959
"eject": "react-scripts eject",
60-
"eslint": "eslint --ext .js --ext tsx src/",
60+
"eslint": "eslint --ext js --ext tsx src/",
6161
"lint": "yarn eslint",
6262
"prettier": "prettier --write '**'",
6363
"prettier-ci": "prettier --list-different '**' || (echo '\n\nThis failure means you did not run `yarn prettier-dev` before committing\n\n' && exit 1)",

src/api/index.spec.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
/* global fetch, fetchMock */
1+
/* global fetchMock */
22
import {
3-
ApiState,
43
actions as apiActions,
54
initialState as defaultApiState,
65
} from '../reducers/api';
@@ -9,7 +8,7 @@ import configureStore from '../configureStore';
98
import { HttpMethod, callApi, logOutFromServer } from '.';
109

1110
describe(__filename, () => {
12-
const getApiState = ({ authToken = '12345' } = {}): ApiState => {
11+
const getApiState = ({ authToken = '12345' } = {}) => {
1312
const store = configureStore();
1413

1514
store.dispatch(apiActions.setAuthToken({ authToken }));
@@ -19,7 +18,7 @@ describe(__filename, () => {
1918
};
2019

2120
describe('callApi', () => {
22-
const callApiWithDefaultApiState = (params = {}): object => {
21+
const callApiWithDefaultApiState = (params = {}) => {
2322
return callApi({ apiState: defaultApiState, endpoint: '/', ...params });
2423
};
2524

src/api/index.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* global fetch */
21
import { ApiState } from '../reducers/api';
32

43
export enum HttpMethod {
@@ -28,13 +27,12 @@ export const callApi = async ({
2827
method = HttpMethod.GET,
2928
version = 'v4',
3029
}: CallApiParams): Promise<CallApiResponse> => {
31-
if (!endpoint.startsWith('/')) {
32-
// eslint-disable-next-line no-param-reassign
33-
endpoint = `/${endpoint}`;
30+
let adjustedEndpoint = endpoint;
31+
if (!adjustedEndpoint.startsWith('/')) {
32+
adjustedEndpoint = `/${adjustedEndpoint}`;
3433
}
35-
if (!endpoint.endsWith('/')) {
36-
// eslint-disable-next-line no-param-reassign
37-
endpoint = `${endpoint}/`;
34+
if (!adjustedEndpoint.endsWith('/')) {
35+
adjustedEndpoint = `${adjustedEndpoint}/`;
3836
}
3937

4038
const headers: Headers = {};
@@ -43,21 +41,23 @@ export const callApi = async ({
4341
}
4442

4543
try {
46-
const response = await fetch(`/api/${version}${endpoint}`, {
44+
const response = await fetch(`/api/${version}${adjustedEndpoint}`, {
4745
method,
4846
headers,
4947
});
5048

5149
if (!response.ok) {
5250
throw new Error(
53-
`Unexpected status for ${method} ${endpoint}: ${response.status}`,
51+
`Unexpected status for ${method} ${adjustedEndpoint}: ${
52+
response.status
53+
}`,
5454
);
5555
}
5656

5757
return await response.json();
5858
} catch (error) {
59-
// eslint-disable-next-line amo/only-log-strings, no-console
60-
console.error(error);
59+
// eslint-disable-next-line no-console
60+
console.debug(error);
6161

6262
return {
6363
error,

src/components/App/index.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { ShallowWrapper, shallow } from 'enzyme';
2+
import { shallow } from 'enzyme';
33
import { Store } from 'redux';
44

55
import styles from './styles.module.scss';
@@ -17,7 +17,7 @@ describe(__filename, () => {
1717
const render = ({
1818
store = configureStore(),
1919
authToken = 'some-token',
20-
}: RenderParams = {}): ShallowWrapper => {
20+
}: RenderParams = {}) => {
2121
// TODO: Use shallowUntilTarget()
2222
// https://github.com/mozilla/addons-code-manager/issues/15
2323
const root = shallow(<App authToken={authToken} />, {

src/components/App/index.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ class AppBase extends React.Component<Props, State> {
4242
};
4343
}
4444

45-
componentDidMount(): void {
45+
componentDidMount() {
4646
const { authToken, dispatch } = this.props;
4747

4848
if (authToken) {
4949
dispatch(apiActions.setAuthToken({ authToken }));
5050
}
5151
}
5252

53-
async componentDidUpdate(prevProps: Props): Promise<void> {
53+
async componentDidUpdate(prevProps: Props) {
5454
const { apiState } = this.props;
5555

5656
if (
@@ -69,7 +69,7 @@ class AppBase extends React.Component<Props, State> {
6969
}
7070
}
7171

72-
logOut = async (): Promise<void> => {
72+
logOut = async () => {
7373
const { apiState } = this.props;
7474

7575
this.setState({ isLoggingOut: true });
@@ -79,15 +79,13 @@ class AppBase extends React.Component<Props, State> {
7979
this.setState({ profile: null, isLoggingOut: false });
8080
};
8181

82-
handleToggleClick = (
83-
event: React.SyntheticEvent<HTMLButtonElement>,
84-
): void => {
82+
handleToggleClick = (event: React.SyntheticEvent<HTMLButtonElement>) => {
8583
const { dispatch } = this.props;
8684
event.preventDefault();
8785
dispatch(exampleActions.toggle());
8886
};
8987

90-
render(): React.ReactNode {
88+
render() {
9189
const { toggledOn } = this.props;
9290
const { profile, isLoggingOut } = this.state;
9391

src/components/DiffView/index.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ShallowWrapper, shallow } from 'enzyme';
1+
import { shallow } from 'enzyme';
22
import React from 'react';
33
import { Diff, parseDiff } from 'react-diff-view';
44

@@ -37,7 +37,7 @@ index 0cfbf08..e69de29 100644
3737
@@ -1 +0,0 @@
3838
-2`;
3939

40-
const render = (props = {}): ShallowWrapper => {
40+
const render = (props = {}) => {
4141
return shallow(<DiffView diff={basicDiff} {...props} />);
4242
};
4343

src/components/LoginButton/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import { Button } from 'react-bootstrap';
44
import styles from './styles.module.scss';
55

66
export class LoginButtonBase extends React.Component {
7-
getFxaURL(): string {
7+
getFxaURL() {
88
const fxaConfig = process.env.REACT_APP_FXA_CONFIG;
99

1010
return `/api/v4/accounts/login/start/?config=${fxaConfig}&to=/`;
1111
}
1212

13-
render(): React.ReactNode {
13+
render() {
1414
return (
1515
<Button href={this.getFxaURL()} className={styles.link}>
1616
Log in

src/configureStore.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
Action,
33
AnyAction,
44
Dispatch,
5-
Reducer,
65
Store,
76
applyMiddleware,
87
combineReducers,
@@ -23,7 +22,7 @@ export type ApplicationState = {
2322
example: ExampleState;
2423
};
2524

26-
const createRootReducer = (): Reducer<ApplicationState> => {
25+
const createRootReducer = () => {
2726
return combineReducers<ApplicationState>({ api, example });
2827
};
2928

src/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* global document */
21
import React from 'react';
32
import ReactDOM from 'react-dom';
43
import { BrowserRouter } from 'react-router-dom';

0 commit comments

Comments
 (0)