Skip to content
This repository was archived by the owner on Sep 28, 2020. It is now read-only.

Commit c8e6ad5

Browse files
committed
format with prettier
1 parent eba1199 commit c8e6ad5

17 files changed

+686
-666
lines changed

index.js

Lines changed: 85 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
"use strict"
1+
"use strict";
22

3-
var assign = require("object-assign")
4-
var loaderUtils = require("loader-utils")
5-
var objectHash = require("object-hash")
6-
var pkg = require("./package.json")
7-
var createCache = require("loader-fs-cache")
8-
var cache = createCache("eslint-loader")
3+
var assign = require("object-assign");
4+
var loaderUtils = require("loader-utils");
5+
var objectHash = require("object-hash");
6+
var pkg = require("./package.json");
7+
var createCache = require("loader-fs-cache");
8+
var cache = createCache("eslint-loader");
99

10-
var engines = {}
10+
var engines = {};
1111

1212
/**
1313
* Class representing an ESLintError.
@@ -19,10 +19,10 @@ class ESLintError extends Error {
1919
* @param {string} messages - Formatted eslint errors.
2020
*/
2121
constructor(messages) {
22-
super()
23-
this.name = "ESLintError"
24-
this.message = messages
25-
this.stack = ""
22+
super();
23+
this.name = "ESLintError";
24+
this.message = messages;
25+
this.stack = "";
2626
}
2727

2828
/**
@@ -32,7 +32,7 @@ class ESLintError extends Error {
3232
* @return {string} error - A stringified representation of the error.
3333
*/
3434
inspect() {
35-
return this.message
35+
return this.message;
3636
}
3737
}
3838

@@ -47,87 +47,89 @@ class ESLintError extends Error {
4747
function printLinterOutput(res, config, webpack) {
4848
// skip ignored file warning
4949
if (
50-
!(res.warningCount === 1 &&
50+
!(
51+
res.warningCount === 1 &&
5152
res.results[0].messages[0] &&
5253
res.results[0].messages[0].message &&
53-
res.results[0].messages[0].message.indexOf("ignore") > 1)
54+
res.results[0].messages[0].message.indexOf("ignore") > 1
55+
)
5456
) {
5557
// quiet filter done now
5658
// eslint allow rules to be specified in the input between comments
5759
// so we can found warnings defined in the input itself
5860
if (res.warningCount && config.quiet) {
59-
res.warningCount = 0
60-
res.results[0].warningCount = 0
61+
res.warningCount = 0;
62+
res.results[0].warningCount = 0;
6163
res.results[0].messages = res.results[0].messages.filter(function(
6264
message
6365
) {
64-
return message.severity !== 1
65-
})
66+
return message.severity !== 1;
67+
});
6668
}
6769

6870
// if enabled, use eslint auto-fixing where possible
6971
if (config.fix && res.results[0].output) {
70-
var eslint = require(config.eslintPath)
71-
eslint.CLIEngine.outputFixes(res)
72+
var eslint = require(config.eslintPath);
73+
eslint.CLIEngine.outputFixes(res);
7274
}
7375

7476
if (res.errorCount || res.warningCount) {
7577
// add filename for each results so formatter can have relevant filename
7678
res.results.forEach(function(r) {
77-
r.filePath = webpack.resourcePath
78-
})
79-
var messages = config.formatter(res.results)
79+
r.filePath = webpack.resourcePath;
80+
});
81+
var messages = config.formatter(res.results);
8082

