Browse Source

Merge pull request #106 from eliperelman/linting-round-2

Using neutrino to lint itself
v6-dev
Eli Perelman 8 years ago
committed by GitHub
parent
commit
bdac66185b
  1. 120
      .eslintrc.js
  2. 1
      .travis.yml
  3. 8
      package.json
  4. 2
      packages/neutrino-middleware-banner/index.js
  5. 5
      packages/neutrino-middleware-eslint/index.js
  6. 2
      packages/neutrino-middleware-html-template/index.js
  7. 7
      packages/neutrino-middleware-style-loader/index.js
  8. 5
      packages/neutrino-preset-airbnb-base/index.js
  9. 2
      packages/neutrino-preset-karma/index.js
  10. 6
      packages/neutrino-preset-node/index.js
  11. 2
      packages/neutrino-preset-react/index.js
  12. 60
      packages/neutrino-preset-web/index.js
  13. 617
      yarn.lock

120
.eslintrc.js

@ -1,50 +1,78 @@
module.exports = {
ecmaVersion: 2017,
const Neutrino = require('./packages/neutrino');
const airbnb = require('./packages/neutrino-preset-airbnb-base');
// http://eslint.org/docs/user-guide/configuring#specifying-parser-options
ecmaFeatures: {
modules: true,
decorators: true,
experimentalObjectRestSpread: true,
},
const api = new Neutrino();
env: {
api.use(airbnb, {
eslint: {
node: true,
browser: true,
es6: true,
worker: true,
serviceworker: true,
},
plugins: [
'eslint-plugin-prettier',
],
rules: {
// Specify the maximum length of a line in your program
// JSX can get lengthy, so this helps alleviate that a bit
// http://eslint.org/docs/rules/max-len
'max-len': ['error', 120, 2, {
ignoreUrls: true,
ignoreComments: false,
ignoreStrings: true,
ignoreTemplateLiterals: true
}],
// Allow using class methods with static/non-instance functionality
// React lifecycle methods commonly do not use an instance context for anything
'class-methods-use-this': 'off',
// Disallow trailing commas on arrays, objects, functions, et al
'comma-dangle': ['error', 'never'],
// Allow console during development, otherwise throw an error
'no-console': 'warn',
// Allow extra parentheses since multiline JSX being wrapped in parens is considered idiomatic
'no-extra-parens': 'off',
// Our frontend strives to adopt functional programming practices, so we prefer const over let
'prefer-const': 'error',
plugins: ['eslint-plugin-prettier'],
rules: {
// Disable necessitating return after a callback
'callback-return': 'off',
// Allow using class methods with static/non-instance functionality
// React lifecycle methods commonly do not use an instance context for anything
'class-methods-use-this': 'off',
// Disallow trailing commas on arrays, objects, functions, et al
'comma-dangle': ['error', 'never'],
// Require all requires be top-level
// http://eslint.org/docs/rules/global-require
'global-require': 'error',
// Enforces error handling in callbacks (node environment)
'handle-callback-err': 'off',
// Allow dynamic requires
'import/no-dynamic-require': 'off',
// Specify the maximum length of a line in your program
// JSX can get lengthy, so this helps alleviate that a bit
// http://eslint.org/docs/rules/max-len
'max-len': ['error', 120, 2, {
ignoreUrls: true,
ignoreComments: false,
ignoreStrings: true,
ignoreTemplateLiterals: true
}],
// Allow console during development, otherwise throw an error
'no-console': 'warn',
// Allow extra parentheses since multiline JSX being wrapped in parens is considered idiomatic
'no-extra-parens': 'off',
// Disallow mixing regular variable and require declarations
'no-mixed-requires': ['off', false],
// Disallow use of new operator with the require function
'no-new-require': 'error',
// Disallow string concatenation with __dirname and __filename
// http://eslint.org/docs/rules/no-path-concat
'no-path-concat': 'error',
// Allow use of process.env
'no-process-env': 'off',
// Allow process.exit()
'no-process-exit': 'off',
// Restrict usage of specified node modules
'no-restricted-modules': 'off',
// Allowing shadowing variable that share the same context as the outer scope
'no-shadow': 'off',
// Allow use of synchronous methods (off by default)
'no-sync': 'off',
// Our frontend strives to adopt functional programming practices, so we prefer const over let
'prefer-const': 'error',
}
}
}
});
module.exports = api.eslintrc();

1
.travis.yml

@ -35,4 +35,5 @@ cache:
before_script:
- yarn bootstrap
script:
- yarn lint
- yarn test

8
package.json

@ -8,7 +8,7 @@
"bugs": "https://github.com/mozilla-neutrino/neutrino-dev/issues",
"repository": "mozilla-neutrino/neutrino-dev",
"scripts": {
"lint": "eslint packages/**/*.js --fix",
"lint": "eslint packages/**/*.js",
"bootstrap": "oao bootstrap",
"changelog": "changelog mozilla-neutrino/neutrino-dev all --markdown > CHANGELOG.md",
"deps:add": "oao add",
@ -24,8 +24,12 @@
},
"devDependencies": {
"ava": "^0.18.2",
"babel-eslint": "^7.1.1",
"changelog": "^1.0.7",
"eslint": "^3.17.1",
"eslint-config-airbnb-base": "^11.1.1",
"eslint-plugin-babel": "^4.1.1",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-prettier": "^2.0.1",
"gh-pages": "^0.12.0",
"gitbook-cli": "^2.3.0",
@ -34,8 +38,8 @@
"gitbook-plugin-github": "^2.0.0",
"gitbook-plugin-npmsearchlist": "^1.0.0",
"gitbook-plugin-prism": "^2.1.0",
"prettier": "^0.21.0",
"oao": "^0.7.2",
"prettier": "^0.21.0",
"webpack": "^2.2.1"
}
}

