Skip to content
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

Use eslint to catch import mistakes and style nits #945

Merged
merged 3 commits into from
Aug 19, 2016
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
62 changes: 61 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,72 @@
"parser": "babel-eslint",
"rules": {
"arrow-parens": ["error", "always"],
"import/no-unresolved": "off",
// This makes sure imported modules exist.
"import/no-unresolved": ["error"],
// This makes sure imported names exist.
"import/named": ["error"],
// This will catch accidental default imports when no default is defined.
"import/default": ["error"],
// This makes sure `*' imports are dereferenced to real exports.
"import/namespace": ["error"],
// This catches any export mistakes.
"import/export": ["error"],
// This catches default names that conflict with actual exported names.
// For example, this was probably a typo:
// import foo from 'bar';
// that should be corrected as:
// import { foo } from 'bar';
"import/no-named-as-default": ["error"],
// This catches possible typos like trying to access a real export on a
// default import.
"import/no-named-as-default-member": ["error"],
// This prevents exporting a mutable variable.
"import/no-mutable-exports": ["error"],
// This makes sure package.json defines dev vs. prod dependencies correctly.
"import/no-extraneous-dependencies": ["error", {
// The following are not allowed to be imported. See .eslintrc in other
// directories (like ./test) for where this gets overidden.
"devDependencies": false, "optionalDependencies": false, "peerDependencies": false
}],
// This ensures imports are at the top of the file.
"import/imports-first": ["error"],
// This catches duplicate exports.
"import/no-duplicates": ["error"],
// This ensures import statements never provide a file extension in the path.
"import/extensions": ["error", "never"],
// This ensures imports are organized by type and that groups are separated
// by a new line.
"import/order": ["error", {
"groups": [
"builtin", "external", "internal", ["parent", "sibling"], "index"
],
"newlines-between": "always"
}],
// This ensures a new line after all import statements.
"import/newline-after-import": ["error"],
"no-underscore-dangle": "off",
"space-before-function-paren": ["error", "never"],
"react/prefer-stateless-function": "off",
"react/jsx-indent-props": "off",
"react/jsx-closing-bracket-location": "off",
"react/jsx-first-prop-new-line": "off"
},
"settings": {
"import/ignore": [
// Because of CommonJS incompatibility, we can't
// check for bad imports in node_modules.
"node_modules",
// Ignore non-JS imports.
"\\.scss$",
"\\.jpg$",
"\\.mp4$",
"\\.webm$"
],
"import/resolver": {
"node": {
// This adds ./src for relative imports.
"moduleDirectory": ["node_modules", "src"]
}
}
}
}
8 changes: 8 additions & 0 deletions bin/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"rules": {
"import/no-extraneous-dependencies": ["error", {
// Allow dev-dependencies in this directory.
"devDependencies": true
}],
}
}
1 change: 0 additions & 1 deletion bin/build-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/* eslint-disable global-require, no-console */

const chalk = require('chalk');

require('babel-register');
const config = require('config');

Expand Down
1 change: 0 additions & 1 deletion bin/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/* eslint-disable global-require, no-console */

const chalk = require('chalk');

require('babel-register');
const config = require('config');

Expand Down
5 changes: 2 additions & 3 deletions bin/webpack-dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
/* eslint-disable strict, no-console */

require('babel-register');

const Express = require('express');
const config = require('config');
const webpack = require('webpack');
const webpackDevMiddleware = require('webpack-dev-middleware');
const webpackHotMiddleware = require('webpack-hot-middleware');
const webpackDevConfig = require('webpack.dev.config.babel').default;

const config = require('config');
const webpackDevConfig = require('../webpack.dev.config.babel').default;

const host = config.get('webpackServerHost');
const port = config.get('webpackServerPort');
Expand Down
12 changes: 7 additions & 5 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
// Karma configuration
/* eslint-disable max-len, no-console, strict */
/* eslint-disable max-len, no-console, strict, import/no-extraneous-dependencies */
'use strict';

require('babel-register');

const fs = require('fs');

const babelrc = fs.readFileSync('./.babelrc');
const babelQuery = JSON.parse(babelrc);
const webpack = require('webpack');
const webpackConfigProd = require('./webpack.prod.config.babel').default;
const config = require('config');
const getClientConfig = require('src/core/utils').getClientConfig;

const getClientConfig = require('./src/core/utils').getClientConfig;
const webpackConfigProd = require('./webpack.prod.config.babel').default;