8183
if (config.outputReport && config.outputReport.filePath) {
82-
var reportOutput
84+
var reportOutput;
8385
// if a different formatter is passed in as an option use that
8486
if (config.outputReport.formatter) {
85-
reportOutput = config.outputReport.formatter(res.results)
86-
}
87-
else {
88-
reportOutput = messages
87+
reportOutput = config.outputReport.formatter(res.results);
88+
} else {
89+
reportOutput = messages;
8990
}
90-
var filePath = loaderUtils.interpolateName(webpack,
91-
config.outputReport.filePath, {
92-
content: res.results.map(function(r) {
93-
return r.source
94-
}).join("\n"),
91+
var filePath = loaderUtils.interpolateName(
92+
webpack,
93+
config.outputReport.filePath,
94+
{
95+
content: res.results
96+
.map(function(r) {
97+
return r.source;
98+
})
99+
.join("\n")
95100
}
96-
)
97-
webpack.emitFile(filePath, reportOutput)
101+
);
102+
webpack.emitFile(filePath, reportOutput);
98103
}
99104

100105
// default behavior: emit error only if we have errors
101-
var emitter = res.errorCount ? webpack.emitError : webpack.emitWarning
106+
var emitter = res.errorCount ? webpack.emitError : webpack.emitWarning;
102107

103108
// force emitError or emitWarning if user want this
104109
if (config.emitError) {
105-
emitter = webpack.emitError
106-
}
107-
else if (config.emitWarning) {
108-
emitter = webpack.emitWarning
110+
emitter = webpack.emitError;
111+
} else if (config.emitWarning) {
112+
emitter = webpack.emitWarning;
109113
}
110114

111115
if (emitter) {
112116
if (config.failOnError && res.errorCount) {
113117
throw new ESLintError(
114118
"Module failed because of a eslint error.\n" + messages
115-
)
116-
}
117-
else if (config.failOnWarning && res.warningCount) {
119+
);
120+
} else if (config.failOnWarning && res.warningCount) {
118121
throw new ESLintError(
119122
"Module failed because of a eslint warning.\n" + messages
120-
)
123+
);
121124
}
122125

123-
emitter(new ESLintError(messages))
124-
}
125-
else {
126+
emitter(new ESLintError(messages));
127+
} else {
126128
throw new Error(
127129
"Your module system doesn't support emitWarning. " +
128130
"Update available? \n" +
129131
messages
130-
)
132+
);
131133
}
132134
}
133135
}
@@ -141,24 +143,23 @@ function printLinterOutput(res, config, webpack) {
141143
* @return {void}
142144
*/
143145
module.exports = function(input, map) {
144-
var webpack = this
146+
var webpack = this;
145147

146148
var userOptions = assign(
147149
// user defaults
148150
(webpack.options && webpack.options.eslint) || webpack.query || {},
149151
// loader query string
150152
loaderUtils.getOptions(webpack)
151-
)
153+
);
152154

153-
var userEslintPath = userOptions.eslintPath
154-
var formatter = require("eslint/lib/formatters/stylish")
155+
var userEslintPath = userOptions.eslintPath;
156+
var formatter = require("eslint/lib/formatters/stylish");
155157

156158
if (userEslintPath) {
157159
try {
158-
formatter = require(userEslintPath + "/lib/formatters/stylish")
159-
}
160-
catch (e) {
161-
formatter = require("eslint/lib/formatters/stylish")
160+
formatter = require(userEslintPath + "/lib/formatters/stylish");
161+
} catch (e) {
162+
formatter = require("eslint/lib/formatters/stylish");
162163
}
163164
}
164165

@@ -168,69 +169,68 @@ module.exports = function(input, map) {
168169
formatter: formatter,
169170
cacheIdentifier: JSON.stringify({
170171
"eslint-loader": pkg.version,
171-
eslint: require(userEslintPath || "eslint").version,
172+
eslint: require(userEslintPath || "eslint").version
172173
}),
173-
eslintPath: "eslint",
174+
eslintPath: "eslint"
174175
},
175176
userOptions
176-
)
177+
);
177178

178-
var cacheDirectory = config.cache
179-
var cacheIdentifier = config.cacheIdentifier
179+
var cacheDirectory = config.cache;
180+
var cacheIdentifier = config.cacheIdentifier;
180181

181-
delete config.cacheIdentifier
182+
delete config.cacheIdentifier;
182183

183184
// Create the engine only once per config
184-
var configHash = objectHash(config)
185+
var configHash = objectHash(config);
185186
if (!engines[configHash]) {
186-
var eslint = require(config.eslintPath)
187-
engines[configHash] = new eslint.CLIEngine(config)
187+
var eslint = require(config.eslintPath);
188+
engines[configHash] = new eslint.CLIEngine(config);
188189
}
189190

190-
webpack.cacheable()
191+
webpack.cacheable();
191192

192-
var resourcePath = webpack.resourcePath
193-
var cwd = process.cwd()
193+
var resourcePath = webpack.resourcePath;
194+
var cwd = process.cwd();
194195

195196
// remove cwd from resource path in case webpack has been started from project
196197
// root, to allow having relative paths in .eslintignore
197198
if (resourcePath.indexOf(cwd) === 0) {
198-
resourcePath = resourcePath.substr(cwd.length + 1)
199+
resourcePath = resourcePath.substr(cwd.length + 1);
199200
}
200201

201-
var engine = engines[configHash]
202+
var engine = engines[configHash];
202203
// return early if cached
203204
if (config.cache) {
204-
var callback = webpack.async()
205+
var callback = webpack.async();
205206
return cache(
206207
{
207208
directory: cacheDirectory,
208209
identifier: cacheIdentifier,
209210
options: config,
210211
source: input,
211212
transform: function() {
212-
return lint(engine, input, resourcePath)
213-
},
213+
return lint(engine, input, resourcePath);
214+
}
214215
},
215216
function(err, res) {
216217
if (err) {
217-
return callback(err)
218+
return callback(err);
218219
}
219220

220221
try {
221-
printLinterOutput(res || {}, config, webpack)
222-
}
223-
catch (e) {
224-
err = e
222+
printLinterOutput(res || {}, config, webpack);
223+
} catch (e) {
224+
err = e;
225225
}
226-
return callback(err, input, map)
226+
return callback(err, input, map);
227227
}
228-
)
228+
);
229229
}
230-
printLinterOutput(lint(engine, input, resourcePath), config, webpack)
231-
webpack.callback(null, input, map)
232-
}
230+
printLinterOutput(lint(engine, input, resourcePath), config, webpack);
231+
webpack.callback(null, input, map);
232+
};
233233

234234
function lint(engine, input, resourcePath) {
235-
return engine.executeOnText(input, resourcePath, true)
235+
return engine.executeOnText(input, resourcePath, true);
236236
}

test/autofix.js

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,45 @@
1-
var test = require("ava")
2-
var webpack = require("webpack")
3-
var conf = require("./utils/conf")
4-
var fs = require("fs")
1+
var test = require("ava");
2+
var webpack = require("webpack");
3+
var conf = require("./utils/conf");
4+
var fs = require("fs");
55

66
// clone the "fixable" file, so that we do not lose the original contents
77
// when the fixes are applied to disk
88
test.before(function() {
9-
fs
10-
.createReadStream("./test/fixtures/fixable.js")
11-
.pipe(fs.createWriteStream("./test/fixtures/fixable-clone.js"))
12-
})
9+
fs.createReadStream("./test/fixtures/fixable.js").pipe(
10+
fs.createWriteStream("./test/fixtures/fixable-clone.js")
11+
);
12+
});
1313

14-
test.cb("loader doesn't throw error if file ok after auto-fixing",
15-
function(t) {
16-
t.plan(2)
17-
webpack(conf(
18-
{
19-
entry: "./test/fixtures/fixable-clone.js",
20-
module: {
21-
rules: [
22-
{
23-
test: /\.js$/,
24-
use: "./index?fix=true",
25-
exclude: /node_modules/,
26-
},
27-
],
28-
},
14+
test.cb("loader doesn't throw error if file ok after auto-fixing", function(t) {
15+
t.plan(2);
16+
webpack(
17+
conf({
18+
entry: "./test/fixtures/fixable-clone.js",
19+
module: {
20+
rules: [
21+
{
22+
test: /\.js$/,
23+
use: "./index?fix=true",
24+
exclude: /node_modules/
25+
}
26+
]
2927
}
30-
),
28+
}),
3129
function(err, stats) {
3230
if (err) {
33-
throw err
31+
throw err;
3432
}
3533
// console.log(stats.compilation.errors)
36-
t.false(stats.hasErrors(), "a good file doesn't give any error")
34+
t.false(stats.hasErrors(), "a good file doesn't give any error");
3735
// console.log(stats.compilation.warnings)
38-
t.false(stats.hasWarnings(), "a good file doesn't give any warning")
39-
t.end()
40-
})
41-
})
36+
t.false(stats.hasWarnings(), "a good file doesn't give any warning");
37+
t.end();
38+
}
39+
);
40+
});
4241

4342
// remove the clone
4443
test.after.always(function() {
45-
fs.unlinkSync("./test/fixtures/fixable-clone.js")
46-
})
44+
fs.unlinkSync("./test/fixtures/fixable-clone.js");
45+
});

0 commit comments

Comments
 (0)