colorguard
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -5,3 +5,5 @@ var walk = require('rework-walk'); | ||
var colorDiff = require('color-diff'); | ||
var SourceMapConsumer = require('source-map').SourceMapConsumer; | ||
var colors = {}; | ||
var sourceMapConsumer; | ||
@@ -27,16 +29,40 @@ function getWhitelistHashKey(pair) { | ||
function renderConflictLine(data) { | ||
// returns correct column number of the color declaration | ||
// pipetteur finds the position from the beginning of value declaration, | ||
// we need line position instead | ||
function getColumnPositionRelativeToLine(position, which) { | ||
return position.declaration.position[which].column + position.column + position.declaration.property.length; | ||
} | ||
function renderOriginalPosition (position) { | ||
return position.source + ':' + position.line + ':' + position.column; | ||
} | ||
function renderConflictLine (data) { | ||
return '_match_ (_hex_) [line: _lines_]' | ||
.replace('_match_', data[0].match) | ||
.replace('_hex_', data[0].color.hex()) | ||
.replace('_lines_', data.map(function (info) { | ||
// Column calculation is not this simple :( | ||
//return info.declaration.position.start.line + ':' + (info.declaration.position.start.column + info.column); | ||
return info.declaration.position.start.line; | ||
.replace('_match_', data.lines[0].match) | ||
.replace('_hex_', data.lines[0].color.hex()) | ||
.replace('_lines_', data.lines.map(function (info, index) { | ||
var result = info.declaration.position.start.line + ':' + getColumnPositionRelativeToLine(info, 'start'); | ||
if (data.originalLines && data.originalLines.length) { | ||
result += ' (' + renderOriginalPosition(data.originalLines[index]) + ')'; | ||
} | ||
return result; | ||
}).join(', ')); | ||
} | ||
exports.inspect = function (css, options) { | ||
function getOriginalPosition (info) { | ||
return sourceMapConsumer && sourceMapConsumer.originalPositionFor({ | ||
line: info.declaration.position.start.line, | ||
column: getColumnPositionRelativeToLine(info, 'start') | ||
}); | ||
} | ||
exports.inspect = function (css, options, map) { | ||
options = options || {}; | ||
colors = {}; | ||
if (map) { | ||
sourceMapConsumer = new SourceMapConsumer(map); | ||
} | ||
var threshold = typeof options.threshold !== 'undefined' ? options.threshold : 3; | ||
@@ -143,6 +169,8 @@ options.ignore = options.ignore || []; | ||
rgb: colorNames[i], | ||
lines: c1 | ||
lines: c1, | ||
originalLines: sourceMapConsumer && c1.map(getOriginalPosition) || [] | ||
}, { | ||
rgb: colorNames[j], | ||
lines: c2 | ||
lines: c2, | ||
originalLines: sourceMapConsumer && c2.map(getOriginalPosition) || [] | ||
}], | ||
@@ -159,4 +187,4 @@ distance: diffAmount | ||
infoBlock.message = '_1_ is too close (_diffAmount_) to _2_' | ||
.replace('_1_', renderConflictLine(c1)) | ||
.replace('_2_', renderConflictLine(c2)) | ||
.replace('_1_', renderConflictLine(infoBlock.colors[0])) | ||
.replace('_2_', renderConflictLine(infoBlock.colors[1])) | ||
.replace('_diffAmount_', diffAmount); | ||
@@ -163,0 +191,0 @@ |
{ | ||
"name": "colorguard", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Keep a watchful eye on your css colors", | ||
@@ -38,2 +38,4 @@ "main": "index.js", | ||
"rework-walk": "^1.0.0", | ||
"source-map": "^0.2.0", | ||
"source-map-resolve": "^0.3.1", | ||
"yargs": "^1.2.6" | ||
@@ -40,0 +42,0 @@ }, |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
16726
165
0
7
+ Addedsource-map@^0.2.0
+ Addedsource-map-resolve@^0.3.1
+ Addedamdefine@1.0.1(transitive)
+ Addedatob@1.1.3(transitive)
+ Addedsource-map@0.2.0(transitive)
+ Addedsource-map-resolve@0.3.1(transitive)
+ Addedsource-map-url@0.3.0(transitive)