Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added output option #176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function run(args) {
.description(packageDetails.description)
.usage('[options] <file ...>')
.option('-c, --config <path>', 'configuration file path')
.option('-o, --output <output>', 'configuration of output; stderr - default, stdout', 'stderr')
.option('-r, --reporter <reporter>', 'error reporter; console - default, inline', 'console')
.parse(args);

Expand Down Expand Up @@ -37,8 +38,13 @@ function run(args) {
});

if (errors.length) {
reporter.writer(errors);
process.exit(2);
if (program.output == 'stderr') {
reporter.writer(errors);
process.exit(2);
} else {
reporter.writer(errors, program.output);
process.exit(0);
}
} else {
process.exit(0);
}
Expand Down
8 changes: 6 additions & 2 deletions lib/reporters/console.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (errors) {
module.exports = function (errors, output = 'stderr') {
if (errors.length) {
var messages = [];

Expand All @@ -10,6 +10,10 @@ module.exports = function (errors) {
messages.push(error.message);
});

console.error(messages.join('\n'));
if (output == 'stderr') {
console.error(messages.join('\n'));
} else {
console.log(messages.join('\n'));
}
}
};
8 changes: 6 additions & 2 deletions lib/reporters/inline.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (errors) {
module.exports = function (errors, output = 'stderr') {
if (errors.length) {
errors.forEach(function (error) {
var message = [
Expand All @@ -8,7 +8,11 @@ module.exports = function (errors) {
' ' + error.msg
];

console.error(message.join(''));
if (output == 'stderr') {
console.error(message.join(''));
} else {
console.log(message.join(''));
}
});
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pug-lint",
"version": "2.6.0",
"version": "2.7.0",
"description": "An unopinionated and configurable linter and style checker for Pug (formerly Jade)",
"author": "Ben Edwards <[email protected]>",
"license": "ISC",
Expand Down