mirror of
https://github.com/less/less.js.git
synced 2026-05-01 03:00:22 -04:00
more whitespace rules
This commit is contained in:
12
.jscsrc
12
.jscsrc
@@ -1,6 +1,16 @@
|
||||
{
|
||||
"disallowImplicitTypeConversion": ["numeric", "boolean", "binary", "string"],
|
||||
"disallowKeywords": ["with"],
|
||||
"disallowMixedSpacesAndTabs": true,
|
||||
"disallowMultipleLineBreaks": true,
|
||||
"disallowTrailingWhitespace": true
|
||||
"disallowOperatorBeforeLineBreak": ["."],
|
||||
"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~"],
|
||||
"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"],
|
||||
"disallowSpacesInCallExpression": true,
|
||||
"disallowSpacesInNamedFunctionExpression": {
|
||||
"beforeOpeningRoundBrace": true
|
||||
},
|
||||
"disallowTrailingComma": true,
|
||||
"disallowTrailingWhitespace": true,
|
||||
"maximumLineLength": 160
|
||||
}
|
||||
@@ -243,7 +243,8 @@ function printUsage() {
|
||||
if (plugin) {
|
||||
plugins.push(plugin);
|
||||
} else {
|
||||
console.log("Unable to load plugin " + name + " please make sure that it is installed under or at the same level as less");
|
||||
console.log("Unable to load plugin " + name +
|
||||
" please make sure that it is installed under or at the same level as less");
|
||||
console.log();
|
||||
printUsage();
|
||||
currentErrorcode = 1;
|
||||
@@ -254,7 +255,9 @@ function printUsage() {
|
||||
if (plugin) {
|
||||
plugins.push(plugin);
|
||||
} else {
|
||||
console.log("Unable to interpret argument " + arg + " - if it is a plugin (less-plugin-" + arg + "), make sure that it is installed under or at the same level as less");
|
||||
console.log("Unable to interpret argument " + arg +
|
||||
" - if it is a plugin (less-plugin-" + arg + "), make sure that it is installed under or at" +
|
||||
" the same level as less");
|
||||
console.log();
|
||||
printUsage();
|
||||
currentErrorcode = 1;
|
||||
|
||||
@@ -73,7 +73,8 @@ module.exports = function(environment) {
|
||||
if (uri.length >= DATA_URI_MAX) {
|
||||
|
||||
if (this.context.ieCompat !== false) {
|
||||
logger.warn("Skipped data-uri embedding of " + filePath + " because its size (" + uri.length + " characters) exceeds IE8-safe " + DATA_URI_MAX + " characters!");
|
||||
logger.warn("Skipped data-uri embedding of " + filePath + " because its size (" + uri.length +
|
||||
" characters) exceeds IE8-safe " + DATA_URI_MAX + " characters!");
|
||||
|
||||
return fallback(this, filePathNode || mimetypeNode);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@ functionRegistry.addMultiple({
|
||||
return new Anonymous(str instanceof JavaScript ? str.evaluated : str.value);
|
||||
},
|
||||
escape: function (str) {
|
||||
return new Anonymous(encodeURI(str.value).replace(/=/g, "%3D").replace(/:/g, "%3A").replace(/#/g, "%23").replace(/;/g, "%3B").replace(/\(/g, "%28").replace(/\)/g, "%29"));
|
||||
return new Anonymous(
|
||||
encodeURI(str.value).replace(/=/g, "%3D").replace(/:/g, "%3A").replace(/#/g, "%23").replace(/;/g, "%3B")
|
||||
.replace(/\(/g, "%28").replace(/\)/g, "%29"));
|
||||
},
|
||||
replace: function (string, pattern, replacement, flags) {
|
||||
var result = string.value;
|
||||
|
||||
@@ -9,7 +9,9 @@ module.exports = function(environment) {
|
||||
functionRegistry.add("svg-gradient", function(direction) {
|
||||
|
||||
function throwArgumentDescriptor() {
|
||||
throw { type: "Argument", message: "svg-gradient expects direction, start_color [start_position], [color position,]..., end_color [end_position]" };
|
||||
throw { type: "Argument",
|
||||
message: "svg-gradient expects direction, start_color [start_position], [color position,]...," +
|
||||
" end_color [end_position]" };
|
||||
}
|
||||
|
||||
if (arguments.length < 3) {
|
||||
@@ -44,7 +46,8 @@ module.exports = function(environment) {
|
||||
rectangleDimension = 'x="-50" y="-50" width="101" height="101"';
|
||||
break;
|
||||
default:
|
||||
throw { type: "Argument", message: "svg-gradient direction must be 'to bottom', 'to right', 'to bottom right', 'to top right' or 'ellipse at center'" };
|
||||
throw { type: "Argument", message: "svg-gradient direction must be 'to bottom', 'to right'," +
|
||||
" 'to bottom right', 'to top right' or 'ellipse at center'" };
|
||||
}
|
||||
returner = '<?xml version="1.0" ?>' +
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100%" height="100%" viewBox="0 0 1 1" preserveAspectRatio="none">' +
|
||||
|
||||
@@ -52,7 +52,9 @@ functionRegistry.addMultiple({
|
||||
isunit: isunit,
|
||||
unit: function (val, unit) {
|
||||
if(!(val instanceof Dimension)) {
|
||||
throw { type: "Argument", message: "the first argument to unit must be a number" + (val instanceof Operation ? ". Have you forgotten parenthesis?" : "") };
|
||||
throw { type: "Argument",
|
||||
message: "the first argument to unit must be a number" +
|
||||
(val instanceof Operation ? ". Have you forgotten parenthesis?" : "") };
|
||||
}
|
||||
if (unit) {
|
||||
if (unit instanceof Keyword) {
|
||||
|
||||
@@ -82,7 +82,10 @@ module.exports = function(environment) {
|
||||
// then rootpath should become 'less/../'
|
||||
newFileInfo.currentDirectory = fileManager.getPath(resolvedFilename);
|
||||
if(newFileInfo.relativeUrls) {
|
||||
newFileInfo.rootpath = fileManager.join((importManager.context.rootpath || ""), fileManager.pathDiff(newFileInfo.currentDirectory, newFileInfo.entryPath));
|
||||
newFileInfo.rootpath = fileManager.join(
|
||||
(importManager.context.rootpath || ""),
|
||||
fileManager.pathDiff(newFileInfo.currentDirectory, newFileInfo.entryPath));
|
||||
|
||||
if (!fileManager.isPathAbsolute(newFileInfo.rootpath) && fileManager.alwaysMakePathsAbsolute()) {
|
||||
newFileInfo.rootpath = fileManager.join(newFileInfo.entryPath, newFileInfo.rootpath);
|
||||
}
|
||||
|
||||
@@ -454,7 +454,9 @@ var Parser = function Parser(context, imports, fileInfo) {
|
||||
var rgb;
|
||||
|
||||
if (parserInput.currentChar() === '#' && (rgb = parserInput.$re(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/))) {
|
||||
var colorCandidateString = rgb.input.match(/^#([\w]+).*/); // strip colons, brackets, whitespaces and other characters that should not definitely be part of color string
|
||||
// strip colons, brackets, whitespaces and other characters that should not
|
||||
// definitely be part of color string
|
||||
var colorCandidateString = rgb.input.match(/^#([\w]+).*/);
|
||||
colorCandidateString = colorCandidateString[1];
|
||||
if (!colorCandidateString.match(/^[A-Fa-f0-9]+$/)) { // verify if candidate consists only of allowed HEX characters
|
||||
error("Invalid HEX color code");
|
||||
@@ -861,9 +863,10 @@ var Parser = function Parser(context, imports, fileInfo) {
|
||||
|
||||
c = this.combinator();
|
||||
|
||||
e = parserInput.$re(/^(?:\d+\.\d+|\d+)%/) || parserInput.$re(/^(?:[.#]?|:*)(?:[\w-]|[^\x00-\x9f]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+/) ||
|
||||
parserInput.$char('*') || parserInput.$char('&') || this.attribute() || parserInput.$re(/^\([^()@]+\)/) || parserInput.$re(/^[\.#:](?=@)/) ||
|
||||
this.entities.variableCurly();
|
||||
e = parserInput.$re(/^(?:\d+\.\d+|\d+)%/) ||
|
||||
parserInput.$re(/^(?:[.#]?|:*)(?:[\w-]|[^\x00-\x9f]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+/) ||
|
||||
parserInput.$char('*') || parserInput.$char('&') || this.attribute() ||
|
||||
parserInput.$re(/^\([^()@]+\)/) || parserInput.$re(/^[\.#:](?=@)/) || this.entities.variableCurly();
|
||||
|
||||
if (! e) {
|
||||
parserInput.save();
|
||||
|
||||
@@ -26,7 +26,7 @@ Condition.prototype.eval = function (context) {
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
}) (this.op, this.lvalue.eval(context), this.rvalue.eval(context));
|
||||
})(this.op, this.lvalue.eval(context), this.rvalue.eval(context));
|
||||
|
||||
return this.negate ? !result : result;
|
||||
};
|
||||
|
||||
@@ -132,9 +132,10 @@ Definition.prototype.evalCall = function (context, args, important) {
|
||||
Definition.prototype.matchCondition = function (args, context) {
|
||||
if (this.condition && !this.condition.eval(
|
||||
new contexts.Eval(context,
|
||||
[this.evalParams(context, new contexts.Eval(context, this.frames ? this.frames.concat(context.frames) : context.frames), args, [])] // the parameter variables
|
||||
.concat(this.frames) // the parent namespace/mixin frames
|
||||
.concat(context.frames)))) { // the current environment frames
|
||||
[this.evalParams(context, /* the parameter variables*/
|
||||
new contexts.Eval(context, this.frames ? this.frames.concat(context.frames) : context.frames), args, [])]
|
||||
.concat(this.frames) // the parent namespace/mixin frames
|
||||
.concat(context.frames)))) { // the current environment frames
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -122,15 +122,16 @@ ProcessExtendsVisitor.prototype = {
|
||||
},
|
||||
doExtendChaining: function (extendsList, extendsListTarget, iterationCount) {
|
||||
//
|
||||
// chaining is different from normal extension.. if we extend an extend then we are not just copying, altering and pasting
|
||||
// the selector we would do normally, but we are also adding an extend with the same target selector
|
||||
// chaining is different from normal extension.. if we extend an extend then we are not just copying, altering
|
||||
// and pasting the selector we would do normally, but we are also adding an extend with the same target selector
|
||||
// this means this new extend can then go and alter other extends
|
||||
//
|
||||
// this method deals with all the chaining work - without it, extend is flat and doesn't work on other extend selectors
|
||||
// this is also the most expensive.. and a match on one selector can cause an extension of a selector we had already processed if
|
||||
// we look at each selector at a time, as is done in visitRuleset
|
||||
// this is also the most expensive.. and a match on one selector can cause an extension of a selector we had already
|
||||
// processed if we look at each selector at a time, as is done in visitRuleset
|
||||
|
||||
var extendIndex, targetExtendIndex, matches, extendsToAdd = [], newSelector, extendVisitor = this, selectorPath, extend, targetExtend, newExtend;
|
||||
var extendIndex, targetExtendIndex, matches, extendsToAdd = [], newSelector, extendVisitor = this, selectorPath,
|
||||
extend, targetExtend, newExtend;
|
||||
|
||||
iterationCount = iterationCount || 0;
|
||||
|
||||
@@ -202,10 +203,12 @@ ProcessExtendsVisitor.prototype = {
|
||||
selectorTwo = extendsToAdd[0].selector.toCSS();
|
||||
}
|
||||
catch(e) {}
|
||||
throw {message: "extend circular reference detected. One of the circular extends is currently:"+selectorOne+":extend(" + selectorTwo+")"};
|
||||
throw { message: "extend circular reference detected. One of the circular extends is currently:" +
|
||||
selectorOne + ":extend(" + selectorTwo + ")"};
|
||||
}
|
||||
|
||||
// now process the new extends on the existing rules so that we can handle a extending b extending c ectending d extending e...
|
||||
// now process the new extends on the existing rules so that we can handle a extending b extending c extending
|
||||
// d extending e...
|
||||
return extendsToAdd.concat(extendVisitor.doExtendChaining(extendsToAdd, extendsListTarget, iterationCount+1));
|
||||
} else {
|
||||
return extendsToAdd;
|
||||
@@ -224,7 +227,8 @@ ProcessExtendsVisitor.prototype = {
|
||||
if (rulesetNode.root) {
|
||||
return;
|
||||
}
|
||||
var matches, pathIndex, extendIndex, allExtends = this.allExtendsStack[this.allExtendsStack.length-1], selectorsToAdd = [], extendVisitor = this, selectorPath;
|
||||
var matches, pathIndex, extendIndex, allExtends = this.allExtendsStack[this.allExtendsStack.length-1],
|
||||
selectorsToAdd = [], extendVisitor = this, selectorPath;
|
||||
|
||||
// look at each selector path in the ruleset, find any extend matches and then copy, find and replace
|
||||
|
||||
@@ -271,15 +275,16 @@ ProcessExtendsVisitor.prototype = {
|
||||
|
||||
// if we allow elements before our match we can add a potential match every time. otherwise only at the first element.
|
||||
if (extend.allowBefore || (haystackSelectorIndex === 0 && hackstackElementIndex === 0)) {
|
||||
potentialMatches.push({pathIndex: haystackSelectorIndex, index: hackstackElementIndex, matched: 0, initialCombinator: haystackElement.combinator});
|
||||
potentialMatches.push({pathIndex: haystackSelectorIndex, index: hackstackElementIndex, matched: 0,
|
||||
initialCombinator: haystackElement.combinator});
|
||||
}
|
||||
|
||||
for(i = 0; i < potentialMatches.length; i++) {
|
||||
potentialMatch = potentialMatches[i];
|
||||
|
||||
// selectors add " " onto the first element. When we use & it joins the selectors together, but if we don't
|
||||
// then each selector in haystackSelectorPath has a space before it added in the toCSS phase. so we need to work out
|
||||
// what the resulting combinator will be
|
||||
// then each selector in haystackSelectorPath has a space before it added in the toCSS phase. so we need to
|
||||
// work out what the resulting combinator will be
|
||||
targetCombinator = haystackElement.combinator.value;
|
||||
if (targetCombinator === '' && hackstackElementIndex === 0) {
|
||||
targetCombinator = ' ';
|
||||
@@ -297,7 +302,8 @@ ProcessExtendsVisitor.prototype = {
|
||||
if (potentialMatch) {
|
||||
potentialMatch.finished = potentialMatch.matched === needleElements.length;
|
||||
if (potentialMatch.finished &&
|
||||
(!extend.allowAfter && (hackstackElementIndex+1 < hackstackSelector.elements.length || haystackSelectorIndex+1 < haystackSelectorPath.length))) {
|
||||
(!extend.allowAfter &&
|
||||
(hackstackElementIndex+1 < hackstackSelector.elements.length || haystackSelectorIndex+1 < haystackSelectorPath.length))) {
|
||||
potentialMatch = null;
|
||||
}
|
||||
}
|
||||
@@ -381,7 +387,8 @@ ProcessExtendsVisitor.prototype = {
|
||||
);
|
||||
|
||||
if (match.pathIndex > currentSelectorPathIndex && currentSelectorPathElementIndex > 0) {
|
||||
path[path.length - 1].elements = path[path.length - 1].elements.concat(selectorPath[currentSelectorPathIndex].elements.slice(currentSelectorPathElementIndex));
|
||||
path[path.length - 1].elements = path[path.length - 1]
|
||||
.elements.concat(selectorPath[currentSelectorPathIndex].elements.slice(currentSelectorPathElementIndex));
|
||||
currentSelectorPathElementIndex = 0;
|
||||
currentSelectorPathIndex++;
|
||||
}
|
||||
@@ -410,7 +417,8 @@ ProcessExtendsVisitor.prototype = {
|
||||
}
|
||||
|
||||
if (currentSelectorPathIndex < selectorPath.length && currentSelectorPathElementIndex > 0) {
|
||||
path[path.length - 1].elements = path[path.length - 1].elements.concat(selectorPath[currentSelectorPathIndex].elements.slice(currentSelectorPathElementIndex));
|
||||
path[path.length - 1].elements = path[path.length - 1]
|
||||
.elements.concat(selectorPath[currentSelectorPathIndex].elements.slice(currentSelectorPathElementIndex));
|
||||
currentSelectorPathIndex++;
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,8 @@ ImportVisitor.prototype = {
|
||||
var onImported = this.onImported.bind(this, evaldImportNode, context),
|
||||
sequencedOnImported = this._sequencer.addImport(onImported);
|
||||
|
||||
this._importer.push(evaldImportNode.getPath(), tryAppendLessExtension, evaldImportNode.currentFileInfo, evaldImportNode.options, sequencedOnImported);
|
||||
this._importer.push(evaldImportNode.getPath(), tryAppendLessExtension, evaldImportNode.currentFileInfo,
|
||||
evaldImportNode.options, sequencedOnImported);
|
||||
} else {
|
||||
this.importCount--;
|
||||
if (this.isFinished) {
|
||||
|
||||
Reference in New Issue
Block a user