diff --git a/Readme.md b/Readme.md index e7bc353..9cd8b52 100644 --- a/Readme.md +++ b/Readme.md @@ -18,11 +18,7 @@ npm install --save-dev standard-loader standard ## Usage -### Webpack 1 - -Webpack 1.x is no longer supported as of [`standard-loader` version `6.0.0`](https://github.com/timoxley/standard-loader/compare/5.0.0...6.0.0). PRs for Webpack 1.x support will be accepted on the [5.x branch](https://github.com/timoxley/standard-loader/tree/5.x). - -### Webpack 2 +### Webpack 2+ ```js // webpack.config.js @@ -39,11 +35,7 @@ const config = { loader: 'standard-loader', exclude: /(node_modules|bower_components)/, options: { - // Emit errors instead of warnings (default = false) - error: false, - // enable snazzy output (default = true) - snazzy: true, - // other config options to be passed through to standard e.g. + // config options to be passed through to standard e.g. parser: 'babel-eslint' } }, @@ -52,9 +44,26 @@ const config = { } } -module.exports = config ``` +### Webpack 1 + +Webpack 1.x is no longer supported as of [`standard-loader` version `6.0.0`](https://github.com/standard/standard-loader/compare/5.0.0...6.0.0). PRs for Webpack 1.x support will be accepted on the [5.x branch](https://github.com/standard/standard-loader/tree/5.x). + +### Configuration Options + +```js +{ + // Emit errors instead of warnings (default = false) + error: false, + // enable snazzy output (default = true) + snazzy: true, + // configure alternative checker e.g. 'standardx' (default = 'standard') + standard: 'standard', + // all other config options are passed through to standard e.g. + parser: 'babel-eslint' +} +``` ### Example Input diff --git a/index.js b/index.js index a53b75e..bd5aafb 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ 'use strict' -var standard = require('standard') +var Standard = require('standard') var format = require('util').format var loaderUtils = require('loader-utils') var snazzy = require('snazzy') @@ -9,10 +9,22 @@ var assign = require('object-assign') module.exports = function standardLoader (input, map) { var webpack = this var callback = webpack.async() + webpack.cacheable() var config = assign({}, loaderUtils.getOptions(webpack)) config.filename = webpack.resourcePath - webpack.cacheable() + let standard = Standard + + // allow configurable 'standard' e.g. standardx + if (config.standard) { + if (typeof config.standard === 'string') { + standard = require(config.standard) + } else { + standard = config.standard + } + } + + delete config.standard standard.lintText(input, config, function (err, result) { if (err) return callback(err, input, map) diff --git a/package.json b/package.json index 0c97c9a..f94c8ae 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "babel-loader": "^6.3.2", "node-libs-browser": "^2.0.0", "standard": "^9.0.0", + "standardx": "^1.0.3", "tape": "^4.6.3", "webpack": "^2.2.1" }, diff --git a/test/fixtures/.eslintrc b/test/fixtures/.eslintrc new file mode 100644 index 0000000..43e9130 --- /dev/null +++ b/test/fixtures/.eslintrc @@ -0,0 +1,5 @@ +{ + "rules": { + "semi": 0 + } +} diff --git a/test/index.js b/test/index.js index 6fc370d..26399d1 100644 --- a/test/index.js +++ b/test/index.js @@ -42,6 +42,48 @@ test('can disable snazzy output', function (t) { }) }) +test('can work with standardx', function (t) { + var preloader = assign({}, config.module.rules[0], { + options: { + standard: 'standardx' + } + }) + + const old = config.module.rules[0] + config.module.rules[0] = preloader + webpack(config, function (err, stats) { + t.ifError(err) + t.ok(!stats.compilation.errors.length, 'has no errors') + t.ok(stats.compilation.warnings.length, 'has some warnings') + t.ok(!stats.compilation.warnings.some(function (warning) { + return /semicolon/gm.test(warning.message) + }), 'has no error about semicolon') + t.end() + }) + config.module.rules[0] = old +}) + +test('can work with standardx as a module', function (t) { + var preloader = assign({}, config.module.rules[0], { + options: { + standard: require('standardx') + } + }) + + const old = config.module.rules[0] + config.module.rules[0] = preloader + webpack(config, function (err, stats) { + t.ifError(err) + t.ok(!stats.compilation.errors.length, 'has no errors') + t.ok(stats.compilation.warnings.length, 'has some warnings') + t.ok(!stats.compilation.warnings.some(function (warning) { + return /semicolon/gm.test(warning.message) + }), 'has no error about semicolon') + t.end() + }) + config.module.rules[0] = old +}) + test('logs error', function (t) { var preloader = assign({}, config.module.rules[0], { options: { diff --git a/yarn.lock b/yarn.lock index ff152a0..183cce1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1070,10 +1070,18 @@ eslint-config-standard-jsx@3.3.0: version "3.3.0" resolved "https://registry.yarnpkg.com/eslint-config-standard-jsx/-/eslint-config-standard-jsx-3.3.0.tgz#cab0801a15a360bf63facb97ab22fbdd88d8a5e0" +eslint-config-standard-jsx@4.0.2: + version "4.0.2" + resolved "https://registry.yarnpkg.com/eslint-config-standard-jsx/-/eslint-config-standard-jsx-4.0.2.tgz#009e53c4ddb1e9ee70b4650ffe63a7f39f8836e1" + eslint-config-standard-jsx@5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/eslint-config-standard-jsx/-/eslint-config-standard-jsx-5.0.0.tgz#4abfac554f38668e0078c664569e7b2384e5d2aa" +eslint-config-standard@10.2.1: + version "10.2.1" + resolved "https://registry.yarnpkg.com/eslint-config-standard/-/eslint-config-standard-10.2.1.tgz#c061e4d066f379dc17cd562c64e819b4dd454591" + eslint-config-standard@11.0.0: version "11.0.0" resolved "https://registry.yarnpkg.com/eslint-config-standard/-/eslint-config-standard-11.0.0.tgz#87ee0d3c9d95382dc761958cbb23da9eea31e0ba" @@ -1082,6 +1090,14 @@ eslint-config-standard@7.1.0: version "7.1.0" resolved "https://registry.yarnpkg.com/eslint-config-standard/-/eslint-config-standard-7.1.0.tgz#47e769ea0739f5b2d5693b1a501c21c9650fafcf" +eslint-import-resolver-node@^0.2.0: + version "0.2.3" + resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.2.3.tgz#5add8106e8c928db2cba232bcd9efa846e3da16c" + dependencies: + debug "^2.2.0" + object-assign "^4.0.1" + resolve "^1.1.6" + eslint-import-resolver-node@^0.3.1: version "0.3.2" resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.2.tgz#58f15fb839b8d0576ca980413476aab2472db66a" @@ -1089,13 +1105,28 @@ eslint-import-resolver-node@^0.3.1: debug "^2.6.9" resolve "^1.5.0" -eslint-module-utils@^2.1.1: +eslint-module-utils@^2.0.0, eslint-module-utils@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.1.1.tgz#abaec824177613b8a95b299639e1b6facf473449" dependencies: debug "^2.6.8" pkg-dir "^1.0.0" +eslint-plugin-import@~2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.2.0.tgz#72ba306fad305d67c4816348a4699a4229ac8b4e" + dependencies: + builtin-modules "^1.1.1" + contains-path "^0.1.0" + debug "^2.2.0" + doctrine "1.5.0" + eslint-import-resolver-node "^0.2.0" + eslint-module-utils "^2.0.0" + has "^1.0.1" + lodash.cond "^4.3.0" + minimatch "^3.0.3" + pkg-up "^1.0.0" + eslint-plugin-import@~2.8.0: version "2.8.0" resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.8.0.tgz#fa1b6ef31fcb3c501c09859c1b86f1fc5b986894" @@ -1111,6 +1142,16 @@ eslint-plugin-import@~2.8.0: minimatch "^3.0.3" read-pkg-up "^2.0.0" +eslint-plugin-node@~4.2.2: + version "4.2.3" + resolved "https://registry.yarnpkg.com/eslint-plugin-node/-/eslint-plugin-node-4.2.3.tgz#c04390ab8dbcbb6887174023d6f3a72769e63b97" + dependencies: + ignore "^3.0.11" + minimatch "^3.0.2" + object-assign "^4.0.1" + resolve "^1.1.7" + semver "5.3.0" + eslint-plugin-node@~6.0.0: version "6.0.1" resolved "https://registry.yarnpkg.com/eslint-plugin-node/-/eslint-plugin-node-6.0.1.tgz#bf19642298064379315d7a4b2a75937376fa05e4" @@ -1124,10 +1165,24 @@ eslint-plugin-promise@~3.4.0: version "3.4.2" resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-3.4.2.tgz#1be2793eafe2d18b5b123b8136c269f804fe7122" +eslint-plugin-promise@~3.5.0: + version "3.5.0" + resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-3.5.0.tgz#78fbb6ffe047201627569e85a6c5373af2a68fca" + eslint-plugin-promise@~3.6.0: version "3.6.0" resolved "https://registry.yarnpkg.com/eslint-plugin-promise/-/eslint-plugin-promise-3.6.0.tgz#54b7658c8f454813dc2a870aff8152ec4969ba75" +eslint-plugin-react@~6.10.0: + version "6.10.3" + resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-6.10.3.tgz#c5435beb06774e12c7db2f6abaddcbf900cd3f78" + dependencies: + array.prototype.find "^2.0.1" + doctrine "^1.2.2" + has "^1.0.1" + jsx-ast-utils "^1.3.4" + object.assign "^4.0.4" + eslint-plugin-react@~6.9.0: version "6.9.0" resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-6.9.0.tgz#54c2e9906b76f9d10142030bdc34e9d6840a0bb2" @@ -1204,6 +1259,46 @@ eslint@~3.18.0: text-table "~0.2.0" user-home "^2.0.0" +eslint@~3.19.0: + version "3.19.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-3.19.0.tgz#c8fc6201c7f40dd08941b87c085767386a679acc" + dependencies: + babel-code-frame "^6.16.0" + chalk "^1.1.3" + concat-stream "^1.5.2" + debug "^2.1.1" + doctrine "^2.0.0" + escope "^3.6.0" + espree "^3.4.0" + esquery "^1.0.0" + estraverse "^4.2.0" + esutils "^2.0.2" + file-entry-cache "^2.0.0" + glob "^7.0.3" + globals "^9.14.0" + ignore "^3.2.0" + imurmurhash "^0.1.4" + inquirer "^0.12.0" + is-my-json-valid "^2.10.0" + is-resolvable "^1.0.0" + js-yaml "^3.5.1" + json-stable-stringify "^1.0.0" + levn "^0.3.0" + lodash "^4.0.0" + mkdirp "^0.5.0" + natural-compare "^1.4.0" + optionator "^0.8.2" + path-is-inside "^1.0.1" + pluralize "^1.2.1" + progress "^1.1.8" + require-uncached "^1.0.2" + shelljs "^0.7.5" + strip-bom "^3.0.0" + strip-json-comments "~2.0.1" + table "^3.7.8" + text-table "~0.2.0" + user-home "^2.0.0" + eslint@~4.18.0: version "4.18.2" resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.18.2.tgz#0f81267ad1012e7d2051e186a9004cc2267b8d45" @@ -1623,6 +1718,10 @@ has-flag@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd" +has-symbols@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/has-symbols/-/has-symbols-1.0.0.tgz#ba1a8f1af2a0fc39650f5c850367704122063b44" + has-unicode@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/has-unicode/-/has-unicode-2.0.1.tgz#e0e6fe6a28cf51138855e086d1691e771de2a8b9" @@ -1732,7 +1831,7 @@ ieee754@^1.1.4: version "1.1.8" resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.8.tgz#be33d40ac10ef1926701f6f08a2d86fbfd1ad3e4" -ignore@^3.0.9, ignore@^3.2.0, ignore@^3.3.3, ignore@^3.3.6: +ignore@^3.0.11, ignore@^3.0.9, ignore@^3.2.0, ignore@^3.3.3, ignore@^3.3.6: version "3.3.7" resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.7.tgz#612289bfb3c220e186a58118618d5be8c1bab021" @@ -2496,7 +2595,7 @@ object-inspect@~1.5.0: version "1.5.0" resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.5.0.tgz#9d876c11e40f485c79215670281b767488f9bfe3" -object-keys@^1.0.8: +object-keys@^1.0.11, object-keys@^1.0.8: version "1.0.11" resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.11.tgz#c54601778ad560f1142ce0e01bcca8b56d13426d" @@ -2506,6 +2605,15 @@ object-visit@^1.0.0: dependencies: isobject "^3.0.0" +object.assign@^4.0.4: + version "4.1.0" + resolved "https://registry.yarnpkg.com/object.assign/-/object.assign-4.1.0.tgz#968bf1100d7956bb3ca086f006f846b3bc4008da" + dependencies: + define-properties "^1.1.2" + function-bind "^1.1.1" + has-symbols "^1.0.0" + object-keys "^1.0.11" + object.pick@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/object.pick/-/object.pick-1.3.0.tgz#87a10ac4c1694bd2e1cbf53591a66141fb5dd747" @@ -2708,6 +2816,12 @@ pkg-dir@^1.0.0: dependencies: find-up "^1.0.0" +pkg-up@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/pkg-up/-/pkg-up-1.0.0.tgz#3e08fb461525c4421624a33b9f7e6d0af5b05a26" + dependencies: + find-up "^1.0.0" + pluralize@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-1.2.1.tgz#d1a21483fd22bb41e58a12fa3421823140897c45" @@ -2962,7 +3076,7 @@ resolve-url@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a" -resolve@^1.1.6, resolve@^1.3.3, resolve@^1.5.0, resolve@~1.5.0: +resolve@^1.1.6, resolve@^1.1.7, resolve@^1.3.3, resolve@^1.5.0, resolve@~1.5.0: version "1.5.0" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.5.0.tgz#1f09acce796c9a762579f31b2c1cc4c3cddf9f36" dependencies: @@ -3055,6 +3169,10 @@ safe-regex@^1.1.0: version "5.5.0" resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab" +semver@5.3.0: + version "5.3.0" + resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f" + set-blocking@^2.0.0, set-blocking@~2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7" @@ -3257,6 +3375,15 @@ sshpk@^1.7.0: jsbn "~0.1.0" tweetnacl "~0.14.0" +standard-engine@^7.0.0: + version "7.2.0" + resolved "https://registry.yarnpkg.com/standard-engine/-/standard-engine-7.2.0.tgz#d2264d4fe880513750de38095bdc3cac9dc7738d" + dependencies: + deglob "^2.1.0" + get-stdin "^5.0.1" + minimist "^1.1.0" + pkg-conf "^2.0.0" + standard-engine@~5.4.0: version "5.4.0" resolved "https://registry.yarnpkg.com/standard-engine/-/standard-engine-5.4.0.tgz#e0e86959ea0786425d3383e40c1bf70d2f985579" @@ -3267,6 +3394,15 @@ standard-engine@~5.4.0: minimist "^1.1.0" pkg-conf "^2.0.0" +standard-engine@~7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/standard-engine/-/standard-engine-7.0.0.tgz#ebb77b9c8fc2c8165ffa353bd91ba0dff41af690" + dependencies: + deglob "^2.1.0" + get-stdin "^5.0.1" + minimist "^1.1.0" + pkg-conf "^2.0.0" + standard-engine@~8.0.0: version "8.0.1" resolved "https://registry.yarnpkg.com/standard-engine/-/standard-engine-8.0.1.tgz#0b77be8d7ab963675717dbeac1ef1d6675fb62f0" @@ -3296,6 +3432,20 @@ standard@*: eslint-plugin-standard "~3.0.1" standard-engine "~8.0.0" +standard@^10.0.3: + version "10.0.3" + resolved "https://registry.yarnpkg.com/standard/-/standard-10.0.3.tgz#7869bcbf422bdeeaab689a1ffb1fea9677dd50ea" + dependencies: + eslint "~3.19.0" + eslint-config-standard "10.2.1" + eslint-config-standard-jsx "4.0.2" + eslint-plugin-import "~2.2.0" + eslint-plugin-node "~4.2.2" + eslint-plugin-promise "~3.5.0" + eslint-plugin-react "~6.10.0" + eslint-plugin-standard "~3.0.1" + standard-engine "~7.0.0" + standard@^9.0.0: version "9.0.2" resolved "https://registry.yarnpkg.com/standard/-/standard-9.0.2.tgz#9bd3b9467492e212b1914d78553943ff9b48fd99" @@ -3308,6 +3458,13 @@ standard@^9.0.0: eslint-plugin-standard "~2.0.1" standard-engine "~5.4.0" +standardx@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/standardx/-/standardx-1.0.3.tgz#89ea1a4c4dbb87f019e3c5f3117b7f70e678014a" + dependencies: + standard "^10.0.3" + standard-engine "^7.0.0" + static-extend@^0.1.1: version "0.1.2" resolved "https://registry.yarnpkg.com/static-extend/-/static-extend-0.1.2.tgz#60809c39cbff55337226fd5e0b520f341f1fb5c6"