Browse Source

Using neutrino to lint itself

Removing --fix from lint command
v6-dev
Eli Perelman 8 years ago
parent
commit
2ef39382a6
  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 = { const Neutrino = require('./packages/neutrino');
ecmaVersion: 2017, const airbnb = require('./packages/neutrino-preset-airbnb-base');
// http://eslint.org/docs/user-guide/configuring#specifying-parser-options const api = new Neutrino();
ecmaFeatures: {
modules: true,
decorators: true,
experimentalObjectRestSpread: true,
},
env: { api.use(airbnb, {
eslint: {
node: true, node: true,
browser: true, plugins: ['eslint-plugin-prettier'],
es6: true, rules: {
worker: true, // Disable necessitating return after a callback
serviceworker: true, 'callback-return': 'off',
},
// Allow using class methods with static/non-instance functionality
plugins: [ // React lifecycle methods commonly do not use an instance context for anything
'eslint-plugin-prettier', 'class-methods-use-this': 'off',
],
// Disallow trailing commas on arrays, objects, functions, et al
rules: { 'comma-dangle': ['error', 'never'],
// Specify the maximum length of a line in your program
// JSX can get lengthy, so this helps alleviate that a bit // Require all requires be top-level
// http://eslint.org/docs/rules/max-len // http://eslint.org/docs/rules/global-require
'max-len': ['error', 120, 2, { 'global-require': 'error',
ignoreUrls: true,
ignoreComments: false, // Enforces error handling in callbacks (node environment)
ignoreStrings: true, 'handle-callback-err': 'off',
ignoreTemplateLiterals: true
}], // Allow dynamic requires
'import/no-dynamic-require': 'off',
// Allow using class methods with static/non-instance functionality
// React lifecycle methods commonly do not use an instance context for anything // Specify the maximum length of a line in your program
'class-methods-use-this': 'off', // JSX can get lengthy, so this helps alleviate that a bit
// http://eslint.org/docs/rules/max-len
// Disallow trailing commas on arrays, objects, functions, et al 'max-len': ['error', 120, 2, {
'comma-dangle': ['error', 'never'], ignoreUrls: true,
ignoreComments: false,
// Allow console during development, otherwise throw an error ignoreStrings: true,
'no-console': 'warn', ignoreTemplateLiterals: true
}],
// Allow extra parentheses since multiline JSX being wrapped in parens is considered idiomatic
'no-extra-parens': 'off', // Allow console during development, otherwise throw an error
'no-console': 'warn',
// Our frontend strives to adopt functional programming practices, so we prefer const over let
'prefer-const': 'error', // 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: before_script:
- yarn bootstrap - yarn bootstrap
script: script:
- yarn lint
- yarn test - yarn test

8
package.json

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

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

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

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

@ -43,13 +43,14 @@ module.exports = (neutrino, options) => {
}, options.eslint || {})); }, options.eslint || {}));
if (options.include) { if (options.include) {
rule.include.merge(options.include); lint.include.merge(options.include);
} }
if (options.exclude) { if (options.exclude) {
rule.exclude.merge(options.exclude); lint.exclude.merge(options.exclude);
} }
// eslint-disable-next-line no-param-reassign
neutrino.eslintrc = () => { neutrino.eslintrc = () => {
const options = clone(config.module.rule('lint').use('eslint').get('options')); 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, useShortDoctype: true,
keepClosingSlash: true, keepClosingSlash: true,
collapseWhitespace: true, collapseWhitespace: true,
preserveLineBreaks: true, preserveLineBreaks: true
} }
}, options) }, options)
]); ]);

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

@ -1,5 +1,8 @@
module.exports = ({ config }) => config.module module.exports = ({ config }) => config.module
.rule('style') .rule('style')
.test(/\.css$/) .test(/\.css$/)
.use('style').loader(require.resolve('style-loader')).end() .use('style')
.use('css').loader(require.resolve('css-loader')); .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 }], 'babel/new-cap': ['error', { newIsCap: true }],
// require padding inside curly braces // require padding inside curly braces
'babel/object-curly-spacing': ['error', 'always'], 'babel/object-curly-spacing': ['error', 'always']
// guard against awaiting async functions inside of a loop
'babel/no-await-in-loop': 'error'
} }
} }
}, options)); }, options));

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

@ -2,7 +2,7 @@ const { Server } = require('karma');
const merge = require('deepmerge'); const merge = require('deepmerge');
const { join } = require('path'); const { join } = require('path');
module.exports = neutrino => { module.exports = (neutrino) => {
const tests = join(neutrino.options.tests, '**/*_test.js'); const tests = join(neutrino.options.tests, '**/*_test.js');
const sources = join(neutrino.options.source, '**/*.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'); const MODULES = join(__dirname, 'node_modules');
module.exports = neutrino => { module.exports = (neutrino) => {
const { config } = neutrino; const { config } = neutrino;
let pkg = {}; let pkg = {};
/* eslint-disable global-require, no-empty */
try { try {
pkg = require(join(neutrino.options.root, 'package.json')); pkg = require(join(neutrino.options.root, 'package.json'));
} catch (ex) {} } catch (ex) {}
/* eslint-enable global-require no-empty */
neutrino.use(namedModules); neutrino.use(namedModules);
neutrino.use(compile, { neutrino.use(compile, {
@ -81,7 +83,7 @@ module.exports = neutrino => {
neutrino.use(clean, { paths: [neutrino.options.output] }); neutrino.use(clean, { paths: [neutrino.options.output] });
neutrino.use(progress); neutrino.use(progress);
neutrino.use(copy, { neutrino.use(copy, {
patterns: [{ context: neutrino.options.source, from: `**/*` }], patterns: [{ context: neutrino.options.source, from: '**/*' }],
options: { ignore: ['*.js*'] } options: { ignore: ['*.js*'] }
}); });
} else { } else {

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

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

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

@ -18,7 +18,31 @@ const { pathOr } = require('ramda');
const MODULES = join(__dirname, 'node_modules'); 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; const { config } = neutrino;
neutrino.use(env); neutrino.use(env);
@ -69,9 +93,9 @@ module.exports = neutrino => {
.filename('[name].bundle.js') .filename('[name].bundle.js')
.chunkFilename('[id].[chunkhash].js'); .chunkFilename('[id].[chunkhash].js');
config.resolve.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.resolve.extensions.add('.js').add('.json');
config.resolveLoader.modules.add(neutrino.options.node_modules).add(MODULES); config.resolveLoader.modules.add(neutrino.options.node_modules).add(MODULES);
config.node config.node
.set('console', false) .set('console', false)
@ -92,7 +116,7 @@ module.exports = neutrino => {
} }
if (process.env.NODE_ENV === 'development') { 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 host = process.env.HOST || pathOr('localhost', ['options', 'config', 'devServer', 'host'], neutrino);
const port = process.env.PORT || pathOr(5000, ['options', 'config', 'devServer', 'port'], 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(progress);
neutrino.use(minify); neutrino.use(minify);
neutrino.use(copy, { neutrino.use(copy, {
patterns: [{ context: neutrino.options.source, from: `**/*` }], patterns: [{ context: neutrino.options.source, from: '**/*' }],
options: { ignore: ['*.js*'] } options: { ignore: ['*.js*'] }
}); });
config.output.filename('[name].[chunkhash].bundle.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