Comparing version 2.0.2 to 2.0.3
# Changelog | ||
## 2.0.3 (2016-08-09) | ||
* Fixed an issue where `importPath` wouldn't handle [Less import options](http://lesscss.org/features/#import-options). ([dc099ee](https://github.com/lesshint/lesshint/commit/dc099eeb8bc11db07e487b01fd3f15245eb1bccc)) | ||
* Fixed two issues where `urlFormat` and `urlQuotes` wouldn't report multiple URLs in the same declaration. ([ec5bd4a](https://github.com/lesshint/lesshint/commit/ec5bd4a46c0c9ee4f4ddb6779bc8bbe4e762f7cf)) | ||
* Updated `gulp-mocha` to `3.x`. ([28c80b8](https://github.com/lesshint/lesshint/commit/28c80b86a3ad42888f019c20e3be0c14fd555747)) | ||
## 2.0.2 (2016-07-31) | ||
@@ -3,0 +8,0 @@ * Fixed an issue where the wrong line was reported in `decimalZero`. ([e0c8e94](https://github.com/lesshint/lesshint/commit/e0c8e942fcf7bd0a741e24e3b26aa1a953400d59)) |
@@ -18,5 +18,7 @@ 'use strict'; | ||
var results = []; | ||
var importOptsRx = /(\s+)?\((\s+)?(reference|inline|less|css|once|multiple|optional)(\s+)?\)(\s+)?/gi; | ||
var value; | ||
var file; | ||
var ast; | ||
var params; | ||
@@ -27,3 +29,7 @@ if (node.name !== 'import') { | ||
ast = parser(node.params).parse(); | ||
// temporary fix for https://github.com/lesshint/lesshint/issues/236 | ||
// TODO: postcss-less really needs to be fixed to make this proper. | ||
params = node.params.replace(importOptsRx, ''); | ||
ast = parser(params).parse(); | ||
value = ast.first.first; | ||
@@ -30,0 +36,0 @@ |
@@ -21,4 +21,4 @@ 'use strict'; | ||
}; | ||
var uri = ast.first.first; | ||
var column; | ||
var self = this; | ||
var results = []; | ||
@@ -29,22 +29,35 @@ if (config.style && !style[config.style]) { | ||
if (uri.type !== 'func' || uri.value !== 'url') { | ||
return; | ||
} | ||
// traverse all child value-nodes | ||
// https://github.com/lesshint/lesshint/issues/225 | ||
ast.first.nodes.forEach(function (child) { | ||
var func = child; | ||
var column; | ||
var uri; | ||
uri = uri.first.next(); | ||
if (func.type !== 'func' || func.value !== 'url') { | ||
return; | ||
} | ||
if (!style[config.style](uri.value)) { | ||
// skip over the 'paren' node; the following node is the value node. | ||
uri = func.first.next(); | ||
column = (decl.raws.between ? decl.raws.between.length : 0) + | ||
decl.source.start.column + | ||
decl.prop.length + | ||
uri.source.start.column - 1; | ||
if (!style[config.style](uri.value)) { | ||
return [{ | ||
column: column, | ||
line: decl.source.start.line, | ||
message: util.format(this.message, uri.value, config.style) | ||
}]; | ||
column = (decl.raws.between ? decl.raws.between.length : 0) + | ||
decl.source.start.column + | ||
decl.prop.length + | ||
uri.source.start.column - 1; | ||
results.push({ | ||
column: column, | ||
line: decl.source.start.line, | ||
message: util.format(self.message, uri.value, config.style) | ||
}); | ||
} | ||
}); | ||
if (results.length) { | ||
return results; | ||
} | ||
} | ||
}; |
@@ -11,8 +11,7 @@ 'use strict'; | ||
lint: function urlQuotesLinter (config, node) { | ||
var results = []; | ||
var rSingle = /^\'(.+)\'$/; | ||
var rDouble = /^\"(.+)\"$/; | ||
var column; | ||
var value; | ||
var self = this; | ||
var ast; | ||
var uri; | ||
@@ -25,30 +24,43 @@ // Nothing to check, bail | ||
ast = parser(node.params || node.value).parse(); | ||
uri = ast.first.first; | ||
if (uri.type !== 'func' || uri.value !== 'url') { | ||
return; | ||
} | ||
// traverse all child value-nodes | ||
// https://github.com/lesshint/lesshint/issues/225 | ||
ast.first.nodes.forEach(function (child) { | ||
var func = child; | ||
var uri; | ||
var column; | ||
var value; | ||
uri = uri.first.next(); | ||
value = uri.value.trim(); | ||
if (func.type !== 'func' || func.value !== 'url') { | ||
return; | ||
} | ||
// postcss-values-parser has a bug with url string params surrounded by | ||
// spaces. so account for that here. | ||
// tracking: https://github.com/lesshint/postcss-values-parser/issues/1 | ||
if ((uri.type === 'word' && | ||
!(rSingle.test(value) || rDouble.test(value))) && | ||
uri.type !== 'string') { | ||
// skip over the 'paren' node; the following node is the value node. | ||
uri = func.first.next(); | ||
value = uri.value.trim(); | ||
column = (node.raws.between ? node.raws.between.length : 0) + | ||
node.source.start.column + | ||
(node.prop || node.name).length + | ||
uri.source.start.column - 1; | ||
// postcss-values-parser has a bug with url string params surrounded by | ||
// spaces. so account for that here. | ||
// tracking: https://github.com/lesshint/postcss-values-parser/issues/1 | ||
if ((uri.type === 'word' && | ||
!(rSingle.test(value) || rDouble.test(value))) && | ||
uri.type !== 'string') { | ||
return [{ | ||
column: column, | ||
line: node.source.start.line, | ||
message: this.message | ||
}]; | ||
column = (node.raws.between ? node.raws.between.length : 0) + | ||
node.source.start.column + | ||
(node.prop || node.name).length + | ||
uri.source.start.column - 1; | ||
results.push({ | ||
column: column, | ||
line: node.source.start.line, | ||
message: self.message | ||
}); | ||
} | ||
}); | ||
if (results.length) { | ||
return results; | ||
} | ||
} | ||
}; |
{ | ||
"name": "lesshint", | ||
"description": "A tool to aid you in writing clean and consistent Less.", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"main": "./lib/lesshint.js", | ||
@@ -40,3 +40,3 @@ "author": { | ||
"gulp-istanbul": "^0.10.2", | ||
"gulp-mocha": "^2.1.3", | ||
"gulp-mocha": "^3.0.0", | ||
"rewire": "^2.3.3", | ||
@@ -43,0 +43,0 @@ "rimraf": "^2.4.2", |
@@ -303,2 +303,87 @@ 'use strict'; | ||
}); | ||
describe('#importPath() with Import Option', function () { | ||
it('should allow filename without extension when "filenameExtension" is "false"', function () { | ||
var source = '@import (css) "foo";'; | ||
var options = { | ||
filenameExtension: false, | ||
exclude: [] | ||
}; | ||
return spec.parse(source, function (ast) { | ||
var result = spec.linter.lint(options, ast.root.first); | ||
expect(result).to.be.undefined; | ||
}); | ||
}); | ||
it('should allow filename with .css extension when "filenameExtension" is "false"', function () { | ||
var source = '@import (inline) "foo.css";'; | ||
var options = { | ||
filenameExtension: false, | ||
exclude: [] | ||
}; | ||
return spec.parse(source, function (ast) { | ||
var result = spec.linter.lint(options, ast.root.first); | ||
expect(result).to.be.undefined; | ||
}); | ||
}); | ||
it('should not allow filename with extension when "filenameExtension" is "false"', function () { | ||
var source = '@import (inline) "foo.less";'; | ||
var expected = [{ | ||
column: 9, | ||
line: 1, | ||
message: 'Imported file, "foo.less" should not include the file extension.' | ||
}]; | ||
var options = { | ||
filenameExtension: false, | ||
exclude: [] | ||
}; | ||
return spec.parse(source, function (ast) { | ||
var result = spec.linter.lint(options, ast.root.first); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
}); | ||
it('should allow filename with extension when "filenameExtension" is "true"', function () { | ||
var source = '@import (inline) "foo.less";'; | ||
var options = { | ||
filenameExtension: true, | ||
exclude: [] | ||
}; | ||
return spec.parse(source, function (ast) { | ||
var result = spec.linter.lint(options, ast.root.first); | ||
expect(result).to.be.undefined; | ||
}); | ||
}); | ||
it('should not allow filename without extension when "filenameExtension" is "true"', function () { | ||
var source = '@import (inline) "foo";'; | ||
var expected = [{ | ||
column: 9, | ||
line: 1, | ||
message: 'Imported file, "foo" should include the file extension.' | ||
}]; | ||
var options = { | ||
filenameExtension: true, | ||
exclude: [] | ||
}; | ||
return spec.parse(source, function (ast) { | ||
var result = spec.linter.lint(options, ast.root.first); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -29,2 +29,15 @@ 'use strict'; | ||
it('should allow multiple relative URLs when "style" is "relative"', function () { | ||
var source = '.foo { background-image: url(img/image.jpg), url(img/foo.jpg); }'; | ||
var options = { | ||
style: 'relative' | ||
}; | ||
return spec.parse(source, function (ast) { | ||
var result = spec.linter.lint(options, ast.root.first.first); | ||
expect(result).to.be.undefined; | ||
}); | ||
}); | ||
it('should not allow absolute URLs when "style" is "relative"', function () { | ||
@@ -49,2 +62,28 @@ var source = '.foo { background-image: url(http://example.com/img/image.jpg); }'; | ||
it('should not allow multiple absolute URLs when "style" is "relative"', function () { | ||
var source = '.foo { background-image: url(http://example.com/img/image.jpg), url(http://example.com/img/foo.jpg); }'; | ||
var expected = [ | ||
{ | ||
column: 30, | ||
line: 1, | ||
message: 'URL "http://example.com/img/image.jpg" should be relative.' | ||
}, | ||
{ | ||
column: 69, | ||
line: 1, | ||
message: 'URL "http://example.com/img/foo.jpg" should be relative.' | ||
} | ||
]; | ||
var options = { | ||
style: 'relative' | ||
}; | ||
return spec.parse(source, function (ast) { | ||
var result = spec.linter.lint(options, ast.root.first.first); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
}); | ||
it('should allow absolute URLs when "style" is "absolute"', function () { | ||
@@ -51,0 +90,0 @@ var source = '.foo { background-image: url(http://example.com/img/image.jpg); }'; |
@@ -54,2 +54,12 @@ 'use strict'; | ||
it('should allow single quotes with multiple urls', function () { | ||
var source = '.foo { background-image: url(\'img/image.jpg\'), url(\'img/foo.jpg\'); }'; | ||
return spec.parse(source, function (ast) { | ||
var result = spec.linter.lint({}, ast.root.first.first); | ||
expect(result).to.be.undefined; | ||
}); | ||
}); | ||
it('should allow double quotes', function () { | ||
@@ -65,2 +75,12 @@ var source = '.foo { background-image: url("img/image.jpg"); }'; | ||
it('should allow double quotes with multiple urls', function () { | ||
var source = '.foo { background-image: url("img/image.jpg"), url("img/foo.jpg"); }'; | ||
return spec.parse(source, function (ast) { | ||
var result = spec.linter.lint({}, ast.root.first.first); | ||
expect(result).to.be.undefined; | ||
}); | ||
}); | ||
it('should not allow missing quotes', function () { | ||
@@ -81,2 +101,24 @@ var source = '.foo { background-image: url(img/image.jpg); }'; | ||
it('should not allow missing quotes with multiple urls', function () { | ||
var source = '.foo { background-image: url(img/image.jpg), url(img/foo.jpg); }'; | ||
var expected = [ | ||
{ | ||
column: 30, | ||
line: 1, | ||
message: 'URLs should be enclosed in quotes.' | ||
}, | ||
{ | ||
column: 50, | ||
line: 1, | ||
message: 'URLs should be enclosed in quotes.' | ||
} | ||
]; | ||
return spec.parse(source, function (ast) { | ||
var result = spec.linter.lint({}, ast.root.first.first); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
}); | ||
it('should not allow missing quotes in imports', function () { | ||
@@ -83,0 +125,0 @@ var source = '@import url(http://example.com)'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
373235
7994