Skip to content

Commit 91051b0

Browse files
committed
Meta tweaks
1 parent 9d12b8f commit 91051b0

File tree

6 files changed

+35
-28
lines changed

6 files changed

+35
-28
lines changed

cli.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
#!/usr/bin/env node
22
'use strict';
33
const meow = require('meow');
4-
54
const findReadmeFile = require('./lib/find-readme-file');
65
const awesomeLint = require('.');
76

7+
const getReporter = name => {
8+
// Check if reporter is an npm package
9+
try {
10+
return require(name).report;
11+
} catch (error) {
12+
if (error.code === 'MODULE_NOT_FOUND') {
13+
console.error(`No reporter found matching \`${name}\`. Using default reporter (vfile-reporter-pretty).`);
14+
} else {
15+
throw error;
16+
}
17+
}
18+
};
19+
820
const main = async () => {
921
const cli = meow(`
1022
Usage
11-
$ awesome-lint <optional input filename>
12-
23+
$ awesome-lint [url|filename]
24+
1325
Options
14-
--reporter, -r Use a custom reporter
26+
--reporter, -r Use a custom reporter
1527
`, {
1628
flags: {
1729
reporter: {
@@ -21,27 +33,15 @@ const main = async () => {
2133
}
2234
});
2335

24-
const options = { };
2536
const input = cli.input[0];
26-
const reporterName = cli.flags.reporter;
2737

28-
if (input) {
29-
options.filename = input;
30-
} else {
31-
options.filename = findReadmeFile(process.cwd());
32-
}
38+
const options = {};
39+
40+
options.filename = input ? input : findReadmeFile(process.cwd());
3341

42+
const reporterName = cli.flags.reporter;
3443
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-
}
44+
options.reporter = getReporter(reporterName);
4545
}
4646

4747
await awesomeLint.report(options);

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@
104104
"vfile-reporter-pretty": "^1.0.2"
105105
},
106106
"devDependencies": {
107-
"ava": "*",
107+
"ava": "^1.2.1",
108108
"sinon": "^6.3.3",
109-
"xo": "*"
109+
"xo": "^0.24.0"
110110
}
111111
}

test/api.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import test from 'ava';
2-
import m from '..';
2+
import lint from '..';
3+
4+
// Because of https://github.com/avajs/ava/issues/2041
5+
// TODO: Remove this when the issue is fixed
6+
process.stderr.isTTY = false;
37

48
test('main', async t => {
5-
t.true((await m({filename: 'test/fixtures/main.md'})).messages.length > 0);
9+
t.true((await lint({filename: 'test/fixtures/main.md'})).messages.length > 0);
610
});
711

812
test('`reporter` option', async t => {
@@ -13,6 +17,7 @@ test('`reporter` option', async t => {
1317
}
1418
};
1519

16-
await m.report({filename: 'test/fixtures/main.md', reporter});
20+
await lint.report({filename: 'test/fixtures/main.md', reporter});
21+
1722
t.true(wasReporterCalled);
1823
});

test/cli.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import test from 'ava';
22
import execa from 'execa';
33

44
test('main', async t => {
5-
const error = await t.throws(execa.stdout('./cli.js', ['test/fixtures/main.md']));
6-
t.regex(error.message, /Missing Awesome badge/);
5+
await t.throwsAsync(
6+
execa.stdout('./cli.js', ['test/fixtures/main.md']),
7+
/Missing Awesome badge/
8+
);
79
});
-9 Bytes
Binary file not shown.
-20 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)