Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
DanPurdy authored Aug 26, 2017
2 parents c2b9aba + aefde6e commit 139fde6
Show file tree
Hide file tree
Showing 26 changed files with 249 additions and 190 deletions.
7 changes: 2 additions & 5 deletions lib/rules/no-mergeable-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ var mergeableNodes = ['atrule', 'include', 'ruleset'],
curLevel = 0,
curSelector = [],
parentSelector = [],
selectorList = [],
syntax = '';
selectorList = [];


/**
Expand Down Expand Up @@ -89,7 +88,6 @@ var checkAtRule = function (atRule) {

/**
* Checks an atRule to see if if it's part of our mergeable at rule list.
* It also checks for Sass syntax as gonzales currently has issues with the syntax
*
* @param {object} node - The current node / atRule part of our selector
* @returns {boolean} Whether this atRule should be merged or not
Expand All @@ -99,7 +97,7 @@ var isMergeableAtRule = function (node) {
node.forEach(function (item) {
// TODO Check back when Gonzales updates to fix this
// Gonzales has issues with nest levels in media queries :(
if (item.is('atkeyword') && validAtRules.indexOf(item.first('ident').content) !== -1 && syntax !== 'sass') {
if (item.is('atkeyword') && validAtRules.indexOf(item.first('ident').content) !== -1) {
isMergeable = true;
}
});
Expand Down Expand Up @@ -181,7 +179,6 @@ module.exports = {
curSelector = [];
parentSelector = [];
selectorList = [];
syntax = ast.syntax;
ast.traverseByType('stylesheet', function (styleSheet) {
traverseBlock(styleSheet, traverseNode);
});
Expand Down
136 changes: 118 additions & 18 deletions lib/rules/no-misspelled-properties.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
'use strict';

var helpers = require('../helpers'),
yaml = require('js-yaml'),
fs = require('fs'),
path = require('path');

var properties = yaml.safeLoad(fs.readFileSync(path.join(__dirname, '../../data', 'properties.yml'), 'utf8')).split(' ');
var helpers = require('../helpers');
var properties = require('known-css-properties').all;

/**
* Combine the valid property array and the array of extras into a new array
Expand All @@ -18,28 +14,133 @@ var getCombinedList = function (props, extras) {
return props.concat(extras);
};

/**
* Combines the base property name with the current property name to correct a full property name
*
* @param {String} baseName - The base property name
* @param {String} name - The property name to append to our base property name
* @returns {String} The constructed property name
*/
var generateName = function (baseName, name) {
return baseName + '-' + name;
};

/**
* Recursive function to build up an array of property names when encountering multiline properties
*
* @param {Object} valBlock - The current block node from within our value
* @param {Object} currentProperty - The current base property name i.e. border-
* @param {Number} propsCounted - The number of properties encountered in our multiline so far
* @returns {Array} Array of objects containing our property and line/col info etc
*/
var buildPartialProperty = function (valBlock, currentProperty, propsCounted) {
var propList = [];
var propsEncountered = propsCounted;
if (valBlock.contains('declaration')) {
valBlock.forEach('declaration', function (node) {
var prop = node.first('property');
var value = node.first('value');
propsEncountered++;

if (prop.first().is('ident')) {
if (value.contains('block')) {
propList = propList.concat(
buildPartialProperty(value.first('block'),
{
name: generateName(currentProperty.name, prop.first('ident').content)
},
propsEncountered
)
);
}
else {
propList.push({
name: generateName(currentProperty.name, prop.first('ident').content),
line: prop.first().start.line,
col: prop.first().start.column,
propsEncountered: propsEncountered
});
}
}
});
}
return propList;
};

module.exports = {
'name': 'no-misspelled-properties',
'defaults': {
'extra-properties': []
},
'detect': function (ast, parser) {
var result = [];
var toSkip = 0;
var propertyList = getCombinedList(properties, parser.options['extra-properties']);

ast.traverseByType('property', function (node) {
if (node.first().is('ident')) {
var curProperty = node.first().content,
propertyList = getCombinedList(properties, parser.options['extra-properties']);
ast.traverseByType('declaration', function (node) {
var prop = node.first('property');
var containsInterp = prop.contains('interpolation');
// If we've already checked declarations in a multiline we can skip those decs here
if (toSkip) {
toSkip--;
return !toSkip;
}
// make sure our first node within our property is an ident
if (!prop.first() || !prop.first().is('ident')) {
return false;
}

if (curProperty.charAt(0) === '-') {
curProperty = helpers.stripPrefix(curProperty);
}
var curProperty = prop.first() && prop.first().is('ident') && prop.first('ident').content;
var value = node.first('value');
var fullProperties = [];

if (helpers.isPartialStringMatch(curProperty, propertyList)) {
return false;
if (value.contains('block')) {
// encountered a multiline property, we should build the property list here
fullProperties = buildPartialProperty(
value.first('block'),
{
name: curProperty,
line: prop.first('ident').start.line,
col: prop.first('ident').start.column
},
0
);
}
// If we have multiline properties
if (fullProperties.length) {
fullProperties.forEach(function (constrProp) {
// Add the number of property declarations we've already checked here so we can skip them
toSkip += constrProp.propsEncountered;
// Check if the property exists in our list
if (propertyList.indexOf(constrProp.name) === -1) {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'line': constrProp.line,
'column': constrProp.col,
'message': 'Property `' + constrProp.name + '` appears to be spelled incorrectly',
'severity': parser.severity
});
}
});
}
else if (curProperty && curProperty.length) {
/*
* If our property name contains interpolation we need to make a best guess by using a
* partial string match as we can't be 100% on the context
*/
if (containsInterp) {
if (!helpers.isPartialStringMatch(curProperty, propertyList)) {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'line': node.start.line,
'column': node.start.column,
'message': 'Property `' + curProperty + '` appears to be spelled incorrectly',
'severity': parser.severity
});
}
}

if (curProperty.length > 0) {
// Otherwise it's just a normal string property name, lets check it here
else if (propertyList.indexOf(curProperty) === -1) {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'line': node.start.line,
Expand All @@ -49,7 +150,6 @@ module.exports = {
});
}
}

return false;
});

Expand Down
18 changes: 7 additions & 11 deletions lib/rules/no-universal-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@ module.exports = {
'detect': function (ast, parser) {
var result = [];

ast.traverseByType('typeSelector', function (typeSelector) {
typeSelector.traverse(function (item) {
if (item.is('ident') && item.content === '*') {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'line': item.start.line,
'column': item.start.column,
'message': '* (universal) selectors are not allowed',
'severity': parser.severity
});
}
ast.traverseByType('universalSelector', function (node) {
result = helpers.addUnique(result, {
'ruleId': parser.rule.name,
'line': node.start.line,
'column': node.start.column,
'message': '* (universal) selectors are not allowed',
'severity': parser.severity
});
});

Expand Down
1 change: 1 addition & 0 deletions lib/rules/zero-unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var helpers = require('../helpers');

var units = [
'%',
'em',
'ex',
'ch',
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
"fs-extra": "^3.0.1",
"glob": "^7.0.0",
"globule": "^1.0.0",
"gonzales-pe": "3.4.7",
"gonzales-pe": "^4.1.1",
"js-yaml": "^3.5.4",
"known-css-properties": "^0.3.0",
"lodash.capitalize": "^4.1.0",
"lodash.kebabcase": "^4.0.0",
"merge": "^1.2.0",
Expand Down
8 changes: 4 additions & 4 deletions tests/rules/attribute-quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('attribute-quotes - scss', function () {
lint.test(file, {
'attribute-quotes': 1
}, function (data) {
lint.assert.equal(5, data.warningCount);
lint.assert.equal(6, data.warningCount);
done();
});
});
Expand All @@ -26,7 +26,7 @@ describe('attribute-quotes - scss', function () {
}
]
}, function (data) {
lint.assert.equal(7, data.warningCount);
lint.assert.equal(8, data.warningCount);
done();
});
});
Expand All @@ -42,7 +42,7 @@ describe('attribute-quotes - sass', function () {
lint.test(file, {
'attribute-quotes': 1
}, function (data) {
lint.assert.equal(5, data.warningCount);
lint.assert.equal(6, data.warningCount);
done();
});
});
Expand All @@ -56,7 +56,7 @@ describe('attribute-quotes - sass', function () {
}
]
}, function (data) {
lint.assert.equal(7, data.warningCount);
lint.assert.equal(8, data.warningCount);
done();
});
});
Expand Down
3 changes: 1 addition & 2 deletions tests/rules/force-pseudo-nesting.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ describe('force pseudo nesting - sass', function () {
lint.test(file, {
'force-pseudo-nesting': 1
}, function (data) {
// Should be 6 once the gonzales parse error is fixed see https://github.com/sasstools/sass-lint/issues/271
lint.assert.equal(5, data.warningCount);
lint.assert.equal(6, data.warningCount);
done();
});
});
Expand Down
4 changes: 2 additions & 2 deletions tests/rules/no-attribute-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('no attribute selectors - scss', function () {
lint.test(file, {
'no-attribute-selectors': 1
}, function (data) {
lint.assert.equal(18, data.warningCount);
lint.assert.equal(21, data.warningCount);
done();
});
});
Expand All @@ -28,7 +28,7 @@ describe('no attribute selectors - sass', function () {
lint.test(file, {
'no-attribute-selectors': 1
}, function (data) {
lint.assert.equal(18, data.warningCount);
lint.assert.equal(21, data.warningCount);
done();
});
});
Expand Down
6 changes: 2 additions & 4 deletions tests/rules/no-mergeable-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,18 @@ describe('no mergeable selectors - scss', function () {

});

// 1 less warning than scss syntax as we dont attempt to merge media queries
describe('no mergeable selectors - sass', function () {
var file = lint.file('no-mergeable-selectors.sass');

it('[default]', function (done) {
lint.test(file, {
'no-mergeable-selectors': 1
}, function (data) {
lint.assert.equal(21, data.warningCount);
lint.assert.equal(22, data.warningCount);
done();
});
});

// 1 less warning than scss syntax as we dont attempt to merge media queries
it('[whitelist: div p]', function (done) {
lint.test(file, {
'no-mergeable-selectors': [
Expand All @@ -57,7 +55,7 @@ describe('no mergeable selectors - sass', function () {
}
]
}, function (data) {
lint.assert.equal(20, data.warningCount);
lint.assert.equal(21, data.warningCount);
done();
});
});
Expand Down
12 changes: 6 additions & 6 deletions tests/rules/no-misspelled-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('no misspelled properties - scss', function () {
lint.test(file, {
'no-misspelled-properties': 1
}, function (data) {
lint.assert.equal(7, data.warningCount);
lint.assert.equal(9, data.warningCount);
done();
});
});
Expand All @@ -28,7 +28,7 @@ describe('no misspelled properties - scss', function () {
}
]
}, function (data) {
lint.assert.equal(5, data.warningCount);
lint.assert.equal(8, data.warningCount);
done();
});
});
Expand All @@ -45,7 +45,7 @@ describe('no misspelled properties - scss', function () {
}
]
}, function (data) {
lint.assert.equal(4, data.warningCount);
lint.assert.equal(7, data.warningCount);
done();
});
});
Expand All @@ -61,7 +61,7 @@ describe('no misspelled properties - sass', function () {
lint.test(file, {
'no-misspelled-properties': 1
}, function (data) {
lint.assert.equal(7, data.warningCount);
lint.assert.equal(9, data.warningCount);
done();
});
});
Expand All @@ -77,7 +77,7 @@ describe('no misspelled properties - sass', function () {
}
]
}, function (data) {
lint.assert.equal(5, data.warningCount);
lint.assert.equal(8, data.warningCount);
done();
});
});
Expand All @@ -94,7 +94,7 @@ describe('no misspelled properties - sass', function () {
}
]
}, function (data) {
lint.assert.equal(4, data.warningCount);
lint.assert.equal(7, data.warningCount);
done();
});
});
Expand Down
Loading

0 comments on commit 139fde6

Please sign in to comment.