1 var chalk = require('chalk');
2 var path = require('path');
3 var symbols = require('log-symbols');
4 var _ = require('lodash');
5 var util = require('./util');
7 module.exports = function(opts) {
8 var options = opts || {};
9 var sortByPosition = (typeof options.sortByPosition !== 'undefined') ? options.sortByPosition : true;
10 var positionless = options.positionless || 'first';
12 return function(input) {
13 var messages = input.messages;
14 var source = input.source;
16 if (!messages.length) return '';
18 var orderedMessages = _.sortBy(
21 if (!m.line) return 1;
22 if (positionless === 'any') return 1;
23 if (positionless === 'first') return 2;
24 if (positionless === 'last') return 0;
27 if (!sortByPosition) return 1;
31 if (!sortByPosition) return 1;
39 output += chalk.bold.underline(logFrom(source)) + '\n';
42 orderedMessages.forEach(function(w) {
43 output += messageToString(w) + '\n';
48 function messageToString(message) {
49 var location = util.getLocation(message);
53 str += chalk.bold(location.line);
56 if (location.column) {
57 str += chalk.bold(':' + location.column)
60 if (location.line || location.column) {
64 if (!options.noIcon && message.type === 'warning') {
65 str += chalk.yellow(symbols.warning + ' ');
69 if (!options.noPlugin) {
70 str += chalk.yellow(' [' + message.plugin + ']');
75 function logFrom(fromValue) {
76 if (fromValue.charAt(0) === '<') return fromValue;
77 return path.relative(process.cwd(), fromValue).split(path.sep).join('/');