Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lesshint

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lesshint - npm Package Compare versions

Comparing version 0.5.0 to 0.5.1

3

CHANGELOG.md
# Changelog
## 0.5.1 (2015-05-19)
* Fixed issues with `hexLength`, `hexNotation`, and `hexValidation` where they wouldn't check for hex colors outside declarations (for example variables).
## 0.5.0 (2015-05-17)

@@ -4,0 +7,0 @@ * Added the following linters:

18

lib/linters/hex_length.js

@@ -15,3 +15,2 @@ 'use strict';

var color;
var value;

@@ -24,17 +23,8 @@ // Bail if the linter isn't wanted

// Not applicable, bail
if (node.type !== 'declaration') {
if (node.type !== 'color') {
return null;
}
node.forEach('value', function (element) {
value = element.first('color');
});
color = '#' + node.content;
// No colors found, bail
if (!value) {
return null;
}
color = '#' + value.content;
switch (config.hexLength.style) {

@@ -62,5 +52,5 @@ case 'long':

return {
column: value.start.column,
column: node.start.column,
file: filename,
line: value.start.line,
line: node.start.line,
linter: 'hexLength',

@@ -67,0 +57,0 @@ message: message

@@ -11,3 +11,2 @@ 'use strict';

var color;
var value;

@@ -20,17 +19,8 @@ // Bail if the linter isn't wanted

// Not applicable, bail
if (node.type !== 'declaration') {
if (node.type !== 'color') {
return null;
}
node.forEach('value', function (element) {
value = element.first('color');
});
color = '#' + node.content;
// No colors found, bail
if (!value) {
return null;
}
color = '#' + value.content;
switch (config.hexNotation.style) {

@@ -57,5 +47,5 @@ case 'lowercase':

return {
column: value.start.column,
column: node.start.column,
file: filename,
line: value.start.line,
line: node.start.line,
linter: 'hexNotation',

@@ -62,0 +52,0 @@ message: message

@@ -10,3 +10,2 @@ 'use strict';

var color;
var value;

@@ -19,21 +18,12 @@ // Bail if the linter isn't wanted

// Not applicable, bail
if (node.type !== 'declaration') {
if (node.type !== 'color') {
return null;
}
node.forEach('value', function (element) {
value = element.first('color');
});
// No colors found, bail
if (!value) {
return null;
}
color = '#' + value.content;
color = '#' + node.content;
if (!/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(color)) {
return {
column: value.start.column,
column: node.start.column,
file: filename,
line: value.start.line,
line: node.start.line,
linter: 'hexValidation',

@@ -40,0 +30,0 @@ message: 'Hexadecimal color "' + color + '" should be either three or six characters long.'

@@ -9,3 +9,3 @@ # Available linters

* [borderZero](#borderzero)
* [Comment](#comment)
* [comment](#comment)
* [duplicateProperty](#duplicateproperty)

@@ -90,2 +90,3 @@ * [emptyRule](#emptyrule)

### valid
```css
// Won't get rendered

@@ -92,0 +93,0 @@

{
"name": "lesshint",
"description": "A tool to aid you in writing clean and consistent Less.",
"version": "0.5.0",
"version": "0.5.1",
"main": "./lib/lesshint.js",

@@ -23,3 +23,3 @@ "author": {

"exit": "^0.1.2",
"gonzales-pe": "^3.0.0-26",
"gonzales-pe": "^3.0.0-28",
"lodash.findindex": "^3.2.0",

@@ -26,0 +26,0 @@ "lodash.flatten": "^3.0.2",

@@ -8,4 +8,4 @@ var assert = require('assert');

describe('#hexLength()', function () {
it('should not allow short hand hex values when "style" is "long', function () {
var source = '.foo { color: #ABC; }';
it('should not allow short hand hex values when "style" is "long"', function () {
var source = 'color: #ABC;';
var actual;

@@ -15,3 +15,3 @@ var ast;

var expected = {
column: 15,
column: 8,
file: 'test.less',

@@ -31,3 +31,3 @@ line: 1,

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('color');

@@ -44,3 +44,3 @@ actual = hexLength({

it('should allow longhand hex values when "style" is "long"', function () {
var source = '.foo { color: #AABBCC; }';
var source = 'color: #AABBCC;';
var ast;

@@ -56,3 +56,3 @@

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('color');

@@ -65,4 +65,4 @@ assert.strictEqual(true, hexLength({

it('should not allow longhand hex values when "style" is "short', function () {
var source = '.foo { color: #AABBCC; }';
it('should not allow longhand hex values when "style" is "short"', function () {
var source = 'color: #AABBCC;';
var actual;

@@ -72,3 +72,3 @@ var ast;

var expected = {
column: 15,
column: 8,
file: 'test.less',

@@ -88,3 +88,3 @@ line: 1,

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('color');

@@ -101,3 +101,3 @@ actual = hexLength({

it('should allow short hand hex values when "style" is "short"', function () {
var source = '.foo { color: #ABC; }';
var source = 'color: #ABC;';
var ast;

@@ -113,3 +113,3 @@

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('color');

@@ -123,3 +123,3 @@ assert.strictEqual(true, hexLength({

it('should allow longhand hex values can can be written with a shorthand when "style" is "short"', function () {
var source = '.foo { color: #4B7A19; }';
var source = 'color: #4B7A19;';
var ast;

@@ -135,3 +135,3 @@

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('color');

@@ -145,7 +145,7 @@ assert.strictEqual(true, hexLength({

it('should find hex values in background declarations', function () {
var source = '.foo { background: url(test.png) no-repeat #AABBCC; }';
var source = 'background: url(test.png) no-repeat #AABBCC;';
var ast;
var expected = {
column: 44,
column: 37,
file: 'test.less',

@@ -165,3 +165,3 @@ line: 1,

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('color');

@@ -177,4 +177,68 @@ actual = hexLength({

it('should not allow short hand hex values in variables when "style" is "long" (#28)', function () {
var source = '@color: #ABC;';
var actual;
var ast;
var expected = {
column: 9,
file: 'test.less',
line: 1,
linter: 'hexLength',
message: '#ABC should be written in the long-form format.'
};
var options = {
hexLength: {
enabled: true,
style: 'long'
}
};
ast = linter.parseAST(source);
ast = ast.first().first('color');
actual = hexLength({
config: options,
node: ast,
path: 'test.less'
});
assert.deepEqual(actual, expected);
});
it('should not allow longhand hex values in variables when "style" is "short" (#28)', function () {
var source = '@color: #AABBCC;';
var actual;
var ast;
var expected = {
column: 9,
file: 'test.less',
line: 1,
linter: 'hexLength',
message: '#AABBCC should be written in the short-form format.'
};
var options = {
hexLength: {
enabled: true,
style: 'short'
}
};
ast = linter.parseAST(source);
ast = ast.first().first('color');
actual = hexLength({
config: options,
node: ast,
path: 'test.less'
});
assert.deepEqual(actual, expected);
});
it('should not do anything when the value is something else than a hex color', function () {
var source = '.foo { color: red; }';
var source = 'color: red;';
var ast;

@@ -190,3 +254,3 @@

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('ident')

@@ -200,3 +264,3 @@ assert.strictEqual(null, hexLength({

it('should return null when disabled', function () {
var source = '.foo { color: #abc; }';
var source = 'color: #abc;';
var ast;

@@ -210,3 +274,3 @@ var options = {

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('color');

@@ -220,3 +284,3 @@ assert.equal(null, hexLength({

it('should return null when disabled via shorthand', function () {
var source = '.foo { color: #abc; }';
var source = 'color: #abc;';
var ast;

@@ -228,3 +292,3 @@ var options = {

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('color');

@@ -238,3 +302,3 @@ assert.equal(null, hexLength({

it('should throw on invalid "style" value', function () {
var source = '.foo { color: #aabbcc; }';
var source = 'color: #aabbcc;';
var ast;

@@ -250,3 +314,3 @@

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('color');

@@ -253,0 +317,0 @@ assert.throws(hexLength.bind(null, {

@@ -8,4 +8,4 @@ var assert = require('assert');

describe('#hexNotation()', function () {
it('should not allow uppercase hex values when "style" is "lowercase', function () {
var source = '.foo { color: #AABBCC; }';
it('should not allow uppercase hex values when "style" is "lowercase"', function () {
var source = 'color: #AABBCC;';
var actual;

@@ -15,3 +15,3 @@ var ast;

var expected = {
column: 15,
column: 8,
file: 'test.less',

@@ -31,3 +31,3 @@ line: 1,

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('color');

@@ -43,4 +43,4 @@ actual = hexNotation({

it('should allow lowercase hex values when "style" is "lowercase', function () {
var source = '.foo { color: #aabbcc; }';
it('should allow lowercase hex values when "style" is "lowercase"', function () {
var source = 'color: #aabbcc;';
var ast;

@@ -56,3 +56,3 @@

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('color');

@@ -65,4 +65,4 @@ assert.strictEqual(true, hexNotation({

it('should not allow lowercase hex values when "style" is "uppercase', function () {
var source = '.foo { color: #aabbcc; }';
it('should not allow lowercase hex values when "style" is "uppercase"', function () {
var source = 'color: #aabbcc;';
var actual;

@@ -72,3 +72,3 @@ var ast;

var expected = {
column: 15,
column: 8,
file: 'test.less',

@@ -88,3 +88,3 @@ line: 1,

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('color');

@@ -100,4 +100,4 @@ actual = hexNotation({

it('should allow uppercase hex values when "style" is "uppercase', function () {
var source = '.foo { color: #AABBCC; }';
it('should allow uppercase hex values when "style" is "uppercase"', function () {
var source = 'color: #AABBCC;';
var ast;

@@ -113,3 +113,3 @@

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('color');

@@ -123,7 +123,7 @@ assert.strictEqual(true, hexNotation({

it('should find hex values in background declarations', function () {
var source = '.foo { background: url(test.png) no-repeat #AABBCC; }';
var source = 'background: url(test.png) no-repeat #AABBCC;';
var ast;
var expected = {
column: 44,
column: 37,
file: 'test.less',

@@ -143,3 +143,3 @@ line: 1,

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('color');

@@ -155,4 +155,68 @@ actual = hexNotation({

it('should not allow uppercase hex values in variables when "style" is "lowercase" (#28)', function () {
var source = '@color: #AABBCC;';
var actual;
var ast;
var expected = {
column: 9,
file: 'test.less',
line: 1,
linter: 'hexNotation',
message: '#AABBCC should be written in lowercase.'
};
var options = {
hexNotation: {
enabled: true,
style: 'lowercase'
}
};
ast = linter.parseAST(source);
ast = ast.first().first('color');
actual = hexNotation({
config: options,
node: ast,
path: 'test.less'
});
assert.deepEqual(actual, expected);
});
it('should not allow lowercase hex values in variables when "style" is "uppercase" (#28)', function () {
var source = '@color: #aabbcc;';
var actual;
var ast;
var expected = {
column: 9,
file: 'test.less',
line: 1,
linter: 'hexNotation',
message: '#aabbcc should be written in uppercase.'
};
var options = {
hexNotation: {
enabled: true,
style: 'uppercase'
}
};
ast = linter.parseAST(source);
ast = ast.first().first('color');
actual = hexNotation({
config: options,
node: ast,
path: 'test.less'
});
assert.deepEqual(actual, expected);
});
it('should return null when disabled', function () {
var source = '.foo { color: #abc; }';
var source = 'color: #abc;';
var ast;

@@ -166,3 +230,3 @@ var options = {

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('color');

@@ -176,3 +240,3 @@ assert.equal(null, hexNotation({

it('should return null when disabled via shorthand', function () {
var source = '.foo { color: #abc; }';
var source = 'color: #abc;';
var ast;

@@ -184,3 +248,3 @@ var options = {

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('color');

@@ -194,3 +258,3 @@ assert.equal(null, hexNotation({

it('should throw on invalid "style" value', function () {
var source = '.foo { color: #aabbcc; }';
var source = 'color: #aabbcc;';
var ast;

@@ -206,3 +270,3 @@

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('color');

@@ -209,0 +273,0 @@ assert.throws(hexNotation.bind(null, {

@@ -9,3 +9,3 @@ var assert = require('assert');

it('should allow valid hex values', function () {
var source = '.foo { color: #AABBCC; }';
var source = 'color: #AABBCC;';
var ast;

@@ -20,3 +20,3 @@

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('color');

@@ -30,3 +30,3 @@ assert.strictEqual(true, hexValidation({

it('should not allow invalid hex values', function () {
var source = '.foo { color: #AABBC; }';
var source = 'color: #AABBC;';
var actual;

@@ -36,3 +36,3 @@ var ast;

var expected = {
column: 15,
column: 8,
file: 'test.less',

@@ -51,3 +51,3 @@ line: 1,

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('color');

@@ -64,7 +64,7 @@ actual = hexValidation({

it('should find invalid hex values in background declarations', function () {
var source = '.foo { background: url(test.png) no-repeat #AABBC; }';
var source = 'background: url(test.png) no-repeat #AABBC;';
var ast;
var expected = {
column: 44,
column: 37,
file: 'test.less',

@@ -84,3 +84,3 @@ line: 1,

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('color');

@@ -96,4 +96,35 @@ actual = hexValidation({

it('should not allow invalid hex values in variable declarations (#28)', function () {
var source = '@color: #AABBC;';
var actual;
var ast;
var expected = {
column: 9,
file: 'test.less',
line: 1,
linter: 'hexValidation',
message: 'Hexadecimal color "#AABBC" should be either three or six characters long.'
};
var options = {
hexValidation: {
enabled: true
}
};
ast = linter.parseAST(source);
ast = ast.first().first('color');
actual = hexValidation({
config: options,
node: ast,
path: 'test.less'
});
assert.deepEqual(actual, expected);
});
it('should not do anything when the value is something other than a hex color', function () {
var source = '.foo { color: red; }';
var source = 'color: red;';
var ast;

@@ -108,3 +139,3 @@

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('ident');

@@ -118,3 +149,3 @@ assert.strictEqual(null, hexValidation({

it('should return null when disabled', function () {
var source = '.foo { color: #AABBC; }';
var source = 'color: #AABBC;';
var ast;

@@ -128,3 +159,3 @@ var options = {

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('color');

@@ -138,3 +169,3 @@ assert.equal(null, hexValidation({

it('should return null when disabled via shorthand', function () {
var source = '.foo { color: #AABBC; }';
var source = 'color: #AABBC;';
var ast;

@@ -146,3 +177,3 @@ var options = {

ast = linter.parseAST(source);
ast = ast.first().first('block').first('declaration');
ast = ast.first('declaration').first('value').first('color');

@@ -149,0 +180,0 @@ assert.equal(null, hexValidation({

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc