Skip to content

Commit d7b76b8

Browse files
committed
Use eslint to catch import mistakes and style nits
1 parent fe29c30 commit d7b76b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+274
-165
lines changed

.eslintrc

+61-1
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,72 @@
1313
"parser": "babel-eslint",
1414
"rules": {
1515
"arrow-parens": ["error", "always"],
16-
"import/no-unresolved": "off",
16+
// This makes sure imported modules exist.
17+
"import/no-unresolved": ["error"],
18+
// This makes sure imported names exist.
19+
"import/named": ["error"],
20+
// This will catch accidental default imports when no default is defined.
21+
"import/default": ["error"],
22+
// This makes sure `*' imports are dereferenced to real exports.
23+
"import/namespace": ["error"],
24+
// This catches any export mistakes.
25+
"import/export": ["error"],
26+
// This catches default names that conflict with actual exported names.
27+
// For example, this was probably a typo:
28+
// import foo from 'bar';
29+
// that should be corrected as:
30+
// import { foo } from 'bar';
31+
"import/no-named-as-default": ["error"],
32+
// This catches possible typos like trying to access a real export on a
33+
// default import.
34+
"import/no-named-as-default-member": ["error"],
35+
// This prevents exporting a mutable variable.
36+
"import/no-mutable-exports": ["error"],
37+
// This makes sure package.json defines dev vs. prod dependencies correctly.
38+
"import/no-extraneous-dependencies": ["error", {
39+
// The following are not allowed to be imported. See .eslintrc in other
40+
// directories (like ./test) for where this gets overidden.
41+
"devDependencies": false, "optionalDependencies": false, "peerDependencies": false
42+
}],
43+
// This ensures imports are at the top of the file.
44+
"import/imports-first": ["error"],
45+
// This catches duplicate exports.
46+
"import/no-duplicates": ["error"],
47+
// This ensures import statements never provide a file extension in the path.
48+
"import/extensions": ["error", "never"],
49+
// This ensures imports are organized by type and that groups are separated
50+
// by a new line.
51+
"import/order": ["error", {
52+
"groups": [
53+
"builtin", "external", "internal", ["parent", "sibling"], "index"
54+
],
55+
"newlines-between": "always"
56+
}],
57+
// This ensures a new line after all import statements.
58+
"import/newline-after-import": ["error"],
1759
"no-underscore-dangle": "off",
1860
"space-before-function-paren": ["error", "never"],
1961
"react/prefer-stateless-function": "off",
2062
"react/jsx-indent-props": "off",
2163
"react/jsx-closing-bracket-location": "off",
2264
"react/jsx-first-prop-new-line": "off"
65+
},
66+
"settings": {
67+
"import/ignore": [
68+
// Because of CommonJS incompatibility, we can't
69+
// check for bad imports in node_modules.
70+
"node_modules",
71+
// Ignore non-JS imports.
72+
"\\.scss$",
73+
"\\.jpg$",
74+
"\\.mp4$",
75+
"\\.webm$"
76+
],
77+
"import/resolver": {
78+
"node": {
79+
// This adds ./src for relative imports.
80+
"moduleDirectory": ["node_modules", "src"]
81+
}
82+
}
2383
}
2484
}

bin/.eslintrc

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"rules": {
3+
"import/no-extraneous-dependencies": ["error", {
4+
// Allow dev-dependencies in this directory.
5+
"devDependencies": true
6+
}],
7+
}
8+
}

bin/build-checks.js

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
/* eslint-disable global-require, no-console */
33

44
const chalk = require('chalk');
5-
65
require('babel-register');
76
const config = require('config');
87

bin/server.js

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
/* eslint-disable global-require, no-console */
33

44
const chalk = require('chalk');
5-
65
require('babel-register');
76
const config = require('config');
87

bin/webpack-dev-server.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
/* eslint-disable strict, no-console */
44

55
require('babel-register');
6-
76
const Express = require('express');
7+
const config = require('config');
88
const webpack = require('webpack');
99
const webpackDevMiddleware = require('webpack-dev-middleware');
1010
const webpackHotMiddleware = require('webpack-hot-middleware');
11-
const webpackDevConfig = require('webpack.dev.config.babel').default;
1211

13-
const config = require('config');
12+
const webpackDevConfig = require('../webpack.dev.config.babel').default;
1413

1514
const host = config.get('webpackServerHost');
1615
const port = config.get('webpackServerPort');

karma.conf.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
// Karma configuration
2-
/* eslint-disable max-len, no-console, strict */
2+
/* eslint-disable max-len, no-console, strict, import/no-extraneous-dependencies */
33
'use strict';
44

55
require('babel-register');
66

77
const fs = require('fs');
88

