Skip to content

Commit

Permalink
Merge pull request #44 from SAP/dependabot/npm_and_yarn/eslint-tw-5.5.0
Browse files Browse the repository at this point in the history
Update eslint requirement from ^1.10.3 to ^5.5.0
  • Loading branch information
matz3 authored Sep 10, 2018
2 parents 00318d4 + cc64ce1 commit 21360e5
Show file tree
Hide file tree
Showing 17 changed files with 1,804 additions and 2,070 deletions.
45 changes: 0 additions & 45 deletions .eslintrc

This file was deleted.

48 changes: 48 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module.exports = {
"env": {
"node": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 8
},
"extends": ["eslint:recommended", "google"],
"rules": {
"indent": [
"error",
"tab"
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
],
"no-negated-condition": "off",
"require-jsdoc": "off",
"no-mixed-requires": "off",
"max-len": ["warn", 120],
"no-implicit-coercion": [
2,
{ "allow": ["!!"] }
],
"comma-dangle": "off",
"no-tabs": "off",
'valid-jsdoc': [
2,
{
requireParamDescription: false,
requireReturnDescription: false,
requireReturn: false,
prefer: {return: 'returns'},
}
],
},
"root": true
};
47 changes: 18 additions & 29 deletions lib/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@
// either express or implied. See the License for the specific
// language governing permissions and limitations under the License.

'use strict';
"use strict";

// Regular expression to match type of property in order to check whether
// it possibly contains color values.
var rProperties = /(color|background|border|text|outline)(?!\-(width|radius|offset|style|align|overflow|transform))(\-(color|shadow|image))?/;
let rProperties = /(color|background|border|text|outline)(?!-(width|radius|offset|style|align|overflow|transform))(-(color|shadow|image))?/;

function selectorEquals(s1, s2) {

// Make sure there is the same number of select parts
if (s1.length !== s2.length) {
return false;
}

// Check if all the parts are the same strings
for (var i = 0; i < s1.length; i++) {
for (let i = 0; i < s1.length; i++) {
if (s1[i] !== s2[i]) {
return false;
}
Expand Down Expand Up @@ -55,13 +54,13 @@ function Diffing(oBase, oCompare) {
}

Diffing.prototype.diffRules = function(oBaseRules, oCompareRules) {
var aDiffRules = [];
var iBaseNode, iCompareNode;
let aDiffRules = [];
let iBaseNode; let iCompareNode;

for (iBaseNode = 0, iCompareNode = 0; iBaseNode < oBaseRules.length; iBaseNode++, iCompareNode++) {
var oBaseNode = oBaseRules[iBaseNode];
var oCompareNode = oCompareRules[iCompareNode];
var oDiffNode = null;
let oBaseNode = oBaseRules[iBaseNode];
let oCompareNode = oCompareRules[iCompareNode];
let oDiffNode = null;

// Add all different compare nodes to stack and check for next one
while (oBaseNode.type !== oCompareNode.type) {
Expand All @@ -71,69 +70,59 @@ Diffing.prototype.diffRules = function(oBaseRules, oCompareRules) {
}

if (oBaseNode.type === "comment") {
var sBaseComment = oBaseNode.comment;
var sCompareComment = oCompareNode.comment;
let sBaseComment = oBaseNode.comment;
let sCompareComment = oCompareNode.comment;

if (sBaseComment !== sCompareComment) {
oDiffNode = oCompareNode;
}
}

if (oBaseNode.type === "rule") {

// Add all rules with different selector to stack and check for next one
while (!selectorEquals(oBaseNode.selectors, oCompareNode.selectors)) {
this.oStack.stylesheet.rules.push(oCompareNode);
iCompareNode++;
oCompareNode = oCompareRules[iCompareNode];
}

var aBaseDeclarations = oBaseNode.declarations;
var aCompareDeclarations = oCompareNode.declarations;
for (var j = 0; j < aBaseDeclarations.length; j++) {
var oBaseDeclaration = aBaseDeclarations[j];
var oCompareDeclaration = aCompareDeclarations[j];
let aBaseDeclarations = oBaseNode.declarations;
let aCompareDeclarations = oCompareNode.declarations;
for (let j = 0; j < aBaseDeclarations.length; j++) {
let oBaseDeclaration = aBaseDeclarations[j];
let oCompareDeclaration = aCompareDeclarations[j];

if (oBaseDeclaration.type === "declaration") {

// TODO: Also check for different node and add to stack???
if (oBaseDeclaration.type === oCompareDeclaration.type) {

if (oBaseDeclaration.property === oCompareDeclaration.property) {

// Always add color properties to diff to prevent unexpected CSS overrides
// due to selectors with more importance
if (oBaseDeclaration.value !== oCompareDeclaration.value
|| oCompareDeclaration.property.match(rProperties)) {

// Add compared rule to diff
if (!oDiffNode) {
oDiffNode = oCompareNode;
oDiffNode.declarations = [];
}
oDiffNode.declarations.push(oCompareDeclaration);
}

}
}
}
}

} else if (oBaseNode.type === "media") {

var aMediaDiffRules = this.diffRules(oBaseNode.rules, oCompareNode.rules);
let aMediaDiffRules = this.diffRules(oBaseNode.rules, oCompareNode.rules);

if (aMediaDiffRules.length > 0) {
oDiffNode = oCompareNode;
oDiffNode.rules = aMediaDiffRules;
}

}

if (oDiffNode) {
aDiffRules.push(oDiffNode);
}

}

// Add all leftover compare nodes to stack
Expand All @@ -145,8 +134,8 @@ Diffing.prototype.diffRules = function(oBaseRules, oCompareRules) {
};

Diffing.prototype.run = function() {
var oBaseRules = this.oBase.stylesheet.rules;
var oCompareRules = this.oCompare.stylesheet.rules;
let oBaseRules = this.oBase.stylesheet.rules;
let oCompareRules = this.oCompare.stylesheet.rules;

this.oDiff.stylesheet.rules = this.diffRules(oBaseRules, oCompareRules);

Expand Down
12 changes: 6 additions & 6 deletions lib/fileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
// either express or implied. See the License for the specific
// language governing permissions and limitations under the License.

'use strict';
"use strict";

var path = require('path');
let path = require("path");

module.exports = function(fs) {
if (!fs) {
fs = require('fs');
fs = require("fs");
}

function statFile(filePath) {
return new Promise(function(resolve, reject) {
fs.stat(filePath, function(err, stat) {
// No rejection here as it is ok if the file was not found
resolve(stat ? { path: filePath, stat: stat } : null);
resolve(stat ? {path: filePath, stat: stat} : null);
});
});
}
Expand All @@ -41,7 +41,7 @@ module.exports = function(fs) {
return path.join(rootPath, filePath);
})
).then(function(results) {
for (var i = 0; i < results.length; i++) {
for (let i = 0; i < results.length; i++) {
if (results[i] !== null) {
return results[i];
}
Expand All @@ -62,7 +62,7 @@ module.exports = function(fs) {
}
return new Promise(function(resolve, reject) {
fs.readFile(fileInfo.path, {
encoding: 'utf8'
encoding: "utf8"
}, function(fileErr, content) {
if (fileErr) {
reject(fileErr);
Expand Down
Loading

0 comments on commit 21360e5

Please sign in to comment.