From 6d63925244133ec8e8e982ad622ce6074b443fb7 Mon Sep 17 00:00:00 2001 From: constgen Date: Thu, 27 Jul 2017 12:31:25 +0300 Subject: [PATCH] Add linting tasks --- .eslintignore | 2 ++ .eslintrc | 26 +++++++++++++++++++++----- package.json | 10 +++++++--- src/dev-server.js | 20 ++++++++++---------- src/html-template.js | 8 ++++---- src/index.js | 10 +++++----- 6 files changed, 49 insertions(+), 27 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..1fdb241 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +/src/polyfills.js +/*.* \ No newline at end of file diff --git a/.eslintrc b/.eslintrc index 2ea8ed4..7abf844 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,16 +5,32 @@ "node": true }, "extends": "eslint:recommended", - "parserOptions": { - "sourceType": "module" - }, "rules": { "comma-dangle": ["error", "never"], - "indent": ["error", "tab"], + "indent": ["error", "tab", {"MemberExpression": "off"}], "linebreak-style": ["error", "unix"], "quotes": ["error", "single"], "semi": ["error", "never"], "no-unused-vars": ["warn"], - "no-console": 0 + "no-console": ["warn", { "allow": ["error"] }], + "eqeqeq": ["error", "always"], + "getter-return": ["error"], + "id-length": "error", + "no-eval": "error", + "no-trailing-spaces": "error", + "no-with": "error", + "no-unused-expressions": ["error", { "allowShortCircuit": true, "allowTernary": true, "allowTaggedTemplates": true }], + "strict": ["warn", "safe"], + "curly": ["error", "multi-line"], + "unicode-bom": ["error", "never"], + "vars-on-top": "error", + "max-len": [1, 120, 2, { "ignoreComments": true }], + "quote-props": [1, "consistent-as-needed"], + "no-cond-assign": [2, "except-parens"], + "space-infix-ops": 0, + "default-case": 0, + "no-else-return": 0, + "no-param-reassign": 0, + "new-cap": 2 } } diff --git a/package.json b/package.json index 0fd0c42..aa2632a 100644 --- a/package.json +++ b/package.json @@ -11,14 +11,18 @@ }, "homepage": "https://github.com/constgen/neutrino-preset-svelte", "keywords": [ + "svelte", "neutrino", "preset", - "svelte", "neutrino-preset", "webpack" ], + "scripts": { + "test": "npm run lint", + "lint": "eslint --ext .js src/ " + }, "dependencies": { - "svelte": "~1.26.0", + "svelte": "~1.26.1", "neutrino-middleware-svelte-loader": "~3.1.0", "neutrino-middleware-chunk": "~6.1.4", "neutrino-middleware-clean": "~6.1.4", @@ -48,7 +52,7 @@ "ip": "~1.1.5" }, "devDependencies": { - "eslint": "^3.19.0" + "eslint": "^4.3.0" }, "peerDependencies": { "neutrino": "^6.0.0" diff --git a/src/dev-server.js b/src/dev-server.js index 168c11e..869cc3c 100644 --- a/src/dev-server.js +++ b/src/dev-server.js @@ -18,16 +18,16 @@ module.exports = function (neutrino, options = {}) { let publicHost = ip.address('public', 'ipv4') config.devServer - .host(host) - .port(Number(port)) - .https(Boolean(https)) - .contentBase(contentBase) - .historyApiFallback(true) + .host(host) + .port(Number(port)) + .https(Boolean(https)) + .contentBase(contentBase) + .historyApiFallback(true) .hot(true) .headers({ host: publicHost }) - .public(publicHost) //.public(`${publicHost}:${port}`) + .public(publicHost) //.public(`${publicHost}:${port}`) .publicPath('/') .stats({ assets: false, @@ -54,8 +54,8 @@ module.exports = function (neutrino, options = {}) { opn(`${protocol}://${localHost}:${port}`) }) }) - .end() - .entry('index') - .prepend(require.resolve('webpack/hot/dev-server')) - .prepend(`${require.resolve('webpack-dev-server/client')}?${protocol}://${host}:${port}`) + .end() + .entry('index') + .prepend(require.resolve('webpack/hot/dev-server')) + .prepend(`${require.resolve('webpack-dev-server/client')}?${protocol}://${host}:${port}`) } diff --git a/src/html-template.js b/src/html-template.js index 3994de7..b3135f6 100644 --- a/src/html-template.js +++ b/src/html-template.js @@ -19,12 +19,12 @@ module.exports = function (neutrino, options = {}) { inject: 'head', mobile: true, minify: { - collapseWhitespace: true, + collapseWhitespace: true, preserveLineBreaks: true }, - chunksSortMode: function(a, b){ - let aIndex = chunkOrder.indexOf(a.names[0]) - let bIndex = chunkOrder.indexOf(b.names[0]) + chunksSortMode: function(aChunk, bChunk){ + let aIndex = chunkOrder.indexOf(aChunk.names[0]) + let bIndex = chunkOrder.indexOf(bChunk.names[0]) if (aIndex < 0) { return 1 } diff --git a/src/index.js b/src/index.js index 99068c2..dc01b8b 100644 --- a/src/index.js +++ b/src/index.js @@ -79,8 +79,8 @@ module.exports = function (neutrino, options = {}) { neutrino.use(env) neutrino.use(babel, { include: [ - neutrino.options.source, - neutrino.options.tests, + neutrino.options.source, + neutrino.options.tests, require.resolve('./polyfills.js') ], targets: { @@ -94,13 +94,13 @@ module.exports = function (neutrino, options = {}) { neutrino.use(styleLoader) neutrino.use(fontLoader) neutrino.use(imageLoader) - + if (!testRun) { neutrino.use(chunk) } if (devRun) { neutrino.use(devServer, options.server) - } + } else { neutrino.use(progress) neutrino.use(clean, { paths: [neutrino.options.output] }) @@ -115,7 +115,7 @@ module.exports = function (neutrino, options = {}) { config.output.filename('[name].[chunkhash].bundle.js') } - if (eslintLoader) { + if (eslintLoader) { lintRule .pre() eslintLoader