Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:sasstools/sass-lint into greenke…
Browse files Browse the repository at this point in the history
…eper-eslint-2.7.0

# Conflicts:
#	package.json
  • Loading branch information
DanPurdy committed Apr 5, 2016
2 parents bceaa15 + bede866 commit ef22e7d
Show file tree
Hide file tree
Showing 50 changed files with 1,182 additions and 1,366 deletions.
14 changes: 6 additions & 8 deletions .eslintrc
Expand Up @@ -54,7 +54,7 @@ rules:
no-caller: 2
no-console: 0
no-delete-var: 2
no-empty-label: 2
no-labels: 2
no-eval: 2
no-extend-native: 2
no-extra-bind: 2
Expand All @@ -64,7 +64,6 @@ rules:
no-invalid-this: 2
no-iterator: 2
no-label-var: 2
no-labels: 2
no-lone-blocks: 2
no-loop-func: 2
no-mixed-spaces-and-tabs:
Expand Down Expand Up @@ -110,15 +109,16 @@ rules:
- 2
- before: false
after: true
space-after-keywords:
- 2
- always
keyword-spacing:
- 2
-
before: true
after: true
space-before-blocks: 2
space-before-function-paren:
- 2
- always
space-infix-ops: 2
space-return-throw-case: 2
space-unary-ops:
- 2
- words: true
Expand All @@ -144,11 +144,9 @@ rules:

# Previously on by default in node environment
no-catch-shadow: 0
no-console: 0
no-mixed-requires: 2
no-new-require: 2
no-path-concat: 2
no-process-exit: 2
handle-callback-err:
- 2
- err
8 changes: 7 additions & 1 deletion docs/rules/variable-for-property.md
@@ -1,6 +1,12 @@
# Variable For Property

Rule `variable-for-property` will enforce the use of variables for the values of specified properties. There are no properties by default.
Rule `variable-for-property` will enforce the use of variables for the values of specified properties.
There are no properties by default, except for reserved words listed below which are always whitelisted:
* inherit
* initial
* transparent
* none
* currentColor

## Options

Expand Down
1 change: 0 additions & 1 deletion index.js
Expand Up @@ -164,7 +164,6 @@ sassLint.lintFiles = function (files, options, configPath) {
}
else {
files = this.getConfig(options, configPath).files;

if (typeof files === 'string') {
files = glob.sync(files);
}
Expand Down
24 changes: 11 additions & 13 deletions lib/config.js
Expand Up @@ -14,29 +14,27 @@ var loadDefaults = function loadDefaults () {

var findFile = function findFile (configPath, filename) {
var HOME = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE,
dirname,
parentDirname;
dirname = null,
parentDirname = null;

configPath = configPath || path.join(process.cwd(), filename);

if (fs.existsSync(configPath)) {
if (configPath && fs.existsSync(configPath)) {
dirname = path.dirname(configPath);
parentDirname = path.dirname(dirname);
return fs.realpathSync(configPath);
}

dirname = path.dirname(configPath);
parentDirname = path.dirname(dirname);

if (dirname === HOME || dirname === parentDirname) {
if (dirname === null || dirname === HOME || dirname === parentDirname) {
return null;
}

configPath = path.join(parentDirname, filename);

return findFile(configPath, filename);
};

module.exports = function (options, configPath) {
var meta,
var meta = null,
metaPath,
configMerge = false,
configMergeExists = false,
Expand Down Expand Up @@ -70,10 +68,11 @@ module.exports = function (options, configPath) {

if (!configPath) {
metaPath = findFile(false, 'package.json');
meta = require(metaPath);

if (meta.sasslintConfig) {
if (metaPath) {
meta = require(metaPath);
}

if (meta && meta.sasslintConfig) {
configPath = path.resolve(path.dirname(metaPath), meta.sasslintConfig);
}
else {
Expand All @@ -90,7 +89,6 @@ module.exports = function (options, configPath) {
config.rules = config.rules ? config.rules : {};
}
}

// check to see if user config contains an options property and whether property has a property called merge-default-rules
configMergeExists = (config.options && typeof config.options['merge-default-rules'] !== 'undefined');

Expand Down
2 changes: 1 addition & 1 deletion lib/groot.js
Expand Up @@ -3,7 +3,7 @@
//////////////////////////////
'use strict';

var gonzales = require('gonzales-pe');
var gonzales = require('gonzales-pe-sl');

module.exports = function (text, syntax, filename) {
var tree;
Expand Down
145 changes: 11 additions & 134 deletions lib/helpers.js
Expand Up @@ -4,16 +4,7 @@ var util = require('util'),
fs = require('fs'),
path = require('path'),
yaml = require('js-yaml'),
merge = require('merge');

/**
* Easy access to the 'merge' library's cloning functionality
* @param {object} obj Object to clone
* @returns {object} Clone of obj
*/
var clone = function (obj) {
return merge(true, obj);
};
gonzales = require('gonzales-pe-sl');

var helpers = {};

Expand Down Expand Up @@ -240,112 +231,6 @@ helpers.stripLastSpace = function (selector) {

};

/**
* Scans through our selectors and keeps track of the order of selectors and delimiters
* @param {object} selector - the current selector tree from our AST
* @returns {array} mappedElements - an array / list representing the order of selectors and delimiters encountered
*/

helpers.mapDelims = function (val) {

if (val.type === 'simpleSelector') {
return 's';
}

if (val.type === 'delimiter') {
return 'd';
}

return false;
};

/**
* Constructs a syntax complete selector
* @param {object} node - the current node / part of our selector
* @returns {object} constructedSelector - The constructed selector
* @returns {string} constructedSelector.content - The selector string
* @returns {string} constructedSelector.type - The type of the selector
*/
helpers.constructSelector = function (node) {
var content = node.content,
type = '';

if (node.type === 'id') {
content = '#' + node.content;
type = 'id';
}

else if (node.type === 'class') {
content = '.' + node.content;
type = 'class';
}

else if (node.type === 'ident') {
content = node.content;
type = 'selector';
}

else if (node.type === 'attribute') {
var selector = '[';

node.forEach(function (attrib) {
var selectorPiece = helpers.constructSelector(attrib);

selector += selectorPiece.content;
});

content = selector + ']';
type = 'attribute';
}

else if (node.type === 'pseudoClass') {
content = ':' + node.content;
type = 'pseudoClass';
}

else if (node.type === 'pseudoElement') {
content = '::' + node.content;
type = 'pseudoElement';
}

else if (node.type === 'nth') {
content = '(' + node.content + ')';
type = 'nth';
}

else if (node.type === 'nthSelector') {
var nthSelector = ':';

node.forEach(function (attrib) {
var selectorPiece = helpers.constructSelector(attrib);

nthSelector += selectorPiece.content;
});

content = nthSelector;
type = 'nthSelector';
}

else if (node.type === 'space') {
content = ' ';
}

else if (node.type === 'parentSelector') {
content = node.content;
type = 'parentSelector';
}

else if (node.type === 'combinator') {
content = node.content;
type = 'combinator';
}

return {
content: content,
type: type
};
};

/**
* Checks the current selector value against the previous selector value and assesses whether they are
* a) currently an enforced selector type for nesting (user specified - all true by default)
Expand Down Expand Up @@ -395,7 +280,6 @@ helpers.attemptTraversal = function (node, traversalPath) {
currentNodeList.forEach(processChildNode);
currentNodeList = nextNodeList;
}

return currentNodeList;
};

Expand All @@ -407,7 +291,7 @@ helpers.attemptTraversal = function (node, traversalPath) {
* (without '.', '#', etc) resulting from suffix extensions
*/
helpers.collectSuffixExtensions = function (ruleset, selectorType) {
var parentSelectors = helpers.attemptTraversal(ruleset, ['selector', 'simpleSelector', selectorType, 'ident']),
var parentSelectors = helpers.attemptTraversal(ruleset, ['selector', selectorType, 'ident']),
childSuffixes = helpers.attemptTraversal(ruleset, ['block', 'ruleset']),
selectorList = [];

Expand All @@ -419,25 +303,18 @@ helpers.collectSuffixExtensions = function (ruleset, selectorType) {
// extended, so lots of looping is required.
var processChildSuffix = function (child, parents) {
var currentParents = [],
selectors = helpers.attemptTraversal(child, ['selector', 'simpleSelector']),
selectors = helpers.attemptTraversal(child, ['selector', 'parentSelectorExtension', 'ident']),
nestedChildSuffixes = helpers.attemptTraversal(child, ['block', 'ruleset']);

selectors.forEach(function (childSuffixNode) {
var extendedNode;

if (childSuffixNode.length >= 2 &&
childSuffixNode.contains('parentSelector') &&
childSuffixNode.contains('ident')) {

// append suffix extension to all parent selectors
parents.forEach(function (parent) {
// clone so we don't modify the actual AST
extendedNode = clone(childSuffixNode.first('ident'));
extendedNode.content = parent.content + extendedNode.content;

currentParents.push(extendedNode);
});
}
// append suffix extension to all parent selectors
parents.forEach(function (parent) {
// clone so we don't modify the actual AST
var clonedChildSuffixNode = gonzales.createNode(childSuffixNode);
clonedChildSuffixNode.content = parent.content + clonedChildSuffixNode.content;

currentParents.push(clonedChildSuffixNode);
});
});

selectorList = selectorList.concat(currentParents);
Expand Down

0 comments on commit ef22e7d

Please sign in to comment.