Skip to content

Commit

Permalink
🎨 tidy up refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
DanPurdy committed Aug 26, 2017
1 parent 789440e commit 8a7f07e
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions lib/rules/no-misspelled-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

var helpers = require('../helpers');
var properties = require('known-css-properties').all;
var PROP_DIVIDER = '-';

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

/**
* Combine the valid property array and the array of extras into a new array
*
* @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
*
Expand All @@ -37,15 +47,15 @@ var buildPartialProperty = function (valBlock, currentProperty, propsCounted) {
propList = propList.concat(
buildPartialProperty(value.first('block'),
{
name: currentProperty.name + PROP_DIVIDER + prop.first('ident').content
name: generateName(currentProperty.name, prop.first('ident').content)
},
propsEncountered
)
);
}
else {
propList.push({
name: currentProperty.name + PROP_DIVIDER + prop.first('ident').content,
name: generateName(currentProperty.name, prop.first('ident').content),
line: prop.first().start.line,
col: prop.first().start.column,
propsEncountered: propsEncountered
Expand Down Expand Up @@ -99,7 +109,7 @@ module.exports = {
// If we have multiline properties
if (fullProperties.length) {
fullProperties.forEach(function (constrProp) {
// Add the number of propertiy declarations we've already checked here so we can skip them
// 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) {
Expand All @@ -113,25 +123,13 @@ module.exports = {
}
});
}
else {
if (curProperty && curProperty.length > 0) {
/*
* 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
});
}
}
// Otherwise it's just a normal string property name, lets check it here
else if (propertyList.indexOf(curProperty) === -1) {
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,
Expand All @@ -141,6 +139,16 @@ module.exports = {
});
}
}
// 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,
'column': node.start.column,
'message': 'Property `' + curProperty + '` appears to be spelled incorrectly',
'severity': parser.severity
});
}
}
return false;
});
Expand Down

0 comments on commit 8a7f07e

Please sign in to comment.