Skip to content

Commit 8c8b587

Browse files
committed
Add sourcemap consumption for accurate output
1 parent f56ba94 commit 8c8b587

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
var checkCSS = require('airtight-css-lint');
22
var loaderUtils = require('loader-utils');
33
var assign = require("object-assign");
4+
var sourceMap = require('source-map');
45

56
function checkCSSLoader(source, options, webpack, map, callback) {
67
var results = [];
78

89
checkCSS(source, function (line, col, msg) {
9-
results.push([ 'Line ' + line + ':' + col + ' - ' + msg ]);
10+
var message = 'Line ' + line + ':' + col + ' - ' + msg;
11+
if (map) {
12+
var smc = new sourceMap.SourceMapConsumer(map);
13+
var originalPos = smc.originalPositionFor({
14+
line: line,
15+
column: col
16+
});
17+
18+
message = originalPos.source + ':' + originalPos.line + ':' + originalPos.column + ' - ' + msg;
19+
}
20+
21+
results.push([message]);
1022
});
1123

1224
if (results.length) {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dependencies": {
1313
"airtight-css-lint": "~0.3.1",
1414
"loader-utils": "^0.2.16",
15-
"object-assign": "^4.1.1"
15+
"object-assign": "^4.1.1",
16+
"source-map": "^0.5.6"
1617
}
1718
}

0 commit comments

Comments
 (0)