From 2a8a52a150e0615ea3d6f46a12a6389ea09890ab Mon Sep 17 00:00:00 2001 From: Jonathan Wilsson Date: Thu, 16 Mar 2017 21:04:05 +0100 Subject: [PATCH 1/3] Handle both strings and error objects in custom errors (#360) * Handle both strings and error objects in custom errors * Add custom error tests --- lib/errors/lesshint-error.js | 2 +- lib/errors/runner-error.js | 2 +- test/specs/errors/lesshint-error.js | 33 +++++++++++++++++++++++++++++ test/specs/errors/runner-error.js | 30 ++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 test/specs/errors/lesshint-error.js create mode 100644 test/specs/errors/runner-error.js diff --git a/lib/errors/lesshint-error.js b/lib/errors/lesshint-error.js index 2bf01d4b..8b442ff5 100644 --- a/lib/errors/lesshint-error.js +++ b/lib/errors/lesshint-error.js @@ -8,7 +8,7 @@ class LesshintError extends Error { errorPath = errorPath || error.path; - this.message = error.message; + this.message = error.message || error; this.name = this.constructor.name; this.path = path.resolve(process.cwd(), errorPath); this.stack = error.stack; diff --git a/lib/errors/runner-error.js b/lib/errors/runner-error.js index e31df8c3..8a6e38a8 100644 --- a/lib/errors/runner-error.js +++ b/lib/errors/runner-error.js @@ -4,7 +4,7 @@ class RunnerError extends Error { constructor (error, status) { super(error); - this.message = error.message; + this.message = error.message || error; this.name = this.constructor.name; this.status = status; this.stack = error.stack; diff --git a/test/specs/errors/lesshint-error.js b/test/specs/errors/lesshint-error.js new file mode 100644 index 00000000..8489c5e9 --- /dev/null +++ b/test/specs/errors/lesshint-error.js @@ -0,0 +1,33 @@ +'use strict'; + +const LesshintError = require('../../../lib/errors/lesshint-error'); +const expect = require('chai').expect; +const path = require('path'); + +describe('LesshintError', function () { + it('should handle an Error object', function () { + const message = 'Something went wrong'; + const error = new Error(message); + + const lesshintError = new LesshintError(error, '/path/to/file.less'); + + expect(lesshintError.message).to.equal(message); + }); + + it('should handle a a string', function () { + const message = 'Something went wrong'; + + const lesshintError = new LesshintError(message, '/path/to/file.less'); + + expect(lesshintError.message).to.equal(message); + }); + + it('should resolve paths', function () { + const file = 'file.less'; + const errorPath = path.resolve(process.cwd(), file); + + const lesshintError = new LesshintError('Something went wrong', file); + + expect(lesshintError.path).to.equal(errorPath); + }); +}); diff --git a/test/specs/errors/runner-error.js b/test/specs/errors/runner-error.js new file mode 100644 index 00000000..2d471626 --- /dev/null +++ b/test/specs/errors/runner-error.js @@ -0,0 +1,30 @@ +'use strict'; + +const RunnerError = require('../../../lib/errors/runner-error'); +const expect = require('chai').expect; + +describe('RunnerError', function () { + it('should handle an Error object', function () { + const message = 'Something went wrong'; + const error = new Error(message); + + const runnerError = new RunnerError(error, 1); + + expect(runnerError.message).to.equal(message); + }); + + it('should handle a a string', function () { + const message = 'Something went wrong'; + + const runnerError = new RunnerError(message, 1); + + expect(runnerError.message).to.equal(message); + }); + + it('should set the status', function () { + const status = 1; + const runnerError = new RunnerError('Something went wrong', status); + + expect(runnerError.status).to.equal(status); + }); +}); From 4508e81a6cdd5ddc6b380ee58fea64be57fff6b9 Mon Sep 17 00:00:00 2001 From: amandakalk Date: Fri, 17 Mar 2017 16:42:01 -0400 Subject: [PATCH 2/3] Add check for variable in url quotes linter. (#366) --- lib/linters/url_quotes.js | 5 +++++ test/specs/linters/url_quotes.js | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/linters/url_quotes.js b/lib/linters/url_quotes.js index 17518e50..b4c52f4a 100644 --- a/lib/linters/url_quotes.js +++ b/lib/linters/url_quotes.js @@ -34,6 +34,11 @@ module.exports = { const uri = child.first.next(); const value = uri.value.trim(); + // Ignore variables + if (value.substring(0, 1) === '@') { + return; + } + /** * postcss-values-parser has a bug with url string params surrounded by * spaces. So account for that here. diff --git a/test/specs/linters/url_quotes.js b/test/specs/linters/url_quotes.js index 9bee407b..385ef271 100644 --- a/test/specs/linters/url_quotes.js +++ b/test/specs/linters/url_quotes.js @@ -167,5 +167,16 @@ describe('lesshint', function () { expect(result).to.deep.equal(expected); }); }); + + it('should ignore variables', function () { + const source = '.foo { background-image: url(@bar) }'; + + return spec.parse(source, function (ast) { + const result = spec.linter.lint({}, ast.root.first.first); + + expect(result).to.be.undefined; + }); + }); + }); }); From f30fc75ca08a66f8bd32ebf92b1a157d233202d4 Mon Sep 17 00:00:00 2001 From: Jonathan Wilsson Date: Sat, 18 Mar 2017 12:07:28 +0100 Subject: [PATCH 3/3] Exclude gulpfile from test coverage --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index 5d49144c..6caa1ab5 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,9 @@ "functions": 95, "branches": 95, "check-coverage": true, + "exclude": [ + "gulpfile.js" + ], "reporter": [ "lcov", "text-summary"