[Pkg-javascript-commits] [less.js] 05/14: more whitespace rules

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:29:16 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag v2.3.1
in repository less.js.

commit 08a7f9ebeb918b57aaaee6cea2a78050c489225e
Author: Luke Page <luke.a.page at gmail.com>
Date:   Tue Jan 27 21:38:13 2015 +0000

    more whitespace rules
---
 .jscsrc                             | 12 +++++++++++-
 bin/lessc                           |  7 +++++--
 lib/less/functions/data-uri.js      |  3 ++-
 lib/less/functions/string.js        |  4 +++-
 lib/less/functions/svg.js           |  7 +++++--
 lib/less/functions/types.js         |  4 +++-
 lib/less/import-manager.js          |  5 ++++-
 lib/less/parser/parser.js           | 11 +++++++----
 lib/less/tree/condition.js          |  2 +-
 lib/less/tree/mixin-definition.js   |  7 ++++---
 lib/less/visitors/extend-visitor.js | 36 ++++++++++++++++++++++--------------
 lib/less/visitors/import-visitor.js |  3 ++-
 12 files changed, 69 insertions(+), 32 deletions(-)

diff --git a/.jscsrc b/.jscsrc
index c192399..99b33ae 100644
--- a/.jscsrc
+++ b/.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
 }
\ No newline at end of file
diff --git a/bin/lessc b/bin/lessc
index 46f6421..b507b30 100755
--- a/bin/lessc
+++ b/bin/lessc
@@ -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;
diff --git a/lib/less/functions/data-uri.js b/lib/less/functions/data-uri.js
index ce8e50d..c4f0f4a 100644
--- a/lib/less/functions/data-uri.js
+++ b/lib/less/functions/data-uri.js
@@ -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);
             }
diff --git a/lib/less/functions/string.js b/lib/less/functions/string.js
index 1b55d4c..31fbf6b 100644
--- a/lib/less/functions/string.js
+++ b/lib/less/functions/string.js
@@ -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;
diff --git a/lib/less/functions/svg.js b/lib/less/functions/svg.js
index ceec585..92336d1 100644
--- a/lib/less/functions/svg.js
+++ b/lib/less/functions/svg.js
@@ -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">' +
diff --git a/lib/less/functions/types.js b/lib/less/functions/types.js
index adc1347..da71286 100644
--- a/lib/less/functions/types.js
+++ b/lib/less/functions/types.js
@@ -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) {
diff --git a/lib/less/import-manager.js b/lib/less/import-manager.js
index 79ac50e..316df79 100644
--- a/lib/less/import-manager.js
+++ b/lib/less/import-manager.js
@@ -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);
                 }
diff --git a/lib/less/parser/parser.js b/lib/less/parser/parser.js
index a56dc87..5a30e55 100644
--- a/lib/less/parser/parser.js
+++ b/lib/less/parser/parser.js
@@ -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();
diff --git a/lib/less/tree/condition.js b/lib/less/tree/condition.js
index a451593..3278942 100644
--- a/lib/less/tree/condition.js
+++ b/lib/less/tree/condition.js
@@ -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;
 };
diff --git a/lib/less/tree/mixin-definition.js b/lib/less/tree/mixin-definition.js
index 41b74a1..5320c08 100644
--- a/lib/less/tree/mixin-definition.js
+++ b/lib/less/tree/mixin-definition.js
@@ -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;
diff --git a/lib/less/visitors/extend-visitor.js b/lib/less/visitors/extend-visitor.js
index 5df87df..df16436 100644
--- a/lib/less/visitors/extend-visitor.js
+++ b/lib/less/visitors/extend-visitor.js
@@ -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++;
         }
 
diff --git a/lib/less/visitors/import-visitor.js b/lib/less/visitors/import-visitor.js
index e9faf91..80ac219 100644
--- a/lib/less/visitors/import-visitor.js
+++ b/lib/less/visitors/import-visitor.js
@@ -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) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git



More information about the Pkg-javascript-commits mailing list