Skip to content

Commit

Permalink
Enable loose mode for postcss-values-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilsson committed Feb 3, 2017
1 parent 316e579 commit 573417d
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 17 deletions.
5 changes: 4 additions & 1 deletion lib/linters/decimal_zero.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ module.exports = {
message: '%s should be written %s %s zero.',

lint: function decimalZeroLinter (config, node) {
const ast = parser(node.value).parse();
const ast = parser(node.value, {
loose: true
}).parse();

const results = [];

ast.walk((child) => {
Expand Down
5 changes: 4 additions & 1 deletion lib/linters/hex_length.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ module.exports = {
*/
node.value = node.value.replace(/;$/, '');

const ast = parser(node.value).parse();
const ast = parser(node.value, {
loose: true
}).parse();

const results = [];

ast.first.walk((child) => {
Expand Down
4 changes: 3 additions & 1 deletion lib/linters/hex_notation.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ module.exports = {
*/
node.value = node.value.replace(/;$/, '');

const ast = parser(node.value).parse();
const ast = parser(node.value, {
loose: true
}).parse();

if (config.style && !styles[config.style]) {
throw new Error(`Invalid setting value for hexNotation: ${ config.style }`);
Expand Down
5 changes: 4 additions & 1 deletion lib/linters/hex_validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ module.exports = {
*/
node.value = node.value.replace(/;$/, '');

const ast = parser(node.value).parse();
const ast = parser(node.value, {
loose: true
}).parse();

const results = [];

ast.first.walk((child) => {
Expand Down
4 changes: 3 additions & 1 deletion lib/linters/import_path.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ module.exports = {
*/
const importOptsRx = /(\s+)?\((\s+)?(reference|inline|less|css|once|multiple|optional)(\s+)?\)(\s+)?/gi;
const params = node.params.replace(importOptsRx, '');
const ast = parser(params).parse();
const ast = parser(params, {
loose: true
}).parse();

let value = ast.first.first;

Expand Down
5 changes: 4 additions & 1 deletion lib/linters/property_units.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ module.exports = {
config.invalid = Array.isArray(config.invalid) ? config.invalid : [];
config.properties = config.properties || {};

const ast = parser(node.value).parse();
const allowed = config.properties[property];
const ast = parser(node.value, {
loose: true
}).parse();

const results = [];

ast.first.walk((value) => {
Expand Down
10 changes: 7 additions & 3 deletions lib/linters/space_around_comma.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@ module.exports = {

lint: function spaceAroundCommaLinter (config, node) {
let column = node.source.start.column;
let ast;
let value;

if (node.params) {
// A bit hacky, we're abusing the values parser for mixins etc.
ast = parser(node.selector).parse();
value = node.selector;
} else if (node.type === 'decl') {
ast = parser(node.value).parse();
value = node.value;
column += node.prop.length + node.raws.between.length;
} else {
return;
}

const ast = parser(value, {
loose: true
}).parse();

const results = [];

ast.walk((child) => {
Expand Down
5 changes: 4 additions & 1 deletion lib/linters/space_around_operator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ module.exports = {
message: 'Operators should%s be %s by %s space.',

lint: function spaceAroundOperatorLinter (config, node) {
const ast = parser(node.value).parse();
const ast = parser(node.value, {
loose: true
}).parse();

const results = [];

ast.walk((child) => {
Expand Down
10 changes: 7 additions & 3 deletions lib/linters/space_between_parens.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@ module.exports = {

lint: function spaceBetweenParensLinter (config, node) {
let column = node.source.start.column;
let ast;
let value;

if (node.params) {
// A bit hacky, we're abusing the values parser for mixins etc.
ast = parser(node.selector).parse();
value = node.selector;
} else if (node.type === 'decl') {
ast = parser(node.value).parse();
value = node.value;
column += node.prop.length + node.raws.between.length;
} else {
return;
}

const ast = parser(value, {
loose: true
}).parse();

const results = [];

ast.walk((child) => {
Expand Down
4 changes: 3 additions & 1 deletion lib/linters/string_quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ module.exports = {
});
}
} else if (node.type === 'decl') {
const ast = valuesParser(node.value).parse();
const ast = valuesParser(node.value, {
loose: true
}).parse();

ast.first.walk((decl) => {
if (decl.type !== 'string') {
Expand Down
5 changes: 4 additions & 1 deletion lib/linters/url_format.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ module.exports = {
* Traverse all child value-nodes
* https://github.com/lesshint/lesshint/issues/225
*/
const ast = parser(decl.params || decl.value).parse();
const ast = parser(decl.params || decl.value, {
loose: true
}).parse();

const results = [];

ast.first.nodes.forEach((child) => {
Expand Down
4 changes: 3 additions & 1 deletion lib/linters/url_quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ module.exports = {
* Traverse all child value-nodes
* https://github.com/lesshint/lesshint/issues/225
*/
const ast = parser(node.params || node.value).parse();
const ast = parser(node.params || node.value, {
loose: true
}).parse();

ast.first.nodes.forEach((child) => {
if (child.type !== 'func' || child.value !== 'url') {
Expand Down
5 changes: 4 additions & 1 deletion lib/linters/zero_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ module.exports = {
return;
}

const ast = parser(node.value).parse();
const ast = parser(node.value, {
loose: true
}).parse();

const results = [];

ast.first.each((child) => {
Expand Down

0 comments on commit 573417d

Please sign in to comment.