Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Sep 28, 2020. It is now read-only.

Commit997cce5

Browse files
ricardogobbosouzaevilebottnawi
authored andcommitted
fix: try load official formatter (#285)
1 parent8cb02a6 commit997cce5

File tree

3 files changed

+66
-23
lines changed

3 files changed

+66
-23
lines changed

‎README.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ This can either be a `boolean` value or the cache directory path(ex: `'./.eslint
107107
If`cache: true` is used, the cache file is written to the`./node_modules/.cache` directory.
108108
This is the recommended usage.
109109

110-
####`formatter` (default:eslintstylish formatter)
110+
####`formatter` (default:"stylish")
111111

112112
Loader accepts a function that will have one argument: an array of eslint messages (object).
113113
The function must return the output as a string.
114-
You can use official eslint formatters.
114+
You can use official[eslint formatters](https://eslint.org/docs/user-guide/formatters/).
115115

116116
```js
117117
module.exports= {
@@ -126,7 +126,7 @@ module.exports = {
126126
// several examples !
127127

128128
// default value
129-
formatter:require("eslint/lib/formatters/stylish"),
129+
formatter:"stylish",
130130

131131
// community formatter
132132
formatter:require("eslint-friendly-formatter"),
@@ -287,7 +287,7 @@ module.exports = {
287287
options: {
288288
outputReport: {
289289
filePath:"checkstyle.xml",
290-
formatter:require("eslint/lib/formatters/checkstyle")
290+
formatter:"checkstyle"
291291
}
292292
}
293293
}

‎index.js‎

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -195,21 +195,6 @@ module.exports = function(input, map) {
195195
userOptions
196196
);
197197

198-
if(typeofconfig.formatter==="string"){
199-
try{
200-
config.formatter=require(config.formatter);
201-
if(
202-
config.formatter&&
203-
typeofconfig.formatter!=="function"&&
204-
typeofconfig.formatter.default==="function"
205-
){
206-
config.formatter=config.formatter.default;
207-
}
208-
}catch(_){
209-
// ignored
210-
}
211-
}
212-
213198
varcacheDirectory=config.cache;
214199
varcacheIdentifier=config.cacheIdentifier;
215200

@@ -221,15 +206,36 @@ module.exports = function(input, map) {
221206
if(!engines[configHash]){
222207
vareslint=require(config.eslintPath);
223208
engines[configHash]=neweslint.CLIEngine(config);
224-
}
225209

226-
varengine=engines[configHash];
227-
if(config.formatter==null||typeofconfig.formatter!=="function"){
228-
config.formatter=engine.getFormatter("stylish");
210+
// Try to get oficial formatter
211+
if(typeofconfig.formatter==="string"){
212+
try{
213+
config.formatter=engines[configHash].getFormatter(config.formatter);
214+
}catch(_){
215+
try{
216+
config.formatter=require(config.formatter);
217+
if(
218+
config.formatter&&
219+
typeofconfig.formatter!=="function"&&
220+
typeofconfig.formatter.default==="function"
221+
){
222+
config.formatter=config.formatter.default;
223+
}
224+
}catch(_){
225+
// ignored
226+
}
227+
}
228+
}
229+
230+
// Get default formatter `stylish` when not defined
231+
if(config.formatter==null||typeofconfig.formatter!=="function"){
232+
config.formatter=engines[configHash].getFormatter("stylish");
233+
}
229234
}
230235

231236
webpack.cacheable();
232237

238+
varengine=engines[configHash];
233239
varresourcePath=webpack.resourcePath;
234240
varcwd=process.cwd();
235241

‎test/formatter-official.js‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* eslint-disable no-console */
2+
vartest=require("ava");
3+
varwebpack=require("webpack");
4+
5+
varconf=require("./utils/conf");
6+
7+
test.cb("eslint-loader can use official formatter",function(t){
8+
t.plan(1);
9+
webpack(
10+
conf(
11+
{
12+
entry:"./test/fixtures/error.js"
13+
},
14+
{
15+
formatter:"table"
16+
}
17+
),
18+
function(err,stats){
19+
if(err){
20+
throwerr;
21+
}
22+
23+
// console.log("### Here is a example of official formatter")
24+
// console.log(
25+
// "# " +
26+
// stats.compilation.errors[0].message
27+
// .split("\n")
28+
// .join("\n# ")
29+
// )
30+
t.truthy(
31+
stats.compilation.errors[0].message,
32+
"webpack have some output with official formatter"
33+
);
34+
t.end();
35+
}
36+
);
37+
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp