Skip to content

Commit bd585a7

Browse files
authored
fix support for styllint warn (#213)
1 parent 8e9607e commit bd585a7

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

lib/stylint-error.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
'use strict';
22
const LintError = require('./lint-error');
3+
const STYLLINT_SEVERITY_MAP = {
4+
'warning': 'warn',
5+
};
6+
37
/**
48
* stylint错误对象
59
*
@@ -16,14 +20,15 @@ class StyLintError extends LintError {
1620
*/
1721
constructor (message) {
1822
const error = {
19-
// 依靠gulp-stylint现有的API无法获取错误等级,暂时先按error处理
2023
severity: 'error',
2124

2225
// 报错插件
2326
plugin: 'StyLint',
2427
};
2528
message.replace(/^(.+?):\s*(.+?)$/gm, function (s, key, value) {
26-
if (/^(?:error|message)$/i.test(key)) {
29+
if (/^(?:error|warn(?:ing)?|info)$/i.test(key)) {
30+
key = key.toLowerCase();
31+
error.severity = STYLLINT_SEVERITY_MAP[key] || key;
2732
key = 'message';
2833
} else if (/^file(?:Name)?$/i.test(key)) {
2934
key = 'fileName';

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,5 @@
120120
"shorturl": "node scripts/shorturl",
121121
"test": "nyc npm run test_lang"
122122
},
123-
"version": "2.7.0"
123+
"version": "2.7.1"
124124
}

test/stylint.test.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe('stylint', function () {
1818
})
1919
.pipe(stylint({
2020
rules: {
21+
colons: 'never',
2122
zeroUnits: {
2223
expect: 'never', error: true,
2324
},
@@ -30,11 +31,17 @@ describe('stylint', function () {
3031
assert.equal(ex.plugin, 'gulp-reporter');
3132
assert.equal(ex.message, 'Lint failed for: test/fixtures/stylint/novalid.styl');
3233
}).on('finish', () => {
33-
const result = sandbox.getLog().split(/\s*\r?\n\s*/g);
34-
assert.equal(result[0], 'test/fixtures/stylint/novalid.styl');
35-
assert.ok(/\d+:\d+/.test(result[1]));
36-
assert.ok(result[1].endsWith('0 is preferred. Unit value is unnecessary (StyLint)'));
37-
done();
34+
try {
35+
const result = sandbox.getLog().split(/\s*\r?\n\s*/g);
36+
assert.equal(result[0], 'test/fixtures/stylint/novalid.styl');
37+
assert.ok(/\d+:\d+/.test(result[1]));
38+
assert.ok(result[1].endsWith('0 is preferred. Unit value is unnecessary (StyLint)'));
39+
assert.ok(/\d+:\d+/.test(result[2]));
40+
assert.ok(result[2].endsWith('unnecessary colon found (StyLint)'));
41+
done();
42+
} catch (ex) {
43+
done(ex);
44+
}
3845
});
3946
});
4047
});

0 commit comments

Comments
 (0)