2
packages/neutrino-middleware-banner/index.js

@ -5,7 +5,7 @@ module.exports = ({ config }, options) => config
.plugin('banner')
.use(BannerPlugin, [
merge({
banner: `require('source-map-support').install();`,
banner: 'require(\'source-map-support\').install();',
raw: true,
entryOnly: true
}, options)

5
packages/neutrino-middleware-eslint/index.js

@ -43,13 +43,14 @@ module.exports = (neutrino, options) => {
}, options.eslint || {}));
if (options.include) {
rule.include.merge(options.include);
lint.include.merge(options.include);
}
if (options.exclude) {
rule.exclude.merge(options.exclude);
lint.exclude.merge(options.exclude);
}
// eslint-disable-next-line no-param-reassign
neutrino.eslintrc = () => {
const options = clone(config.module.rule('lint').use('eslint').get('options'));

2
packages/neutrino-middleware-html-template/index.js

@ -15,7 +15,7 @@ module.exports = ({ config }, options) => config
useShortDoctype: true,
keepClosingSlash: true,
collapseWhitespace: true,
preserveLineBreaks: true,
preserveLineBreaks: true
}
}, options)
]);

7
packages/neutrino-middleware-style-loader/index.js

@ -1,5 +1,8 @@
module.exports = ({ config }) => config.module
.rule('style')
.test(/\.css$/)
.use('style').loader(require.resolve('style-loader')).end()
.use('css').loader(require.resolve('css-loader'));
.use('style')
.loader(require.resolve('style-loader'))
.end()
.use('css')
.loader(require.resolve('css-loader'));

5
packages/neutrino-preset-airbnb-base/index.js

@ -18,10 +18,7 @@ module.exports = (neutrino, options) => {
'babel/new-cap': ['error', { newIsCap: true }],
// require padding inside curly braces
'babel/object-curly-spacing': ['error', 'always'],
// guard against awaiting async functions inside of a loop
'babel/no-await-in-loop': 'error'
'babel/object-curly-spacing': ['error', 'always']
}
}
}, options));

2
packages/neutrino-preset-karma/index.js

