From a29006e115665d8860d2a362f75fb7d45a67d479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=9B=E5=AE=9A=E8=B0=94=E7=9A=84=E7=8C=AB?= Date: Thu, 8 Jun 2017 21:13:33 +0800 Subject: [PATCH 1/4] update: .eslintrc --- .eslintrc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.eslintrc b/.eslintrc index 7f3aebf..889da7e 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,8 +1,8 @@ --- extends: eslint:recommended - -ecmaFeatures: - modules: true +parserOptions: + ecmaFeatures: + modules: true env: es6: true From 2b76bcfb6b67eeaea4b0876cb4243d9791c84764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=9B=E5=AE=9A=E8=B0=94=E7=9A=84=E7=8C=AB?= Date: Sat, 10 Jun 2017 05:14:34 +0800 Subject: [PATCH 2/4] update: eslint@v4.0.0-rc.0 & fix errors --- .eslintrc | 2 +- index.js | 10 +- package.json | 2 +- test/autofix.js | 52 +++++----- test/cache.js | 154 ++++++++++++++--------------- test/formatter-multiple-entries.js | 82 +++++++-------- test/formatter-write.js | 84 ++++++++-------- 7 files changed, 193 insertions(+), 193 deletions(-) diff --git a/.eslintrc b/.eslintrc index 889da7e..da60f3c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -11,7 +11,7 @@ env: rules: indent: [2, 2] # 2 spaces indentation - max-len: [2, 80, 4] + max-len: [2, 120, 4] quotes: [2, "double"] semi: [2, "never"] no-multiple-empty-lines: [2, {"max": 1}] diff --git a/index.js b/index.js index 467d3d1..184f0a8 100644 --- a/index.js +++ b/index.js @@ -88,11 +88,11 @@ function printLinterOutput(res, config, webpack) { reportOutput = messages } var filePath = loaderUtils.interpolateName(webpack, - config.outputReport.filePath, { - content: res.results.map(function(r) { - return r.source - }).join("\n"), - } + config.outputReport.filePath, { + content: res.results.map(function(r) { + return r.source + }).join("\n"), + } ) webpack.emitFile(filePath, reportOutput) } diff --git a/package.json b/package.json index 062d552..6895289 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ }, "devDependencies": { "ava": "^0.17.0", - "eslint": "^3.0.0", + "eslint": "^4.0.0-rc.0", "eslint-friendly-formatter": "^2.0.4", "npmpub": "^3.0.1", "webpack": "^2.2.0" diff --git a/test/autofix.js b/test/autofix.js index a056bd6..c8b58fd 100644 --- a/test/autofix.js +++ b/test/autofix.js @@ -12,33 +12,33 @@ test.before(function() { }) test.cb("loader doesn't throw error if file ok after auto-fixing", -function(t) { - t.plan(2) - webpack(conf( - { - entry: "./test/fixtures/fixable-clone.js", - module: { - loaders: [ - { - test: /\.js$/, - loader: "./index?fix=true", - exclude: /node_modules/, - }, - ], - }, - } - ), - function(err, stats) { - if (err) { - throw err - } - // console.log(stats.compilation.errors) - t.false(stats.hasErrors(), "a good file doesn't give any error") - // console.log(stats.compilation.warnings) - t.false(stats.hasWarnings(), "a good file doesn't give any warning") - t.end() + function(t) { + t.plan(2) + webpack(conf( + { + entry: "./test/fixtures/fixable-clone.js", + module: { + loaders: [ + { + test: /\.js$/, + loader: "./index?fix=true", + exclude: /node_modules/, + }, + ], + }, + } + ), + function(err, stats) { + if (err) { + throw err + } + // console.log(stats.compilation.errors) + t.false(stats.hasErrors(), "a good file doesn't give any error") + // console.log(stats.compilation.warnings) + t.false(stats.hasWarnings(), "a good file doesn't give any warning") + t.end() + }) }) -}) // remove the clone test.after.always(function() { diff --git a/test/cache.js b/test/cache.js index 271d9af..1eb9367 100644 --- a/test/cache.js +++ b/test/cache.js @@ -79,106 +79,106 @@ test.cb("should output files to cache directory", (t) => { }) test.cb.serial("should output json.gz files to standard cache dir by default", -(t) => { - var config = assign({}, globalConfig, { - output: { - path: t.context.directory, - }, - module: { - loaders: [ - { - test: /\.jsx?/, - loader: eslintLoader, - exclude: /node_modules/, - query: { - cache: true, + (t) => { + var config = assign({}, globalConfig, { + output: { + path: t.context.directory, + }, + module: { + loaders: [ + { + test: /\.jsx?/, + loader: eslintLoader, + exclude: /node_modules/, + query: { + cache: true, + }, }, - }, - ], - }, - }) + ], + }, + }) - webpack(config, (err) => { - t.is(err, null) + webpack(config, (err) => { + t.is(err, null) - fs.readdir(defaultCacheDir, (err, files) => { + fs.readdir(defaultCacheDir, (err, files) => { // console.log("CACHE SETTING:", t.context.cache) - files = files.filter((file) => /\b[0-9a-f]{5,40}\.json\.gz\b/.test(file)) - t.is(err, null) - t.true(files.length > 0) - t.end() + files = files.filter((file) => /\b[0-9a-f]{5,40}\.json\.gz\b/.test(file)) + t.is(err, null) + t.true(files.length > 0) + t.end() + }) }) }) -}) test.cb.serial( -"should output files to standard cache dir if set to true in query", -(t) => { - var config = assign({}, globalConfig, { - output: { - path: t.context.directory, - }, - module: { - loaders: [ - { - test: /\.jsx?/, - loader: `${eslintLoader}?cache=true`, - exclude: /node_modules/, - }, - ], - }, - }) + "should output files to standard cache dir if set to true in query", + (t) => { + var config = assign({}, globalConfig, { + output: { + path: t.context.directory, + }, + module: { + loaders: [ + { + test: /\.jsx?/, + loader: `${eslintLoader}?cache=true`, + exclude: /node_modules/, + }, + ], + }, + }) - webpack(config, (err) => { - t.is(err, null) + webpack(config, (err) => { + t.is(err, null) - fs.readdir(defaultCacheDir, (err, files) => { + fs.readdir(defaultCacheDir, (err, files) => { // console.log("CACHE SETTING:", t.context.cache) - files = files.filter((file) => /\b[0-9a-f]{5,40}\.json\.gz\b/.test(file)) + files = files.filter((file) => /\b[0-9a-f]{5,40}\.json\.gz\b/.test(file)) - t.is(err, null) - t.true(files.length > 0) - t.end() + t.is(err, null) + t.true(files.length > 0) + t.end() + }) }) }) -}) test.cb.serial("should read from cache directory if cached file exists", -(t) => { - var config = assign({}, globalConfig, { - output: { - path: t.context.directory, - }, - module: { - loaders: [ - { - test: /\.jsx?/, - loader: eslintLoader, - exclude: /node_modules/, - query: { - cache: t.context.cache, + (t) => { + var config = assign({}, globalConfig, { + output: { + path: t.context.directory, + }, + module: { + loaders: [ + { + test: /\.jsx?/, + loader: eslintLoader, + exclude: /node_modules/, + query: { + cache: t.context.cache, + }, }, - }, - ], - }, - }) - - // @TODO Find a way to know if the file as correctly read without relying on - // Istanbul for coverage. - webpack(config, (err) => { - t.is(err, null) + ], + }, + }) + // @TODO Find a way to know if the file as correctly read without relying on + // Istanbul for coverage. webpack(config, (err) => { t.is(err, null) - fs.readdir(t.context.cache, (err, files) => { + + webpack(config, (err) => { t.is(err, null) - t.true(files.length > 0) - t.end() + fs.readdir(t.context.cache, (err, files) => { + t.is(err, null) + t.true(files.length > 0) + t.end() + }) }) }) - }) -}) + }) test.cb.serial("should have one file per module", (t) => { var config = assign({}, globalConfig, { @@ -283,5 +283,5 @@ function createTestDirectory(baseDirectory, testTitle, cb) { } function escapeDirectory(directory) { - return directory.replace(/[\/?<>\\:*|"\s]/g, "_") + return directory.replace(/[/?<>\\:*|"\s]/g, "_") } \ No newline at end of file diff --git a/test/formatter-multiple-entries.js b/test/formatter-multiple-entries.js index b8e7dd6..f0ccc01 100644 --- a/test/formatter-multiple-entries.js +++ b/test/formatter-multiple-entries.js @@ -5,53 +5,53 @@ var fs = require("fs") var path = require("path") test.cb("eslint-loader can be configured to write multiple eslint result files", -function(t) { - var outputFilename = "outputReport-[name].txt" - var config = conf( - { - entry: [ - "./test/fixtures/error-multi-two.js", - "./test/fixtures/error-multi-one.js", - "./test/fixtures/error-multi.js", - ], - }, - { - formatter: require("eslint/lib/formatters/checkstyle"), - outputReport: { - filePath: outputFilename, + function(t) { + var outputFilename = "outputReport-[name].txt" + var config = conf( + { + entry: [ + "./test/fixtures/error-multi-two.js", + "./test/fixtures/error-multi-one.js", + "./test/fixtures/error-multi.js", + ], }, - } - ) + { + formatter: require("eslint/lib/formatters/checkstyle"), + outputReport: { + filePath: outputFilename, + }, + } + ) - /* Plan for the success count. Failure cases are going to fail anyway so the + /* Plan for the success count. Failure cases are going to fail anyway so the * count being off for those cases doesn't matter. */ - t.plan(config.entry.length * 2) + t.plan(config.entry.length * 2) - webpack(config, - function(err, stats) { - if (err) { - throw err - } + webpack(config, + function(err, stats) { + if (err) { + throw err + } - stats.compilation.errors.forEach(function(error) { - var basename = path.basename(error.module.resource, ".js") - var filename = config.output.path + "outputReport-" + basename + ".txt" + stats.compilation.errors.forEach(function(error) { + var basename = path.basename(error.module.resource, ".js") + var filename = config.output.path + "outputReport-" + basename + ".txt" - try { - var contents = fs.readFileSync(filename, "utf8") + try { + var contents = fs.readFileSync(filename, "utf8") - t.pass("File '" + filename + "' has been created") - t.is( - error.message, - contents, - "File '" + filename + "' Contents should equal output" - ) - } - catch (e) { - t.fail("Expected file '" + filename + "' to have been created:" + e) - } - }) + t.pass("File '" + filename + "' has been created") + t.is( + error.message, + contents, + "File '" + filename + "' Contents should equal output" + ) + } + catch (e) { + t.fail("Expected file '" + filename + "' to have been created:" + e) + } + }) - t.end() + t.end() + }) }) -}) diff --git a/test/formatter-write.js b/test/formatter-write.js index 7323e9e..701c322 100644 --- a/test/formatter-write.js +++ b/test/formatter-write.js @@ -5,53 +5,53 @@ var conf = require("./utils/conf") var fs = require("fs") test.cb("eslint-loader can be configured to write eslint results to a file", -function(t) { - t.plan(2) - - var outputFilename = "outputReport.txt" - var config = conf( - { - entry: "./test/fixtures/error.js", - }, - { - formatter: require("eslint/lib/formatters/checkstyle"), - outputReport: { - filePath: outputFilename, + function(t) { + t.plan(2) + + var outputFilename = "outputReport.txt" + var config = conf( + { + entry: "./test/fixtures/error.js", }, - } - ) - - webpack(config, - function(err, stats) { - if (err) { - throw err - } - - console.log("### Here is a the output of the formatter") - console.log( - "# " + - stats.compilation.errors[0].message - .split("\n") - .join("\n# ") + { + formatter: require("eslint/lib/formatters/checkstyle"), + outputReport: { + filePath: outputFilename, + }, + } ) - fs.readFile(config.output.path + outputFilename, - "utf8", function(err, contents) { + webpack(config, + function(err, stats) { if (err) { - t.fail("Expected file to have been created") - } - else { - t.pass("File has been created") - - t.is( - stats.compilation.errors[0].message, - contents, - "File Contents should equal output" - ) + throw err } - t.end() - + console.log("### Here is a the output of the formatter") + console.log( + "# " + + stats.compilation.errors[0].message + .split("\n") + .join("\n# ") + ) + + fs.readFile(config.output.path + outputFilename, + "utf8", function(err, contents) { + if (err) { + t.fail("Expected file to have been created") + } + else { + t.pass("File has been created") + + t.is( + stats.compilation.errors[0].message, + contents, + "File Contents should equal output" + ) + } + + t.end() + + }) }) }) -}) From 343e0bfee8523927e7f108ab8d0bbae7396581df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=9B=E5=AE=9A=E8=B0=94=E7=9A=84=E7=8C=AB?= Date: Sat, 10 Jun 2017 05:17:29 +0800 Subject: [PATCH 3/4] update: peerdep: eslint<5.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6895289..4f8853c 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "index.js" ], "peerDependencies": { - "eslint": ">=1.6.0 <4.0.0" + "eslint": ">=1.6.0 <5.0.0" }, "dependencies": { "find-cache-dir": "^0.1.1", From 605f9a6f601d78459f098c6fae6c0db9df490f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=9B=E5=AE=9A=E8=B0=94=E7=9A=84=E7=8C=AB?= Date: Mon, 12 Jun 2017 20:57:07 +0800 Subject: [PATCH 4/4] update: eslint@4.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4f8853c..1db548e 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ }, "devDependencies": { "ava": "^0.17.0", - "eslint": "^4.0.0-rc.0", + "eslint": "^4.0.0", "eslint-friendly-formatter": "^2.0.4", "npmpub": "^3.0.1", "webpack": "^2.2.0"