Skip to content

Commit

Permalink
fix support for styllint warn (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
gucong3000 authored Mar 1, 2018
1 parent 8e9607e commit bd585a7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
9 changes: 7 additions & 2 deletions lib/stylint-error.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
'use strict';
const LintError = require('./lint-error');
const STYLLINT_SEVERITY_MAP = {
'warning': 'warn',
};

/**
* stylint错误对象
*
Expand All @@ -16,14 +20,15 @@ class StyLintError extends LintError {
*/
constructor (message) {
const error = {
// 依靠gulp-stylint现有的API无法获取错误等级,暂时先按error处理
severity: 'error',

// 报错插件
plugin: 'StyLint',
};
message.replace(/^(.+?):\s*(.+?)$/gm, function (s, key, value) {
if (/^(?:error|message)$/i.test(key)) {
if (/^(?:error|warn(?:ing)?|info)$/i.test(key)) {
key = key.toLowerCase();
error.severity = STYLLINT_SEVERITY_MAP[key] || key;
key = 'message';
} else if (/^file(?:Name)?$/i.test(key)) {
key = 'fileName';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,5 @@
"shorturl": "node scripts/shorturl",
"test": "nyc npm run test_lang"
},
"version": "2.7.0"
"version": "2.7.1"
}
17 changes: 12 additions & 5 deletions test/stylint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('stylint', function () {
})
.pipe(stylint({
rules: {
colons: 'never',
zeroUnits: {
expect: 'never', error: true,
},
Expand All @@ -30,11 +31,17 @@ describe('stylint', function () {
assert.equal(ex.plugin, 'gulp-reporter');
assert.equal(ex.message, 'Lint failed for: test/fixtures/stylint/novalid.styl');
}).on('finish', () => {
const result = sandbox.getLog().split(/\s*\r?\n\s*/g);
assert.equal(result[0], 'test/fixtures/stylint/novalid.styl');
assert.ok(/\d+:\d+/.test(result[1]));
assert.ok(result[1].endsWith('0 is preferred. Unit value is unnecessary (StyLint)'));
done();
try {
const result = sandbox.getLog().split(/\s*\r?\n\s*/g);
assert.equal(result[0], 'test/fixtures/stylint/novalid.styl');
assert.ok(/\d+:\d+/.test(result[1]));
assert.ok(result[1].endsWith('0 is preferred. Unit value is unnecessary (StyLint)'));
assert.ok(/\d+:\d+/.test(result[2]));
assert.ok(result[2].endsWith('unnecessary colon found (StyLint)'));
done();
} catch (ex) {
done(ex);
}
});
});
});

0 comments on commit bd585a7

Please sign in to comment.