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

Quiet Watch #104

Merged
merged 6 commits into from
Feb 12, 2017
Merged
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
3 changes: 2 additions & 1 deletion src/eslint/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,6 @@ export default function eslintHelp(){
if(!result.message){
throw new Error('Help text not received from Eslint.');
}
return parseHelp(result.message);
const eslintOptions = parseHelp(result.message);
return eslintOptions;
};
50 changes: 24 additions & 26 deletions src/formatters/simple-detail.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
// Template Author Sindre Sorhus @eslint
// https://github.com/sindresorhus/eslint-stylish
var chalk = require('chalk');
var table = require('text-table');
var c = require('./helpers/characters');
var Logger = require('../log');
var logger = Logger('simple-detail');
import chalk from 'chalk';
import table from 'text-table';

import c from './helpers/characters';
import Logger from '../log';

const logger = Logger('simple-detail');

logger.debug('loaded');

var tableSettings = {
align: ['', '', 'r'],
stringLength: function (str) {
return chalk.stripColor(str).length;
}
stringLength: (str) => chalk.stripColor(str).length
};

function pluralize(word, count) {
return (count === 1 ? word : word + 's');
}

function simpleDetail(results) {
var totalErrors = 0;
var totalWarnings = 0;
var output = '';
var cleanMsg = '';
var messageTime = chalk.gray('(' + new Date().toLocaleTimeString() + ')');
let totalErrors = 0;
let totalWarnings = 0;
let output = '';
let cleanMsg = '';
let messageTime = chalk.gray(`(${new Date().toLocaleTimeString()})`);
logger.debug(results);
results.forEach(function (result) {
var messages = result.messages;
var warnings = 0;
var errors = 0;
let messages = result.messages;
let warnings = 0;
let errors = 0;
if (!messages.length) {
return;
}

var tableText = table(
let tableText = table(
messages.map(function (message) {
function getMessageType(msg) {
if (msg.fatal || msg.severity === 2) {
Expand All @@ -56,28 +56,26 @@ function simpleDetail(results) {
chalk.gray(message.ruleId || '')];
}), tableSettings);

output += chalk.white.underline(result.filePath) + ' (' + chalk.red(errors) + '/' + chalk.yellow(warnings) + ')' + c.endLine;
output += chalk.white.underline(result.filePath) + ` (${chalk.red(errors)}/${chalk.yellow(warnings)})${c.endLine}`;
output += tableText.split(c.endLine).map(function (el) {
return el.replace(/(\d+)\s+(\d+)/, function (m, p1, p2) {
return chalk.gray(p1 + ':' + p2);
});
return el.replace(/(\d+)\s+(\d+)/, (m, p1, p2) => chalk.gray(`${p1}:${p2}`));
}).join(c.endLine) + c.endLine + c.endLine;
});

if(totalErrors) {
output += chalk.red(c.x + ' ' + totalErrors + ' ' + pluralize('error', totalErrors)) + ' ';
output += chalk.red(`${c.x} ${totalErrors} ${pluralize('error', totalErrors)} `);
}
if (totalWarnings) {
output += chalk.yellow(c.ex + ' ' + totalWarnings + ' ' + pluralize('warning', totalWarnings)) + ' ';
output += chalk.yellow(`${c.ex} ${totalWarnings} ${pluralize('warning', totalWarnings)} `);
}

if(results.length > 0 || !results.length) {
cleanMsg = chalk.green(c.check + ' Clean') + ' ' + messageTime;
cleanMsg = chalk.green(`${c.check} Clean`) + ` ${messageTime}`;
}

output = (totalErrors || totalWarnings) ? output + messageTime + c.endLine : cleanMsg;
output = (totalErrors || totalWarnings) ? `${output}${messageTime}${c.endLine}` : cleanMsg;

return output;
}

module.exports = simpleDetail;
export default simpleDetail;
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint no-process-exit: 0*/
import keypress from 'keypress';

import settings from './settings';
import eslintCli from './eslint/cli';
import helpOptions from './options';
import watcher from './watcher';
Expand Down Expand Up @@ -48,6 +49,8 @@ function keyListener(args, options){

logger.debug('Arguments passed: %o', args);
const parsedOptions = helpOptions.parse(args);
settings.cliOptions = parsedOptions;

logger.debug('Parsing args');
const eslArgs = argParser.parse(args, parsedOptions);
if (!parsedOptions.help) {
Expand Down
17 changes: 15 additions & 2 deletions src/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import eslint from 'eslint';
import _ from 'lodash';
import path from 'path';

import settings from './settings';
import formatter from './formatters/simple-detail';
import Logger from './log';

Expand All @@ -27,6 +28,19 @@ const cliOptionMap = {
cacheFile: 'cacheLocation'
};

function filterWarnings(results){
return _.reduce(results, (curr, result) =>{
if(result.warningCount){
let newResult = _.omit(result, 'messages');
newResult.messages = _.find(result.messages, (m) => m.severity > 1);
curr.push(newResult);
return curr;
}
curr.push(result);
return curr;
}, []);
}

///https://github.com/eslint/eslint/blob/233440e524aa41545b66b2c3c7ca26fe790e32e0/tests/lib/cli-engine.js#L105-L107

export default function watcher(options) {
Expand All @@ -47,8 +61,7 @@ export default function watcher(options) {
if (options.fix) {
eslint.CLIEngine.outputFixes(report);
}

let results = report.results;
const results = settings.cliOptions.quiet ? filterWarnings(report.results) : report.results;
logger.log(formatter(results));
}

Expand Down