postcss-reporter
Advanced tools
Comparing version 7.0.4 to 7.0.5
var pico = require('picocolors'); | ||
var path = require('path'); | ||
var sortBy = require('lodash.sortby'); | ||
var firstBy = require('thenby'); | ||
var util = require('./util'); | ||
@@ -12,2 +12,21 @@ | ||
function createSortFunction(positionless, sortByPosition) { | ||
var positionValue = 0 | ||
if (positionless === 'any') { positionValue = 1; } | ||
if (positionless === 'first') { positionValue = 2; } | ||
if (positionless === 'last') { positionValue = 0; } | ||
var sortFunction = firstBy((m) => { | ||
if (!m.line) return 1; | ||
return positionValue; | ||
}) | ||
if (sortByPosition) { | ||
sortFunction = sortFunction.thenBy('line').thenBy('column'); | ||
} | ||
return sortFunction; | ||
} | ||
module.exports = function (opts) { | ||
@@ -21,2 +40,4 @@ var options = opts || {}; | ||
var sortFunction = createSortFunction(positionless, sortByPosition); | ||
return function (input) { | ||
@@ -30,19 +51,3 @@ var messages = input.messages.filter(function (message) { | ||
var orderedMessages = sortBy( | ||
messages, | ||
function (m) { | ||
if (!m.line) return 1; | ||
if (positionless === 'any') return 1; | ||
if (positionless === 'first') return 2; | ||
if (positionless === 'last') return 0; | ||
}, | ||
function (m) { | ||
if (!sortByPosition) return 1; | ||
return m.line; | ||
}, | ||
function (m) { | ||
if (!sortByPosition) return 1; | ||
return m.column; | ||
} | ||
); | ||
var orderedMessages = messages.sort(sortFunction); | ||
@@ -49,0 +54,0 @@ var output = '\n'; |
var defaultFormatter = require('./formatter'); | ||
var pico = require('picocolors'); | ||
var util = require('./util'); | ||
var groupBy = require('lodash.groupby'); | ||
var forOwn = require('lodash.forown'); | ||
var difference = require('lodash.difference'); | ||
@@ -51,16 +48,26 @@ module.exports = function (opts = {}) { | ||
var sourceGroupedMessages = groupBy(messagesToLog, (message) => { | ||
return util.getLocation(message).file || resultSource; | ||
}); | ||
var sourceGroupedMessages = messagesToLog.reduce((grouped, message) => { | ||
const key = util.getLocation(message).file || resultSource; | ||
if (!grouped.hasOwnProperty(key)) { | ||
grouped[key] = []; | ||
} | ||
grouped[key].push(message); | ||
return grouped; | ||
}, {}); | ||
var report = ''; | ||
forOwn(sourceGroupedMessages, function (messages, source) { | ||
report += formatter({ | ||
messages: messages, | ||
source: source, | ||
}); | ||
}); | ||
for (const source in sourceGroupedMessages) { | ||
if (sourceGroupedMessages.hasOwnProperty(source)) { | ||
report += formatter({ | ||
messages: sourceGroupedMessages[source], | ||
source: source, | ||
}); | ||
} | ||
} | ||
if (opts.clearReportedMessages) { | ||
result.messages = difference(result.messages, messagesToLog); | ||
result.messages = result.messages.filter(message => !messagesToLog.includes(message)); | ||
} | ||
@@ -70,3 +77,3 @@ | ||
var messagesToClear = result.messages.filter(pluginFilter); | ||
result.messages = difference(result.messages, messagesToClear); | ||
result.messages = result.messages.filter(message => !messagesToClear.includes(message)); | ||
} | ||
@@ -73,0 +80,0 @@ |
@@ -1,3 +0,1 @@ | ||
var get = require('lodash.get'); | ||
exports.getLocation = function (message) { | ||
@@ -11,3 +9,3 @@ var messageNode = message.node; | ||
var messageInput = get(messageNode, 'source.input'); | ||
var messageInput = messageNode && messageNode.source && messageNode.source.input; | ||
@@ -14,0 +12,0 @@ if (!messageInput) return location; |
{ | ||
"name": "postcss-reporter", | ||
"version": "7.0.4", | ||
"version": "7.0.5", | ||
"description": "Log PostCSS messages in the console", | ||
@@ -28,9 +28,5 @@ "main": "index.js", | ||
"dependencies": { | ||
"lodash.difference": "^4.5.0", | ||
"lodash.forown": "^4.4.0", | ||
"lodash.get": "^4.4.2", | ||
"lodash.groupby": "^4.6.0", | ||
"lodash.sortby": "^4.7.0", | ||
"picocolors": "^1.0.0" | ||
"picocolors": "^1.0.0", | ||
"thenby": "^1.3.4" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7737
3
175
+ Addedthenby@^1.3.4
+ Addedthenby@1.3.4(transitive)
- Removedlodash.difference@^4.5.0
- Removedlodash.forown@^4.4.0
- Removedlodash.get@^4.4.2
- Removedlodash.groupby@^4.6.0
- Removedlodash.sortby@^4.7.0
- Removedlodash.difference@4.5.0(transitive)
- Removedlodash.forown@4.4.0(transitive)
- Removedlodash.get@4.4.2(transitive)
- Removedlodash.groupby@4.6.0(transitive)
- Removedlodash.sortby@4.7.0(transitive)