9-
const babelrc = fs.readFileSync('./.babelrc');
10-
const babelQuery = JSON.parse(babelrc);
119
const webpack = require('webpack');
12-
const webpackConfigProd = require('./webpack.prod.config.babel').default;
1310
const config = require('config');
14-
const getClientConfig = require('src/core/utils').getClientConfig;
11+
12+
const getClientConfig = require('./src/core/utils').getClientConfig;
13+
const webpackConfigProd = require('./webpack.prod.config.babel').default;
14+
1515
const clientConfig = getClientConfig(config);
16+
const babelrc = fs.readFileSync('./.babelrc');
17+
const babelQuery = JSON.parse(babelrc);
1618

1719
const coverageReporters = [{
1820
type: 'text-summary',

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
"homepage": "https://github.com/mozillla/addons-frontend#readme",
139139
"dependencies": {
140140
"babel-plugin-dedent": "2.0.0",
141+
"babel-polyfill": "6.13.0",
141142
"better-npm-run": "0.0.11",
142143
"bunyan": "1.8.1",
143144
"camelcase": "3.0.0",
@@ -156,6 +157,7 @@
156157
"react": "15.3.0",
157158
"react-addons-css-transition-group": "15.3.1",
158159
"react-cookie": "0.4.8",
160+
"react-dom": "15.3.1",
159161
"react-helmet": "3.1.0",
160162
"react-onclickoutside": "5.3.3",
161163
"react-redux": "4.4.5",
@@ -165,7 +167,8 @@
165167
"redux-logger": "2.6.1",
166168
"serialize-javascript": "1.3.0",
167169
"url": "0.11.0",
168-
"url-loader": "0.5.7"
170+
"url-loader": "0.5.7",
171+
"webpack-isomorphic-tools": "2.5.7"
169172
},
170173
"devDependencies": {
171174
"autoprefixer": "6.4.0",
@@ -178,7 +181,6 @@
178181
"babel-plugin-transform-class-properties": "6.11.5",
179182
"babel-plugin-transform-decorators-legacy": "1.3.4",
180183
"babel-plugin-transform-object-rest-spread": "6.8.0",
181-
"babel-polyfill": "6.13.0",
182184
"babel-preset-es2015": "6.13.2",
183185
"babel-preset-react": "6.11.1",
184186
"babel-preset-stage-2": "6.13.0",
@@ -213,7 +215,6 @@
213215
"po2json": "0.4.2",
214216
"postcss-loader": "0.10.1",
215217
"react-addons-test-utils": "15.3.1",
216-
"react-dom": "15.3.1",
217218
"react-hot-loader": "1.3.0",
218219
"react-transform-hmr": "1.0.4",
219220
"redux-devtools": "3.3.1",
@@ -233,7 +234,6 @@
233234
"webpack": "1.13.2",
234235
"webpack-dev-middleware": "1.6.1",
235236
"webpack-dev-server": "1.14.1",
236-
"webpack-hot-middleware": "2.12.2",
237-
"webpack-isomorphic-tools": "2.5.7"
237+
"webpack-hot-middleware": "2.12.2"
238238
}
239239
}

src/amo/client.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import makeClient from 'core/client/base';
2-
import routes from './routes';
3-
import createStore from './store';
42

53
// Initialize the tracking.
64
import 'core/tracking';
75

6+
import routes from './routes';
7+
import createStore from './store';
8+
89
makeClient(routes, createStore);

src/amo/components/AddonMeta.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import translate from 'core/i18n/translate';
44

55
import 'amo/css/AddonMeta.scss';
66

7-
export class AddonMeta extends React.Component {
7+
export class AddonMetaBase extends React.Component {
88
static propTypes = {
99
i18n: PropTypes.object,
1010
}
@@ -34,4 +34,4 @@ export class AddonMeta extends React.Component {
3434
}
3535
}
3636

37-
export default translate({ withRef: true })(AddonMeta);
37+
export default translate({ withRef: true })(AddonMetaBase);

src/amo/components/LikeButton.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import translate from 'core/i18n/translate';
44

55
import 'amo/css/LikeButton.scss';
66

7-
export class LikeButton extends React.Component {
7+
export class LikeButtonBase extends React.Component {
88
static propTypes = {
99
i18n: PropTypes.object,
1010
}
@@ -21,4 +21,4 @@ export class LikeButton extends React.Component {
2121
}
2222
}
2323

24-
export default translate({ withRef: true })(LikeButton);
24+
export default translate({ withRef: true })(LikeButtonBase);

src/amo/components/ScreenShots.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import translate from 'core/i18n/translate';
55
import 'amo/css/ScreenShots.scss';
66

77

8-
export class ScreenShots extends React.Component {
8+
export class ScreenShotsBase extends React.Component {
99
static propTypes = {
1010
i18n: PropTypes.object,
1111
}
@@ -36,4 +36,4 @@ export class ScreenShots extends React.Component {
3636
}
3737
}
3838

39-
export default translate({ withRef: true })(ScreenShots);
39+
export default translate({ withRef: true })(ScreenShotsBase);

src/amo/components/SearchBox.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import translate from 'core/i18n/translate';
55
import 'amo/css/SearchBox.scss';
66

77

8-
export class SearchBox extends React.Component {
8+
export class SearchBoxBase extends React.Component {
99
static propTypes = {
1010
i18n: PropTypes.object,
1111
}
@@ -22,4 +22,4 @@ export class SearchBox extends React.Component {
2222
}
2323
}
2424

25-
export default translate({ withRef: true })(SearchBox);
25+
export default translate({ withRef: true })(SearchBoxBase);

src/amo/containers/App.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'amo/css/App.scss';
66
import translate from 'core/i18n/translate';
77

88

9-
export class App extends React.Component {
9+
export class AppBase extends React.Component {
1010
static propTypes = {
1111
children: PropTypes.node,
1212
i18n: PropTypes.object.isRequired,
@@ -25,4 +25,4 @@ export class App extends React.Component {
2525
}
2626
}
2727

28-
export default translate({ withRef: true })(App);
28+
export default translate({ withRef: true })(AppBase);

src/amo/containers/DetailPage.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import AddonDetail from 'amo/components/AddonDetail';
77
import translate from 'core/i18n/translate';
88
import { loadAddonIfNeeded } from 'core/utils';
99

10-
export class DetailPage extends React.Component {
10+
export class DetailPageBase extends React.Component {
1111
static propTypes = {
1212
addon: PropTypes.object,
1313
}
@@ -36,4 +36,4 @@ export default compose(
3636
}]),
3737
connect(mapStateToProps),
3838
translate({ withRef: true }),
39-
)(DetailPage);
39+
)(DetailPageBase);

src/amo/store.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createStore as _createStore, combineReducers } from 'redux';
22
import { reducer as reduxAsyncConnect } from 'redux-async-connect';
3-
import { middleware } from 'core/store';
43

4+
import { middleware } from 'core/store';
55
import addons from 'core/reducers/addons';
66
import api from 'core/reducers/api';
77

src/core/api/index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { Schema, arrayOf, normalize } from 'normalizr';
21
import url from 'url';
32

4-
import config from 'config';
5-
63
import 'isomorphic-fetch';
4+
import { Schema, arrayOf, normalize } from 'normalizr';
5+
import config from 'config';
76

87
const API_BASE = `${config.get('apiHost')}${config.get('apiPath')}`;
98

src/core/client/base.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import 'babel-polyfill';
2-
import React from 'react';
3-
42
import config from 'config';
3+
import Jed from 'jed';
4+
import React from 'react';
55
import { render } from 'react-dom';
66
import { Provider } from 'react-redux';
77
import { Router, browserHistory } from 'react-router';
88
import { ReduxAsyncConnect } from 'redux-async-connect';
9+
910
import { langToLocale, sanitizeLanguage } from 'core/i18n/utils';
1011
import I18nProvider from 'core/i18n/Provider';
11-
import Jed from 'jed';
12-
1312
import log from 'core/logger';
1413

1514

src/core/components/InstallButton/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { PropTypes } from 'react';
2-
import translate from 'core/i18n/translate';
32

3+
import translate from 'core/i18n/translate';
44
import {
55
DOWNLOADING,
66
DISABLED,
@@ -19,7 +19,7 @@ import { getThemeData } from 'disco/themePreview';
1919

2020
import './InstallButton.scss';
2121

22-
export class InstallButton extends React.Component {
22+
export class InstallButtonBase extends React.Component {
2323
static propTypes = {
2424
downloadProgress: PropTypes.number,
2525
enable: PropTypes.func,
@@ -122,4 +122,4 @@ export class InstallButton extends React.Component {
122122
}
123123
}
124124

125-
export default translate()(InstallButton);
125+
export default translate()(InstallButtonBase);

src/core/components/NotFound.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
23
import { gettext as _ } from 'core/utils';
34

45
export default class NotFound extends React.Component {

src/core/containers/HandleLogin/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { PropTypes } from 'react';
22
import cookie from 'react-cookie';
33
import { connect } from 'react-redux';
4-
54
import config from 'config';
5+
66
import { setJWT } from 'core/actions';
77
import { login } from 'core/api';
88
import LoginPage from 'core/components/LoginPage';

src/core/containers/LoginRequired/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { PropTypes } from 'react';
22
import { connect } from 'react-redux';
3+
34
import LoginPage from 'core/components/LoginPage';
45

56
export function mapStateToProps(state) {
@@ -9,7 +10,7 @@ export function mapStateToProps(state) {
910
}
1011

1112
// This class is exported for testing outside of redux.
12-
export class LoginRequired extends React.Component {
13+
export class LoginRequiredBase extends React.Component {
1314
static propTypes = {
1415
authenticated: PropTypes.bool.isRequired,
1516
children: PropTypes.node,
@@ -24,4 +25,4 @@ export class LoginRequired extends React.Component {
2425
}
2526
}
2627

27-
export default connect(mapStateToProps)(LoginRequired);
28+
export default connect(mapStateToProps)(LoginRequiredBase);

0 commit comments

Comments
 (0)