File tree Expand file tree Collapse file tree 4 files changed +47
-4
lines changed Expand file tree Collapse file tree 4 files changed +47
-4
lines changed Original file line number Diff line number Diff line change @@ -8,18 +8,42 @@ const awesomeLint = require('.');
8
8
const main = async ( ) => {
9
9
const cli = meow ( `
10
10
Usage
11
- $ awesome-lint
12
- ` ) ;
11
+ $ awesome-lint <optional input filename>
12
+
13
+ Options
14
+ --reporter, -r Use a custom reporter
15
+ ` , {
16
+ flags : {
17
+ reporter : {
18
+ type : 'string' ,
19
+ alias : 'r'
20
+ }
21
+ }
22
+ } ) ;
13
23
14
24
const options = { } ;
15
25
const input = cli . input [ 0 ] ;
26
+ const reporterName = cli . flags . reporter ;
16
27
17
28
if ( input ) {
18
29
options . filename = input ;
19
30
} else {
20
31
options . filename = findReadmeFile ( process . cwd ( ) ) ;
21
32
}
22
33
34
+ if ( reporterName ) {
35
+ // Check if reporter is an npm package
36
+ try {
37
+ options . reporter = require ( reporterName ) . report ;
38
+ } catch ( error ) {
39
+ if ( error . code === 'MODULE_NOT_FOUND' ) {
40
+ console . log ( `No reporter found matching "${ reporterName } ". Proceeding with default reporter (vfile-reporter-pretty)` ) ;
41
+ } else {
42
+ throw error ;
43
+ }
44
+ }
45
+ }
46
+
23
47
await awesomeLint . report ( options ) ;
24
48
} ;
25
49
Original file line number Diff line number Diff line change @@ -58,6 +58,11 @@ lint.report = async options => {
58
58
59
59
if ( messages . length === 0 ) {
60
60
spinner . succeed ( ) ;
61
+
62
+ if ( options . reporter ) {
63
+ console . log ( options . reporter ( [ ] ) ) ;
64
+ }
65
+
61
66
return ;
62
67
}
63
68
@@ -69,7 +74,9 @@ lint.report = async options => {
69
74
process . exitCode = 1 ;
70
75
71
76
file . path = path . basename ( file . path ) ;
72
- console . log ( vfileReporterPretty ( [ file ] ) ) ;
77
+
78
+ const reporter = options . reporter || vfileReporterPretty ;
79
+ console . log ( reporter ( [ file ] ) ) ;
73
80
} ;
74
81
75
82
module . exports = lint ;
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ Returns a `Promise` for a [`VFile`](https://github.com/wooorm/vfile).
88
88
89
89
#### awesomeLint.report()
90
90
91
- Show the lint output.
91
+ Show the lint output. This can be custom reported by setting ` options.reporter=<function> ` and passing in ` options ` as a parameter.
92
92
93
93
94
94
## Maintainers
Original file line number Diff line number Diff line change @@ -4,3 +4,15 @@ import m from '..';
4
4
test ( 'main' , async t => {
5
5
t . true ( ( await m ( { filename : 'test/fixtures/main.md' } ) ) . messages . length > 0 ) ;
6
6
} ) ;
7
+
8
+ test ( '`reporter` option' , async t => {
9
+ let wasReporterCalled = false ;
10
+ const reporter = reports => {
11
+ if ( reports . length > 0 ) {
12
+ wasReporterCalled = true ;
13
+ }
14
+ } ;
15
+
16
+ await m . report ( { filename : 'test/fixtures/main.md' , reporter} ) ;
17
+ t . true ( wasReporterCalled ) ;
18
+ } ) ;
You can’t perform that action at this time.
0 commit comments