From bd585a70432b66b4bf2d03db8093d2259869fdc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=BA?= Date: Thu, 1 Mar 2018 19:05:41 +0800 Subject: [PATCH] fix support for styllint warn (#213) --- lib/stylint-error.js | 9 +++++++-- package.json | 2 +- test/stylint.test.js | 17 ++++++++++++----- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/stylint-error.js b/lib/stylint-error.js index 84a283e..a8d92bd 100644 --- a/lib/stylint-error.js +++ b/lib/stylint-error.js @@ -1,5 +1,9 @@ 'use strict'; const LintError = require('./lint-error'); +const STYLLINT_SEVERITY_MAP = { + 'warning': 'warn', +}; + /** * stylint错误对象 * @@ -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'; diff --git a/package.json b/package.json index d0d2f02..050809c 100644 --- a/package.json +++ b/package.json @@ -120,5 +120,5 @@ "shorturl": "node scripts/shorturl", "test": "nyc npm run test_lang" }, - "version": "2.7.0" + "version": "2.7.1" } diff --git a/test/stylint.test.js b/test/stylint.test.js index 6d272ab..adbbd98 100644 --- a/test/stylint.test.js +++ b/test/stylint.test.js @@ -18,6 +18,7 @@ describe('stylint', function () { }) .pipe(stylint({ rules: { + colons: 'never', zeroUnits: { expect: 'never', error: true, }, @@ -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); + } }); }); });