Skip to content

Commit

Permalink
fix(plugin): ignore empty sourcemaps
Browse files Browse the repository at this point in the history
  • Loading branch information
olegskl committed Jan 2, 2018
1 parent 864a21f commit f615bcc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/index.js
Expand Up @@ -96,7 +96,9 @@ module.exports = function gulpStylelint(options) { // eslint-disable-line max-st

const lintPromise = lint(localLintOptions)
.then(lintResult =>
file.sourceMap ?
// Checking for the presence of sourceMap.mappings
// in case sourcemaps are initialized, but still empty:
file.sourceMap && file.sourceMap.mappings ?
applySourcemap(lintResult, file.sourceMap) :
lintResult
)
Expand Down
45 changes: 45 additions & 0 deletions test/sourcemap.spec.js
Expand Up @@ -71,3 +71,48 @@ test('should apply sourcemaps correctly', t => {
}))
.on('error', error => t.pass(`error ${error.code} has been emitted correctly`));
});

test('should ignore empty sourcemaps', t => {
t.plan(6);
gulp
.src(fixtures('original-*.css'))
.pipe(gulpSourcemaps.init()) // empty sourcemaps here
.pipe(gulpStylelint({
config: {rules: {
'declaration-no-important': true
}},
reporters: [{
formatter(lintResult) {
t.deepEqual(
lintResult.map(r => r.source),
[
path.join(__dirname, 'fixtures', 'original-a.css'),
path.join(__dirname, 'fixtures', 'original-b.css')
],
'there are two files'
);
t.equal(
lintResult[0].warnings[0].line,
2,
'original-a.css has an error on line 2'
);
t.equal(
lintResult[0].warnings[0].column,
15,
'original-a.css has an error on column 15'
);
t.equal(
lintResult[1].warnings[0].line,
2,
'original-b.css has an error on line 2'
);
t.equal(
lintResult[1].warnings[0].column,
16,
'original-b.css has an error on column 16'
);
}
}]
}))
.on('error', error => t.pass(`error ${error.code} has been emitted correctly`));
});

0 comments on commit f615bcc

Please sign in to comment.