const clientConfig = getClientConfig(config);
const babelrc = fs.readFileSync('./.babelrc');
const babelQuery = JSON.parse(babelrc);

const coverageReporters = [{
type: 'text-summary',
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
"homepage": "https://github.com/mozillla/addons-frontend#readme",
"dependencies": {
"babel-plugin-dedent": "2.0.0",
"babel-polyfill": "6.13.0",
"better-npm-run": "0.0.11",
"bunyan": "1.8.1",
"camelcase": "3.0.0",
Expand All @@ -156,6 +157,7 @@
"react": "15.3.0",
"react-addons-css-transition-group": "15.3.1",
"react-cookie": "0.4.8",
"react-dom": "15.3.1",
"react-helmet": "3.1.0",
"react-onclickoutside": "5.3.3",
"react-redux": "4.4.5",
Expand All @@ -165,7 +167,8 @@
"redux-logger": "2.6.1",
"serialize-javascript": "1.3.0",
"url": "0.11.0",
"url-loader": "0.5.7"
"url-loader": "0.5.7",
"webpack-isomorphic-tools": "2.5.7"
},
"devDependencies": {
"autoprefixer": "6.4.0",
Expand All @@ -178,7 +181,6 @@
"babel-plugin-transform-class-properties": "6.11.5",
"babel-plugin-transform-decorators-legacy": "1.3.4",
"babel-plugin-transform-object-rest-spread": "6.8.0",
"babel-polyfill": "6.13.0",
"babel-preset-es2015": "6.13.2",
"babel-preset-react": "6.11.1",
"babel-preset-stage-2": "6.13.0",
Expand Down Expand Up @@ -213,7 +215,6 @@
"po2json": "0.4.2",
"postcss-loader": "0.10.1",
"react-addons-test-utils": "15.3.1",
"react-dom": "15.3.1",
"react-hot-loader": "1.3.0",
"react-transform-hmr": "1.0.4",
"redux-devtools": "3.3.1",
Expand All @@ -233,7 +234,6 @@
"webpack": "1.13.2",
"webpack-dev-middleware": "1.6.1",
"webpack-dev-server": "1.14.1",
"webpack-hot-middleware": "2.12.2",
"webpack-isomorphic-tools": "2.5.7"
"webpack-hot-middleware": "2.12.2"
}
}
5 changes: 3 additions & 2 deletions src/amo/client.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import makeClient from 'core/client/base';
import routes from './routes';
import createStore from './store';

// Initialize the tracking.
import 'core/tracking';

import routes from './routes';
import createStore from './store';

makeClient(routes, createStore);
4 changes: 2 additions & 2 deletions src/amo/components/AddonMeta.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import translate from 'core/i18n/translate';

import 'amo/css/AddonMeta.scss';

export class AddonMeta extends React.Component {
export class AddonMetaBase extends React.Component {
static propTypes = {
i18n: PropTypes.object,
}
Expand Down Expand Up @@ -34,4 +34,4 @@ export class AddonMeta extends React.Component {
}
}

export default translate({ withRef: true })(AddonMeta);
export default translate({ withRef: true })(AddonMetaBase);
4 changes: 2 additions & 2 deletions src/amo/components/LikeButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import translate from 'core/i18n/translate';

import 'amo/css/LikeButton.scss';

export class LikeButton extends React.Component {
export class LikeButtonBase extends React.Component {
static propTypes = {
i18n: PropTypes.object,
}
Expand All @@ -21,4 +21,4 @@ export class LikeButton extends React.Component {
}
}

export default translate({ withRef: true })(LikeButton);
export default translate({ withRef: true })(LikeButtonBase);
4 changes: 2 additions & 2 deletions src/amo/components/ScreenShots.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import translate from 'core/i18n/translate';
import 'amo/css/ScreenShots.scss';


export class ScreenShots extends React.Component {
export class ScreenShotsBase extends React.Component {
static propTypes = {
i18n: PropTypes.object,
}
Expand Down Expand Up @@ -36,4 +36,4 @@ export class ScreenShots extends React.Component {
}
}

export default translate({ withRef: true })(ScreenShots);
export default translate({ withRef: true })(ScreenShotsBase);
4 changes: 2 additions & 2 deletions src/amo/components/SearchBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import translate from 'core/i18n/translate';
import 'amo/css/SearchBox.scss';


export class SearchBox extends React.Component {
export class SearchBoxBase extends React.Component {
static propTypes = {
i18n: PropTypes.object,
}
Expand All @@ -22,4 +22,4 @@ export class SearchBox extends React.Component {
}
}

export default translate({ withRef: true })(SearchBox);
export default translate({ withRef: true })(SearchBoxBase);
4 changes: 2 additions & 2 deletions src/amo/containers/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'amo/css/App.scss';
import translate from 'core/i18n/translate';


export class App extends React.Component {
export class AppBase extends React.Component {
static propTypes = {
children: PropTypes.node,
i18n: PropTypes.object.isRequired,
Expand All @@ -25,4 +25,4 @@ export class App extends React.Component {
}
}

export default translate({ withRef: true })(App);
export default translate({ withRef: true })(AppBase);
4 changes: 2 additions & 2 deletions src/amo/containers/DetailPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import AddonDetail from 'amo/components/AddonDetail';
import translate from 'core/i18n/translate';
import { loadAddonIfNeeded } from 'core/utils';

export class DetailPage extends React.Component {
export class DetailPageBase extends React.Component {
static propTypes = {
addon: PropTypes.object,
}
Expand Down Expand Up @@ -36,4 +36,4 @@ export default compose(
}]),
connect(mapStateToProps),
translate({ withRef: true }),
)(DetailPage);
)(DetailPageBase);
2 changes: 1 addition & 1 deletion src/amo/store.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createStore as _createStore, combineReducers } from 'redux';
import { reducer as reduxAsyncConnect } from 'redux-async-connect';
import { middleware } from 'core/store';

import { middleware } from 'core/store';
import addons from 'core/reducers/addons';
import api from 'core/reducers/api';

Expand Down
5 changes: 2 additions & 3 deletions src/core/api/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Schema, arrayOf, normalize } from 'normalizr';
import url from 'url';

import config from 'config';

import 'isomorphic-fetch';
import { Schema, arrayOf, normalize } from 'normalizr';
import config from 'config';

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

Expand Down
7 changes: 3 additions & 4 deletions src/core/client/base.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import 'babel-polyfill';
import React from 'react';

import config from 'config';
import Jed from 'jed';
import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { Router, browserHistory } from 'react-router';
import { ReduxAsyncConnect } from 'redux-async-connect';

import { langToLocale, sanitizeLanguage } from 'core/i18n/utils';
import I18nProvider from 'core/i18n/Provider';
import Jed from 'jed';

import log from 'core/logger';


Expand Down
6 changes: 3 additions & 3 deletions src/core/components/InstallButton/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { PropTypes } from 'react';
import translate from 'core/i18n/translate';

import translate from 'core/i18n/translate';
import {
DOWNLOADING,
DISABLED,
Expand All @@ -19,7 +19,7 @@ import { getThemeData } from 'disco/themePreview';

import './InstallButton.scss';

export class InstallButton extends React.Component {
export class InstallButtonBase extends React.Component {
static propTypes = {
downloadProgress: PropTypes.number,
enable: PropTypes.func,
Expand Down Expand Up @@ -122,4 +122,4 @@ export class InstallButton extends React.Component {
}
}

export default translate()(InstallButton);
export default translate()(InstallButtonBase);
1 change: 1 addition & 0 deletions src/core/components/NotFound.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';

import { gettext as _ } from 'core/utils';

export default class NotFound extends React.Component {
Expand Down
2 changes: 1 addition & 1 deletion src/core/containers/HandleLogin/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { PropTypes } from 'react';
import cookie from 'react-cookie';
import { connect } from 'react-redux';

import config from 'config';

import { setJWT } from 'core/actions';
import { login } from 'core/api';
import LoginPage from 'core/components/LoginPage';
Expand Down
5 changes: 3 additions & 2 deletions src/core/containers/LoginRequired/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { PropTypes } from 'react';
import { connect } from 'react-redux';

import LoginPage from 'core/components/LoginPage';

export function mapStateToProps(state) {
Expand All @@ -9,7 +10,7 @@ export function mapStateToProps(state) {
}

// This class is exported for testing outside of redux.
export class LoginRequired extends React.Component {
export class LoginRequiredBase extends React.Component {
static propTypes = {
authenticated: PropTypes.bool.isRequired,
children: PropTypes.node,
Expand All @@ -24,4 +25,4 @@ export class LoginRequired extends React.Component {
}
}

export default connect(mapStateToProps)(LoginRequired);
export default connect(mapStateToProps)(LoginRequiredBase);
Loading