Comparing version 1.4.0 to 1.5.0
# Changelog | ||
## 1.5.0 (2016-03-24) | ||
* Added a `at_least_one_space` value for the `style` option in `spaceAfterPropertyColon`. ([5e9fd1e](https://github.com/lesshint/lesshint/commit/5e9fd1e1d6be23a822394e06f9a8d31bddbac018)) | ||
* Added `units` and `exclude` options to `zeroUnit`. ([728f37a](https://github.com/lesshint/lesshint/commit/728f37a73d117d6352d2bf146fa09240be4453a2)) | ||
* Fixed an issue where `decimalZero` wouldn't check all numbers. ([661cc57](https://github.com/lesshint/lesshint/commit/661cc574e6f7d1c04199339daffa1f83475ae66e)) | ||
* Fixed an issue where `zeroUnit` would erroneously report properties without units. ([728f37a](https://github.com/lesshint/lesshint/commit/728f37a73d117d6352d2bf146fa09240be4453a2)) | ||
## 1.4.0 (2016-03-01) | ||
@@ -3,0 +9,0 @@ * Added the following linters: |
@@ -13,3 +13,3 @@ var gulp = require('gulp'); | ||
gulp.task('coverage', function () { | ||
gulp.task('coverage', ['lint'], function () { | ||
return gulp.src(['./lib/**/*.js']) | ||
@@ -20,3 +20,3 @@ .pipe(istanbul()) | ||
gulp.task('test', ['lint', 'coverage'], function () { | ||
gulp.task('test', ['coverage'], function () { | ||
var mocha = require('gulp-mocha'); | ||
@@ -23,0 +23,0 @@ |
@@ -12,56 +12,65 @@ 'use strict'; | ||
var number; | ||
var value; | ||
var output = { | ||
inclusion: 'with', | ||
type: null | ||
}; | ||
var result = []; | ||
var self = this; | ||
node.forEach('value', function (element) { | ||
value = element.first('dimension'); | ||
value = value && value.first('number'); | ||
}); | ||
node.traverseByType('number', function (element) { | ||
var output; | ||
// Bail if NOT floating point format or no value | ||
if (!value || !(/^-?(\d*\.\d*)/.test(value.content))) { | ||
return; | ||
} | ||
number = element.content; | ||
number = value.content; | ||
/* | ||
* Bail if: | ||
* - Not a floating point number | ||
* - Float parsed as 0 (e.g. 0.0, .0, 0.) | ||
*/ | ||
if (!(/^-?(\d*\.\d*)/.test(number)) || parseFloat(number) === 0) { | ||
return; | ||
} | ||
switch (config.style) { | ||
case 'leading': | ||
if (!/^-?(0|\d+)\.(\d*[^0])$/.test(number)) { | ||
output.type = 'leading'; | ||
} | ||
break; | ||
case 'trailing': | ||
if (!/^-?([^0]\d*)?\.(\d*0)$/.test(number)) { | ||
output.type = 'trailing'; | ||
} | ||
break; | ||
case 'both': | ||
if (!/^-?(0|\d+)\.(\d*0)$/.test(number)) { | ||
output.type = 'leading and trailing'; | ||
} | ||
break; | ||
case 'none': | ||
if (!/^-?([^0]\d*)?\.(\d*[^0])$/.test(number)) { | ||
output.type = 'leading and trailing'; | ||
output.inclusion = 'without'; | ||
} | ||
break; | ||
default: | ||
throw new Error( | ||
'Invalid setting value for decimalZero: ' + config.style | ||
); | ||
} | ||
output = { | ||
inclusion: 'with', | ||
type: null | ||
}; | ||
if (output.type) { | ||
return [{ | ||
column: value.start.column, | ||
line: value.start.line, | ||
message: util.format(this.message, number, output.inclusion, output.type) | ||
}]; | ||
switch (config.style) { | ||
case 'leading': | ||
if (!/^-?(\d+)\.(\d*[1-9])$/.test(number)) { | ||
output.type = 'leading'; | ||
} | ||
break; | ||
case 'trailing': | ||
if (!/^-?([1-9]\d*)?\.(\d*0)$/.test(number)) { | ||
output.type = 'trailing'; | ||
} | ||
break; | ||
case 'both': | ||
if (!/^-?(\d+)\.(\d*0)$/.test(number)) { | ||
output.type = 'leading and trailing'; | ||
} | ||
break; | ||
case 'none': | ||
if (!/^-?([1-9]\d*)?\.(\d*[1-9])$/.test(number)) { | ||
output.type = 'leading and trailing'; | ||
output.inclusion = 'without'; | ||
} | ||
break; | ||
default: | ||
throw new Error( | ||
'Invalid setting value for decimalZero: ' + config.style | ||
); | ||
} | ||
if (output.type) { | ||
result.push({ | ||
column: element.start.column, | ||
line: element.start.line, | ||
message: util.format(self.message, number, output.inclusion, output.type) | ||
}); | ||
} | ||
});//traverseByType('number') | ||
if (result.length > 0) { | ||
return result; | ||
} | ||
} | ||
}; |
@@ -7,3 +7,3 @@ # Available linters | ||
* [decimalZero](#decimalzero) | ||
* [depthLevel](#depthLevel) | ||
* [depthLevel](#depthlevel) | ||
* [duplicateProperty](#duplicateproperty) | ||
@@ -804,5 +804,7 @@ * [emptyRule](#emptyrule) | ||
Option | Description | ||
---------- | ---------- | ||
`style` | `no_unit`, `keep_unit` (**default**) | ||
Option | Description | ||
------------| ---------- | ||
`style` | `no_unit`, `keep_unit` (**default**) | ||
`units` | `string array` additional units to enforce. | ||
`exclude` | `string array` additional properties to exclude. | ||
@@ -809,0 +811,0 @@ ### no_unit |
@@ -11,3 +11,4 @@ 'use strict'; | ||
noSpace: 'Colon after property name should not be followed by any spaces.', | ||
oneSpace: 'Colon after property name should be followed by one space.' | ||
oneSpace: 'Colon after property name should be followed by one space.', | ||
atLeastOneSpace: 'Colon after property name should be followed by at least one space.' | ||
}, | ||
@@ -20,2 +21,3 @@ | ||
var maybeSpace; | ||
var message; | ||
@@ -35,2 +37,4 @@ // Find the colon (south of the spleen) | ||
message = this.message.noSpace; | ||
break; | ||
@@ -42,3 +46,13 @@ case 'one_space': | ||
message = this.message.oneSpace; | ||
break; | ||
case 'at_least_one_space': | ||
if (maybeSpace.type !== 'space') { | ||
valid = false; | ||
} | ||
message = this.message.atLeastOneSpace; | ||
break; | ||
default: | ||
@@ -54,3 +68,3 @@ throw new Error( | ||
line: maybeSpace.start.line, | ||
message: util.format(style === 'no_space' ? this.message.noSpace : this.message.oneSpace) | ||
message: util.format(message) | ||
}]; | ||
@@ -57,0 +71,0 @@ } |
@@ -17,3 +17,21 @@ 'use strict'; | ||
var unit; | ||
var excludedProperties = ['opacity', 'z-index']; | ||
var excludedUnits = []; | ||
var property = node.first('property').first('ident').content; | ||
if (config) { | ||
if (config.exclude && config.exclude.length) { | ||
excludedProperties = excludedProperties.concat(config.exclude); | ||
} | ||
if (config.units && config.units.length) { | ||
excludedUnits = excludedUnits.concat(config.units); | ||
} | ||
} | ||
// The property shouldn't be checked for units | ||
if (property && excludedProperties.indexOf(property) !== -1) { | ||
return; | ||
} | ||
node.forEach('value', function (element) { | ||
@@ -34,8 +52,13 @@ value = element.first('dimension'); | ||
if (!number || parseFloat(number.content) !== 0) { | ||
return null; | ||
return; | ||
} | ||
// Unit is required, nothing to do | ||
// Unit is excluded, nothing to do | ||
if (unit && excludedUnits.indexOf(unit.content) > -1) { | ||
return; | ||
} | ||
// Unit is always required by the CSS spec, nothing to do | ||
if (unit && units.indexOf(unit.content) === -1) { | ||
return null; | ||
return; | ||
} | ||
@@ -59,5 +82,3 @@ | ||
default: | ||
throw new Error( | ||
'Invalid setting value for zeroUnit: ' + config.style | ||
); | ||
throw new Error('Invalid setting value for zeroUnit: ' + config.style); | ||
} | ||
@@ -64,0 +85,0 @@ |
{ | ||
"name": "lesshint", | ||
"description": "A tool to aid you in writing clean and consistent Less.", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"main": "./lib/lesshint.js", | ||
@@ -6,0 +6,0 @@ "author": { |
# lesshint | ||
[![npm](https://img.shields.io/npm/v/lesshint.svg)](https://www.npmjs.com/package/lesshint) | ||
[![Build Status](https://travis-ci.org/lesshint/lesshint.svg?branch=master)](https://travis-ci.org/lesshint/lesshint) | ||
[![Build status](https://ci.appveyor.com/api/projects/status/6ig85uac52imq1i6/branch/master?svg=true)](https://ci.appveyor.com/project/jwilsson/lesshint/branch/master) | ||
[![Build status](https://ci.appveyor.com/api/projects/status/1lkhbq625ww0xk78/branch/master?svg=true)](https://ci.appveyor.com/project/jwilsson/lesshint/branch/master) | ||
[![Coverage Status](https://coveralls.io/repos/lesshint/lesshint/badge.svg?branch=master)](https://coveralls.io/r/lesshint/lesshint?branch=master) | ||
@@ -6,0 +6,0 @@ [![Dependency Status](https://david-dm.org/lesshint/lesshint.svg?theme=shields.io&style=flat)](https://david-dm.org/lesshint/lesshint) |
@@ -93,42 +93,44 @@ 'use strict'; | ||
var expected = [{ | ||
column: 7, | ||
file: 'file.less', | ||
fullPath: 'path/to/file.less', | ||
line: 1, | ||
linter: 'stringQuotes', | ||
message: 'Strings should use single quotes.', | ||
severity: 'warning', | ||
source: '[type="text"], [type=email] {' | ||
}, | ||
{ | ||
column: 22, | ||
file: 'file.less', | ||
fullPath: 'path/to/file.less', | ||
line: 1, | ||
linter: 'attributeQuotes', | ||
message: 'Attribute selectors should use quotes.', | ||
severity: 'warning', | ||
source: '[type="text"], [type=email] {' | ||
}, | ||
{ | ||
column: 1, | ||
file: 'file.less', | ||
fullPath: 'path/to/file.less', | ||
line: 3, | ||
linter: 'propertyOrdering', | ||
message: 'Property ordering is not alphabetized', | ||
severity: 'warning', | ||
source: 'color: red;' | ||
}, | ||
{ | ||
column: 1, | ||
file: 'file.less', | ||
fullPath: 'path/to/file.less', | ||
line: 4, | ||
linter: 'duplicateProperty', | ||
message: 'Duplicate property: "color".', | ||
severity: 'warning', | ||
source: 'color: blue;' | ||
}]; | ||
var expected = [ | ||
{ | ||
column: 7, | ||
file: 'file.less', | ||
fullPath: 'path/to/file.less', | ||
line: 1, | ||
linter: 'stringQuotes', | ||
message: 'Strings should use single quotes.', | ||
severity: 'warning', | ||
source: '[type="text"], [type=email] {' | ||
}, | ||
{ | ||
column: 22, | ||
file: 'file.less', | ||
fullPath: 'path/to/file.less', | ||
line: 1, | ||
linter: 'attributeQuotes', | ||
message: 'Attribute selectors should use quotes.', | ||
severity: 'warning', | ||
source: '[type="text"], [type=email] {' | ||
}, | ||
{ | ||
column: 1, | ||
file: 'file.less', | ||
fullPath: 'path/to/file.less', | ||
line: 3, | ||
linter: 'propertyOrdering', | ||
message: 'Property ordering is not alphabetized', | ||
severity: 'warning', | ||
source: 'color: red;' | ||
}, | ||
{ | ||
column: 1, | ||
file: 'file.less', | ||
fullPath: 'path/to/file.less', | ||
line: 4, | ||
linter: 'duplicateProperty', | ||
message: 'Duplicate property: "color".', | ||
severity: 'warning', | ||
source: 'color: blue;' | ||
} | ||
]; | ||
@@ -135,0 +137,0 @@ var config = { |
@@ -10,242 +10,374 @@ 'use strict'; | ||
describe('#decimalZero()', function () { | ||
it('should allow number without decimal zero when "style" is "leading"', function () { | ||
var source = '.foo { font-size: 1em; }'; | ||
var result; | ||
var ast; | ||
var result; | ||
var ast; | ||
var options; | ||
var expected; | ||
var options = { | ||
style: 'leading' | ||
}; | ||
describe('when "style" is "leading"', function () { | ||
beforeEach(function () { | ||
options = { | ||
style: 'leading' | ||
}; | ||
}); | ||
ast = parseAST(source); | ||
ast = ast.first().first('block').first('declaration'); | ||
it('should allow "0.0"', function () { | ||
ast = parseAST('.foo { font-size: 0.0em; }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
result = linter.lint(options, ast); | ||
result = linter.lint(options, ast); | ||
expect(result).to.be.undefined; | ||
}); | ||
expect(result).to.be.undefined; | ||
}); | ||
it('should allow number with leading decimal zero when "style" is "leading"', function () { | ||
var source = '.foo { font-size: 0.5em; }'; | ||
var result; | ||
var ast; | ||
it('should allow number without decimal zero', function () { | ||
ast = parseAST('.foo { font-size: 1em; }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
var options = { | ||
style: 'leading' | ||
}; | ||
result = linter.lint(options, ast); | ||
ast = parseAST(source); | ||
ast = ast.first().first('block').first('declaration'); | ||
expect(result).to.be.undefined; | ||
}); | ||
result = linter.lint(options, ast); | ||
it('should allow number with leading decimal zero', function () { | ||
ast = parseAST('.foo { font-size: 0.5em; }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
expect(result).to.be.undefined; | ||
}); | ||
result = linter.lint(options, ast); | ||
it('should not allow number without leading decimal zero when "style" is "leading"', function () { | ||
var source = '.foo { font-size: .5em; }'; | ||
var result; | ||
var ast; | ||
expect(result).to.be.undefined; | ||
}); | ||
var expected = [{ | ||
column: 19, | ||
line: 1, | ||
message: '.5 should be written with leading zero.' | ||
}]; | ||
it('should allow decimal number greater than 1 without leading zero', function () { | ||
ast = parseAST('.foo { font-size: 1.25em; }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
var options = { | ||
style: 'leading' | ||
}; | ||
result = linter.lint(options, ast); | ||
ast = parseAST(source); | ||
ast = ast.first().first('block').first('declaration'); | ||
expect(result).to.be.undefined; | ||
}); | ||
result = linter.lint(options, ast); | ||
it('should not allow number without leading decimal zero', function () { | ||
expected = [{ | ||
column: 19, | ||
line: 1, | ||
message: '.5 should be written with leading zero.' | ||
}]; | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
ast = parseAST('.foo { font-size: .5em; }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
it('should allow number without decimal when "style" is "trailing"', function () { | ||
var source = '.foo { font-size: 1em; }'; | ||
var result; | ||
var ast; | ||
result = linter.lint(options, ast); | ||
var options = { | ||
style: 'trailing' | ||
}; | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
ast = parseAST(source); | ||
ast = ast.first().first('block').first('declaration'); | ||
it('should not allow number without leading decimal zero in a function', function () { | ||
expected = [{ | ||
column: 29, | ||
line: 1, | ||
message: '.5 should be written with leading zero.' | ||
}]; | ||
result = linter.lint(options, ast); | ||
ast = parseAST('.foo { color: rgba(0, 0, 0, .5); }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
expect(result).to.be.undefined; | ||
}); | ||
result = linter.lint(options, ast); | ||
it('should allow number without decimal when "style" is "trailing"', function () { | ||
var source = '.foo { font-size: 1em; }'; | ||
var result; | ||
var ast; | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
});//"leading" | ||
var options = { | ||
style: 'trailing' | ||
}; | ||
describe('when "style" is "trailing"', function () { | ||
beforeEach(function () { | ||
options = { | ||
style: 'trailing' | ||
}; | ||
}); | ||
ast = parseAST(source); | ||
ast = ast.first().first('block').first('declaration'); | ||
it('should allow "0.0"', function () { | ||
ast = parseAST('.foo { font-size: 0.0em; }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
result = linter.lint(options, ast); | ||
result = linter.lint(options, ast); | ||
expect(result).to.be.undefined; | ||
}); | ||
expect(result).to.be.undefined; | ||
}); | ||
it('should allow number with trailing decimal zero when "style" is "trailing"', function () { | ||
var source = '.foo { font-size: 1.0em; }'; | ||
var result; | ||
var ast; | ||
it('should allow number without decimal', function () { | ||
ast = parseAST('.foo { font-size: 1em; }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
var options = { | ||
style: 'trailing' | ||
}; | ||
result = linter.lint(options, ast); | ||
ast = parseAST(source); | ||
ast = ast.first().first('block').first('declaration'); | ||
expect(result).to.be.undefined; | ||
}); | ||
result = linter.lint(options, ast); | ||
it('should allow number with trailing decimal zero', function () { | ||
ast = parseAST('.foo { font-size: 1.0em; }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
expect(result).to.be.undefined; | ||
}); | ||
result = linter.lint(options, ast); | ||
it('should not allow number without trailing decimal zero when "style" is "trailing"', function () { | ||
var source = '.foo { font-size: 1.5em; }'; | ||
var result; | ||
var ast; | ||
expect(result).to.be.undefined; | ||
}); | ||
var expected = [{ | ||
column: 19, | ||
line: 1, | ||
message: '1.5 should be written with trailing zero.' | ||
}]; | ||
it('should not allow number without trailing decimal zero', function () { | ||
expected = [{ | ||
column: 19, | ||
line: 1, | ||
message: '1.5 should be written with trailing zero.' | ||
}]; | ||
var options = { | ||
style: 'trailing' | ||
}; | ||
ast = parseAST('.foo { font-size: 1.5em; }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
ast = parseAST(source); | ||
ast = ast.first().first('block').first('declaration'); | ||
result = linter.lint(options, ast); | ||
result = linter.lint(options, ast); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it('should not allow number without trailing decimal zero in a function', function () { | ||
expected = [{ | ||
column: 29, | ||
line: 1, | ||
message: '0.1 should be written with trailing zero.' | ||
}]; | ||
it('should not allow number without trailing decimal zero when "style" is "both"', function () { | ||
var source = '.foo { font-size: 1.5em; }'; | ||
var result; | ||
var ast; | ||
ast = parseAST('.foo { color: rgba(0, 0, 0, 0.1); }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
var expected = [{ | ||
column: 19, | ||
line: 1, | ||
message: '1.5 should be written with leading and trailing zero.' | ||
}]; | ||
result = linter.lint(options, ast); | ||
var options = { | ||
style: 'both' | ||
}; | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
});//"trailing" | ||
ast = parseAST(source); | ||
ast = ast.first().first('block').first('declaration'); | ||
describe('when "style" is "both"', function () { | ||
beforeEach(function () { | ||
options = { | ||
style: 'both' | ||
}; | ||
}); | ||
result = linter.lint(options, ast); | ||
it('should allow "0.0"', function () { | ||
ast = parseAST('.foo { font-size: 0.0em; }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
result = linter.lint(options, ast); | ||
it('should not allow number without leading decimal zero when "style" is "both"', function () { | ||
var source = '.foo { font-size: .50em; }'; | ||
var result; | ||
var ast; | ||
expect(result).to.be.undefined; | ||
}); | ||
var expected = [{ | ||
column: 19, | ||
line: 1, | ||
message: '.50 should be written with leading and trailing zero.' | ||
}]; | ||
it('should allow decimal number greater than 1 without leading zero', function () { | ||
ast = parseAST('.foo { font-size: 1.250em; }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
var options = { | ||
style: 'both' | ||
}; | ||
result = linter.lint(options, ast); | ||
ast = parseAST(source); | ||
ast = ast.first().first('block').first('declaration'); | ||
expect(result).to.be.undefined; | ||
}); | ||
result = linter.lint(options, ast); | ||
it('should not allow number without trailing decimal zero', function () { | ||
expected = [{ | ||
column: 19, | ||
line: 1, | ||
message: '1.5 should be written with leading and trailing zero.' | ||
}]; | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
ast = parseAST('.foo { font-size: 1.5em; }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
it('should not allow number with trailing decimal zero when "style" is "none"', function () { | ||
var source = '.foo { font-size: .50em; }'; | ||
var result; | ||
var ast; | ||
result = linter.lint(options, ast); | ||
var expected = [{ | ||
column: 19, | ||
line: 1, | ||
message: '.50 should be written without leading and trailing zero.' | ||
}]; | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
var options = { | ||
style: 'none' | ||
}; | ||
it('should not allow number without trailing decimal zero in a function', function () { | ||
expected = [{ | ||
column: 29, | ||
line: 1, | ||
message: '1.5 should be written with leading and trailing zero.' | ||
}]; | ||
ast = parseAST(source); | ||
ast = ast.first().first('block').first('declaration'); | ||
ast = parseAST('.foo { color: rgba(0, 0, 0, 1.5); }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
result = linter.lint(options, ast); | ||
result = linter.lint(options, ast); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it('should not allow number with leading decimal zero when "style" is "none"', function () { | ||
var source = '.foo { font-size: 0.5em; }'; | ||
var result; | ||
var ast; | ||
it('should not allow number without leading decimal zero', function () { | ||
expected = [{ | ||
column: 19, | ||
line: 1, | ||
message: '.50 should be written with leading and trailing zero.' | ||
}]; | ||
var expected = [{ | ||
column: 19, | ||
line: 1, | ||
message: '0.5 should be written without leading and trailing zero.' | ||
}]; | ||
ast = parseAST('.foo { font-size: .50em; }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
var options = { | ||
style: 'none' | ||
}; | ||
result = linter.lint(options, ast); | ||
ast = parseAST(source); | ||
ast = ast.first().first('block').first('declaration'); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
result = linter.lint(options, ast); | ||
it('should not allow number without leading decimal zero in a function', function () { | ||
expected = [{ | ||
column: 29, | ||
line: 1, | ||
message: '.50 should be written with leading and trailing zero.' | ||
}]; | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
ast = parseAST('.foo { color: rgba(0, 0, 0, .50); }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
it('should throw on invalid "style" value', function () { | ||
var source = '.foo { font-size: 1.0em; }'; | ||
var lint; | ||
var ast; | ||
result = linter.lint(options, ast); | ||
var options = { | ||
style: 'invalid' | ||
}; | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
});//"both" | ||
ast = parseAST(source); | ||
ast = ast.first().first('block').first('declaration'); | ||
describe('when "style" is "none"', function () { | ||
beforeEach(function () { | ||
options = { | ||
style: 'none' | ||
}; | ||
}); | ||
lint = linter.lint.bind(null, options, ast); | ||
it('should allow "0.0"', function () { | ||
ast = parseAST('.foo { font-size: 0.0em; }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
expect(lint).to.throw(Error); | ||
}); | ||
result = linter.lint(options, ast); | ||
expect(result).to.be.undefined; | ||
}); | ||
it('should not allow number with trailing decimal zero', function () { | ||
expected = [{ | ||
column: 19, | ||
line: 1, | ||
message: '.50 should be written without leading and trailing zero.' | ||
}]; | ||
ast = parseAST('.foo { font-size: .50em; }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
result = linter.lint(options, ast); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it('should not allow number with trailing decimal zero in a function', function () { | ||
expected = [{ | ||
column: 29, | ||
line: 1, | ||
message: '.50 should be written without leading and trailing zero.' | ||
}]; | ||
ast = parseAST('.foo { color: rgba(0, 0, 0, .50); }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
result = linter.lint(options, ast); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it('should not allow number with leading decimal zero', function () { | ||
expected = [{ | ||
column: 19, | ||
line: 1, | ||
message: '0.5 should be written without leading and trailing zero.' | ||
}]; | ||
ast = parseAST('.foo { font-size: 0.5em; }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
result = linter.lint(options, ast); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it('should not allow number with trailing decimal zero in a function', function () { | ||
expected = [{ | ||
column: 29, | ||
line: 1, | ||
message: '0.5 should be written without leading and trailing zero.' | ||
}]; | ||
ast = parseAST('.foo { color: rgba(0, 0, 0, 0.5); }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
result = linter.lint(options, ast); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
});//"none" | ||
describe('with invalid "style" value', function () { | ||
beforeEach(function () { | ||
options = { | ||
style: 'invalid' | ||
}; | ||
}); | ||
it('should throw an error', function () { | ||
var lint; | ||
ast = parseAST('.foo { font-size: 1.0em; }') | ||
.first() | ||
.first('block') | ||
.first('declaration'); | ||
lint = linter.lint.bind(null, options, ast); | ||
expect(lint).to.throw(Error); | ||
}); | ||
});//"invalid" | ||
}); | ||
}); |
@@ -201,12 +201,14 @@ 'use strict'; | ||
var expected = [{ | ||
column: 9, | ||
line: 1, | ||
message: 'Imported file, "_foo.less" should not include the file extension.' | ||
}, | ||
{ | ||
column: 9, | ||
line: 1, | ||
message: 'Imported file, "_foo.less" should not include a leading underscore.' | ||
}]; | ||
var expected = [ | ||
{ | ||
column: 9, | ||
line: 1, | ||
message: 'Imported file, "_foo.less" should not include the file extension.' | ||
}, | ||
{ | ||
column: 9, | ||
line: 1, | ||
message: 'Imported file, "_foo.less" should not include a leading underscore.' | ||
} | ||
]; | ||
@@ -213,0 +215,0 @@ var options = { |
@@ -28,12 +28,14 @@ 'use strict'; | ||
var expected = [{ | ||
column: 2, | ||
line: 2, | ||
message: 'Each property should be on its own line.' | ||
}, | ||
{ | ||
column: 14, | ||
line: 2, | ||
message: 'Each property should be on its own line.' | ||
}]; | ||
var expected = [ | ||
{ | ||
column: 2, | ||
line: 2, | ||
message: 'Each property should be on its own line.' | ||
}, | ||
{ | ||
column: 14, | ||
line: 2, | ||
message: 'Each property should be on its own line.' | ||
} | ||
]; | ||
@@ -277,12 +279,14 @@ ast = parseAST(source); | ||
var expected = [{ | ||
column: 2, | ||
line: 2, | ||
message: 'Each property should be on its own line.' | ||
}, | ||
{ | ||
column: 14, | ||
line: 2, | ||
message: 'Each property should be on its own line.' | ||
}]; | ||
var expected = [ | ||
{ | ||
column: 2, | ||
line: 2, | ||
message: 'Each property should be on its own line.' | ||
}, | ||
{ | ||
column: 14, | ||
line: 2, | ||
message: 'Each property should be on its own line.' | ||
} | ||
]; | ||
@@ -302,12 +306,14 @@ ast = parseAST(source); | ||
var expected = [{ | ||
column: 2, | ||
line: 2, | ||
message: 'Each property should be on its own line.' | ||
}, | ||
{ | ||
column: 14, | ||
line: 2, | ||
message: 'Each property should be on its own line.' | ||
}]; | ||
var expected = [ | ||
{ | ||
column: 2, | ||
line: 2, | ||
message: 'Each property should be on its own line.' | ||
}, | ||
{ | ||
column: 14, | ||
line: 2, | ||
message: 'Each property should be on its own line.' | ||
} | ||
]; | ||
@@ -314,0 +320,0 @@ ast = parseAST(source); |
@@ -10,2 +10,59 @@ 'use strict'; | ||
describe('#spaceAfterPropertyColon()', function () { | ||
it('should allow one space when "style" is "at_least_one_space"', function () { | ||
var source = '.foo { color: red; }'; | ||
var result; | ||
var ast; | ||
var options = { | ||
style: 'at_least_one_space' | ||
}; | ||
ast = parseAST(source); | ||
ast = ast.first().first('block').first('declaration'); | ||
result = linter.lint(options, ast); | ||
expect(result).to.be.undefined; | ||
}); | ||
it('should not tolerate missing space when "style" is "at_least_one_space"', function () { | ||
var source = '.foo { color:red; }'; | ||
var result; | ||
var ast; | ||
var expected = [{ | ||
column: 14, | ||
line: 1, | ||
message: 'Colon after property name should be followed by at least one space.' | ||
}]; | ||
var options = { | ||
style: 'at_least_one_space' | ||
}; | ||
ast = parseAST(source); | ||
ast = ast.first().first('block').first('declaration'); | ||
result = linter.lint(options, ast); | ||
expect(result).to.deep.equal(expected); | ||
}); | ||
it('should allow more than one space when "style" is "at_least_one_space"', function () { | ||
var source = '.foo { color: red; }'; | ||
var result; | ||
var ast; | ||
var options = { | ||
style: 'at_least_one_space' | ||
}; | ||
ast = parseAST(source); | ||
ast = ast.first().first('block').first('declaration'); | ||
result = linter.lint(options, ast); | ||
expect(result).to.be.undefined; | ||
}); | ||
it('should allow one space when "style" is "one_space"', function () { | ||
@@ -12,0 +69,0 @@ var source = '.foo { color: red; }'; |
@@ -95,12 +95,14 @@ 'use strict'; | ||
var expected = [{ | ||
column: 18, | ||
line: 1, | ||
message: 'Semicolon after property value should not be preceded by any space.', | ||
}, | ||
{ | ||
column: 39, | ||
line: 1, | ||
message: 'Semicolon after property value should not be preceded by any space.' | ||
}]; | ||
var expected = [ | ||
{ | ||
column: 18, | ||
line: 1, | ||
message: 'Semicolon after property value should not be preceded by any space.', | ||
}, | ||
{ | ||
column: 39, | ||
line: 1, | ||
message: 'Semicolon after property value should not be preceded by any space.' | ||
} | ||
]; | ||
@@ -124,12 +126,14 @@ var options = { | ||
var expected = [{ | ||
column: 8, | ||
line: 1, | ||
message: 'Semicolon after property value should be preceded by one space.' | ||
}, | ||
{ | ||
column: 20, | ||
line: 1, | ||
message: 'Semicolon after property value should be preceded by one space.' | ||
}]; | ||
var expected = [ | ||
{ | ||
column: 8, | ||
line: 1, | ||
message: 'Semicolon after property value should be preceded by one space.' | ||
}, | ||
{ | ||
column: 20, | ||
line: 1, | ||
message: 'Semicolon after property value should be preceded by one space.' | ||
} | ||
]; | ||
@@ -136,0 +140,0 @@ var options = { |
@@ -32,12 +32,14 @@ 'use strict'; | ||
var expected = [{ | ||
column: 23, | ||
line: 1, | ||
message: 'Commas should be followed by one space.' | ||
}, | ||
{ | ||
column: 27, | ||
line: 1, | ||
message: 'Commas should be followed by one space.' | ||
}]; | ||
var expected = [ | ||
{ | ||
column: 23, | ||
line: 1, | ||
message: 'Commas should be followed by one space.' | ||
}, | ||
{ | ||
column: 27, | ||
line: 1, | ||
message: 'Commas should be followed by one space.' | ||
} | ||
]; | ||
@@ -135,12 +137,14 @@ var options = { | ||
var expected = [{ | ||
column: 19, | ||
line: 1, | ||
message: 'Commas should be preceded by one space.' | ||
}, | ||
{ | ||
column: 24, | ||
line: 1, | ||
message: 'Commas should be preceded by one space.' | ||
}]; | ||
var expected = [ | ||
{ | ||
column: 19, | ||
line: 1, | ||
message: 'Commas should be preceded by one space.' | ||
}, | ||
{ | ||
column: 24, | ||
line: 1, | ||
message: 'Commas should be preceded by one space.' | ||
} | ||
]; | ||
@@ -238,12 +242,14 @@ var options = { | ||
var expected = [{ | ||
column: 19, | ||
line: 1, | ||
message: 'Commas should be preceded and followed by one space.' | ||
}, | ||
{ | ||
column: 24, | ||
line: 1, | ||
message: 'Commas should be preceded and followed by one space.' | ||
}]; | ||
var expected = [ | ||
{ | ||
column: 19, | ||
line: 1, | ||
message: 'Commas should be preceded and followed by one space.' | ||
}, | ||
{ | ||
column: 24, | ||
line: 1, | ||
message: 'Commas should be preceded and followed by one space.' | ||
} | ||
]; | ||
@@ -267,12 +273,14 @@ var options = { | ||
var expected = [{ | ||
column: 24, | ||
line: 1, | ||
message: 'Commas should be preceded and followed by one space.' | ||
}, | ||
{ | ||
column: 29, | ||
line: 1, | ||
message: 'Commas should be preceded and followed by one space.' | ||
}]; | ||
var expected = [ | ||
{ | ||
column: 24, | ||
line: 1, | ||
message: 'Commas should be preceded and followed by one space.' | ||
}, | ||
{ | ||
column: 29, | ||
line: 1, | ||
message: 'Commas should be preceded and followed by one space.' | ||
} | ||
]; | ||
@@ -380,12 +388,14 @@ var options = { | ||
var expected = [{ | ||
column: 23, | ||
line: 1, | ||
message: 'Commas should not be preceded nor followed by any space.' | ||
}, | ||
{ | ||
column: 28, | ||
line: 1, | ||
message: 'Commas should not be preceded nor followed by any space.' | ||
}]; | ||
var expected = [ | ||
{ | ||
column: 23, | ||
line: 1, | ||
message: 'Commas should not be preceded nor followed by any space.' | ||
}, | ||
{ | ||
column: 28, | ||
line: 1, | ||
message: 'Commas should not be preceded nor followed by any space.' | ||
} | ||
]; | ||
@@ -405,12 +415,14 @@ ast = parseAST(source); | ||
var expected = [{ | ||
column: 22, | ||
line: 1, | ||
message: 'Commas should not be preceded nor followed by any space.' | ||
}, | ||
{ | ||
column: 27, | ||
line: 1, | ||
message: 'Commas should not be preceded nor followed by any space.' | ||
}]; | ||
var expected = [ | ||
{ | ||
column: 22, | ||
line: 1, | ||
message: 'Commas should not be preceded nor followed by any space.' | ||
}, | ||
{ | ||
column: 27, | ||
line: 1, | ||
message: 'Commas should not be preceded nor followed by any space.' | ||
} | ||
]; | ||
@@ -531,12 +543,14 @@ var options = { | ||
var expected = [{ | ||
column: 23, | ||
line: 1, | ||
message: 'Commas should not be preceded nor followed by any space.' | ||
}, | ||
{ | ||
column: 28, | ||
line: 1, | ||
message: 'Commas should not be preceded nor followed by any space.' | ||
}]; | ||
var expected = [ | ||
{ | ||
column: 23, | ||
line: 1, | ||
message: 'Commas should not be preceded nor followed by any space.' | ||
}, | ||
{ | ||
column: 28, | ||
line: 1, | ||
message: 'Commas should not be preceded nor followed by any space.' | ||
} | ||
]; | ||
@@ -543,0 +557,0 @@ var options = { |
@@ -112,12 +112,14 @@ 'use strict'; | ||
var expected = [{ | ||
column: 19, | ||
line: 1, | ||
message: 'Opening parenthesis should not be followed by any space.' | ||
}, | ||
{ | ||
column: 33, | ||
line: 1, | ||
message: 'Closing parenthesis should not be preceded by any space.' | ||
}]; | ||
var expected = [ | ||
{ | ||
column: 19, | ||
line: 1, | ||
message: 'Opening parenthesis should not be followed by any space.' | ||
}, | ||
{ | ||
column: 33, | ||
line: 1, | ||
message: 'Closing parenthesis should not be preceded by any space.' | ||
} | ||
]; | ||
@@ -187,12 +189,14 @@ var options = { | ||
var expected = [{ | ||
column: 19, | ||
line: 1, | ||
message: 'Opening parenthesis should not be followed by any space.' | ||
}, | ||
{ | ||
column: 34, | ||
line: 1, | ||
message: 'Closing parenthesis should not be preceded by any space.' | ||
}]; | ||
var expected = [ | ||
{ | ||
column: 19, | ||
line: 1, | ||
message: 'Opening parenthesis should not be followed by any space.' | ||
}, | ||
{ | ||
column: 34, | ||
line: 1, | ||
message: 'Closing parenthesis should not be preceded by any space.' | ||
} | ||
]; | ||
@@ -313,12 +317,14 @@ var options = { | ||
var expected = [{ | ||
column: 19, | ||
line: 1, | ||
message: 'Opening parenthesis should be followed by one space.' | ||
}, | ||
{ | ||
column: 29, | ||
line: 1, | ||
message: 'Closing parenthesis should be preceded by one space.' | ||
}]; | ||
var expected = [ | ||
{ | ||
column: 19, | ||
line: 1, | ||
message: 'Opening parenthesis should be followed by one space.' | ||
}, | ||
{ | ||
column: 29, | ||
line: 1, | ||
message: 'Closing parenthesis should be preceded by one space.' | ||
} | ||
]; | ||
@@ -388,12 +394,14 @@ var options = { | ||
var expected = [{ | ||
column: 19, | ||
line: 1, | ||
message: 'Opening parenthesis should be followed by one space.' | ||
}, | ||
{ | ||
column: 34, | ||
line: 1, | ||
message: 'Closing parenthesis should be preceded by one space.' | ||
}]; | ||
var expected = [ | ||
{ | ||
column: 19, | ||
line: 1, | ||
message: 'Opening parenthesis should be followed by one space.' | ||
}, | ||
{ | ||
column: 34, | ||
line: 1, | ||
message: 'Closing parenthesis should be preceded by one space.' | ||
} | ||
]; | ||
@@ -514,12 +522,14 @@ var options = { | ||
var expected = [{ | ||
column: 8, | ||
line: 1, | ||
message: 'Opening parenthesis should not be followed by any space.' | ||
}, | ||
{ | ||
column: 26, | ||
line: 1, | ||
message: 'Closing parenthesis should not be preceded by any space.' | ||
}]; | ||
var expected = [ | ||
{ | ||
column: 8, | ||
line: 1, | ||
message: 'Opening parenthesis should not be followed by any space.' | ||
}, | ||
{ | ||
column: 26, | ||
line: 1, | ||
message: 'Closing parenthesis should not be preceded by any space.' | ||
} | ||
]; | ||
@@ -589,12 +599,14 @@ var options = { | ||
var expected = [{ | ||
column: 8, | ||
line: 1, | ||
message: 'Opening parenthesis should not be followed by any space.' | ||
}, | ||
{ | ||
column: 27, | ||
line: 1, | ||
message: 'Closing parenthesis should not be preceded by any space.' | ||
}]; | ||
var expected = [ | ||
{ | ||
column: 8, | ||
line: 1, | ||
message: 'Opening parenthesis should not be followed by any space.' | ||
}, | ||
{ | ||
column: 27, | ||
line: 1, | ||
message: 'Closing parenthesis should not be preceded by any space.' | ||
} | ||
]; | ||
@@ -715,12 +727,14 @@ var options = { | ||
var expected = [{ | ||
column: 8, | ||
line: 1, | ||
message: 'Opening parenthesis should be followed by one space.' | ||
}, | ||
{ | ||
column: 17, | ||
line: 1, | ||
message: 'Closing parenthesis should be preceded by one space.' | ||
}]; | ||
var expected = [ | ||
{ | ||
column: 8, | ||
line: 1, | ||
message: 'Opening parenthesis should be followed by one space.' | ||
}, | ||
{ | ||
column: 17, | ||
line: 1, | ||
message: 'Closing parenthesis should be preceded by one space.' | ||
} | ||
]; | ||
@@ -790,12 +804,14 @@ var options = { | ||
var expected = [{ | ||
column: 8, | ||
line: 1, | ||
message: 'Opening parenthesis should be followed by one space.' | ||
}, | ||
{ | ||
column: 27, | ||
line: 1, | ||
message: 'Closing parenthesis should be preceded by one space.' | ||
}]; | ||
var expected = [ | ||
{ | ||
column: 8, | ||
line: 1, | ||
message: 'Opening parenthesis should be followed by one space.' | ||
}, | ||
{ | ||
column: 27, | ||
line: 1, | ||
message: 'Closing parenthesis should be preceded by one space.' | ||
} | ||
]; | ||
@@ -802,0 +818,0 @@ var options = { |
@@ -104,3 +104,3 @@ 'use strict'; | ||
expect(result).to.equal(null); | ||
expect(result).to.be.undefined; | ||
}); | ||
@@ -122,5 +122,58 @@ | ||
expect(result).to.equal(null); | ||
expect(result).to.be.undefined; | ||
}); | ||
it('should not report units on zero values when the unit is configured and "style" is "no_unit"', function () { | ||
var source = '.foo { margin-left: 0zz; }'; | ||
var result; | ||
var ast; | ||
var options = { | ||
style: 'no_unit', | ||
units: ['zz'] | ||
}; | ||
ast = parseAST(source); | ||
ast = ast.first().first('block').first('declaration'); | ||
result = linter.lint(options, ast); | ||
expect(result).to.be.undefined; | ||
}); | ||
it('should not report units on zero values when the the property does not have units and "style" is "no_unit"', function () { | ||
var source = '.bar { z-index: 0; }'; | ||
var result; | ||
var ast; | ||
var options = { | ||
style: 'no_unit' | ||
}; | ||
ast = parseAST(source); | ||
ast = ast.first().first('block').first('declaration'); | ||
result = linter.lint(options, ast); | ||
expect(result).to.be.undefined; | ||
}); | ||
it('should not report units on zero values when the the property does not have units and "style" is "no_unit"', function () { | ||
var source = '.bar { margin-left: 0; }'; | ||
var result; | ||
var ast; | ||
var options = { | ||
style: 'no_unit', | ||
exclude: ['margin-left'] | ||
}; | ||
ast = parseAST(source); | ||
ast = ast.first().first('block').first('declaration'); | ||
result = linter.lint(options, ast); | ||
expect(result).to.be.undefined; | ||
}); | ||
it('should throw on invalid "style" value', function () { | ||
@@ -127,0 +180,0 @@ var source = '.foo { margin-right: 0; }'; |
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
346711
7973