@ -2,7 +2,7 @@ const { Server } = require('karma');
const merge = require('deepmerge');
const { join } = require('path');
module.exports = neutrino => {
module.exports = (neutrino) => {
const tests = join(neutrino.options.tests, '**/*_test.js');
const sources = join(neutrino.options.source, '**/*.js');

6
packages/neutrino-preset-node/index.js

@ -12,13 +12,15 @@ const { join } = require('path');
const MODULES = join(__dirname, 'node_modules');
module.exports = neutrino => {
module.exports = (neutrino) => {
const { config } = neutrino;
let pkg = {};
/* eslint-disable global-require, no-empty */
try {
pkg = require(join(neutrino.options.root, 'package.json'));
} catch (ex) {}
/* eslint-enable global-require no-empty */
neutrino.use(namedModules);
neutrino.use(compile, {
@ -81,7 +83,7 @@ module.exports = neutrino => {
neutrino.use(clean, { paths: [neutrino.options.output] });
neutrino.use(progress);
neutrino.use(copy, {
patterns: [{ context: neutrino.options.source, from: `**/*` }],
patterns: [{ context: neutrino.options.source, from: '**/*' }],
options: { ignore: ['*.js*'] }
});
} else {

2
packages/neutrino-preset-react/index.js

@ -4,7 +4,7 @@ const { join } = require('path');
const MODULES = join(__dirname, 'node_modules');
module.exports = neutrino => {
module.exports = (neutrino) => {
const { config } = neutrino;
neutrino.use(web);

60
packages/neutrino-preset-web/index.js

@ -18,7 +18,31 @@ const { pathOr } = require('ramda');
const MODULES = join(__dirname, 'node_modules');
module.exports = neutrino => {
function devServer({ config }, options) {
config.devServer
.host(options.host)
.port(parseInt(options.port, 10))
.https(options.https)
.contentBase(options.contentBase)
.historyApiFallback(true)
.hot(true)
.stats({
assets: false,
children: false,
chunks: false,
colors: true,
errors: true,
errorDetails: true,
hash: false,
modules: false,
publicPath: false,
timings: false,
version: false,
warnings: true
});
}
module.exports = (neutrino) => {
const { config } = neutrino;
neutrino.use(env);
@ -69,9 +93,9 @@ module.exports = neutrino => {
.filename('[name].bundle.js')
.chunkFilename('[id].[chunkhash].js');
config.resolve.modules.add(neutrino.options.node_modules).add(MODULES);
config.resolve.extensions.add('.js').add('.json');
config.resolveLoader.modules.add(neutrino.options.node_modules).add(MODULES);
config.resolve.modules.add(neutrino.options.node_modules).add(MODULES);
config.resolve.extensions.add('.js').add('.json');
config.resolveLoader.modules.add(neutrino.options.node_modules).add(MODULES);
config.node
.set('console', false)
@ -92,7 +116,7 @@ module.exports = neutrino => {
}
if (process.env.NODE_ENV === 'development') {
const protocol = !!process.env.HTTPS ? 'https' : 'http';
const protocol = process.env.HTTPS ? 'https' : 'http';
const host = process.env.HOST || pathOr('localhost', ['options', 'config', 'devServer', 'host'], neutrino);
const port = process.env.PORT || pathOr(5000, ['options', 'config', 'devServer', 'port'], neutrino);
@ -114,33 +138,9 @@ module.exports = neutrino => {
neutrino.use(progress);
neutrino.use(minify);
neutrino.use(copy, {
patterns: [{ context: neutrino.options.source, from: `**/*` }],
patterns: [{ context: neutrino.options.source, from: '**/*' }],
options: { ignore: ['*.js*'] }
});
config.output.filename('[name].[chunkhash].bundle.js');
}
};
function devServer({ config }, options) {
config.devServer
.host(options.host)
.port(parseInt(options.port))
.https(options.https)
.contentBase(options.contentBase)
.historyApiFallback(true)
.hot(true)
.stats({
assets: false,
children: false,
chunks: false,
colors: true,
errors: true,
errorDetails: true,
hash: false,
modules: false,
publicPath: false,
timings: false,
version: false,
warnings: true
});
}

617
yarn.lock

File diff suppressed because it is too large
Loading…
Cancel
Save