Skip to content

Commit

Permalink
Adjust code to pass eslint one-var (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbarth authored Jun 15, 2023
1 parent 20024c8 commit 329e427
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"no-console": "error",
"no-unused-vars": "warn",
"no-prototype-builtins": "warn",
"one-var": ["warn", "never"],
"one-var": ["error", "never"],
"no-duplicate-imports": "error",
"no-use-before-define": "error",
"curly": "warn",
Expand Down
10 changes: 5 additions & 5 deletions example/example.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable no-console */

var select = require("xml-crypto").xpath,
dom = require("@xmldom/xmldom").DOMParser,
SignedXml = require("xml-crypto").SignedXml,
FileKeyInfo = require("xml-crypto").FileKeyInfo,
fs = require("fs");
var select = require("xml-crypto").xpath;
var dom = require("@xmldom/xmldom").DOMParser;
var SignedXml = require("xml-crypto").SignedXml;
var FileKeyInfo = require("xml-crypto").FileKeyInfo;
var fs = require("fs");

function signXml(xml, xpath, key, dest) {
var sig = new SignedXml();
Expand Down
44 changes: 22 additions & 22 deletions lib/c14n-canonicalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ C14nCanonicalization.prototype.nsCompare = function (a, b) {
};

C14nCanonicalization.prototype.renderAttrs = function (node, defaultNS) {
var a,
i,
attr,
res = [],
attrListToRender = [];
var a;
var i;
var attr;
var res = [];
var attrListToRender = [];

if (node.nodeType === 8) {
return this.renderComment(node);
Expand Down Expand Up @@ -85,14 +85,14 @@ C14nCanonicalization.prototype.renderNs = function (
defaultNsForPrefix,
ancestorNamespaces
) {
var a,
i,
p,
attr,
res = [],
newDefaultNs = defaultNs,
nsListToRender = [],
currNs = node.namespaceURI || "";
var a;
var i;
var p;
var attr;
var res = [];
var newDefaultNs = defaultNs;
var nsListToRender = [];
var currNs = node.namespaceURI || "";

//handle the namespaceof the node itself
if (node.prefix) {
Expand Down Expand Up @@ -184,10 +184,10 @@ C14nCanonicalization.prototype.processInner = function (
return utils.encodeSpecialCharactersInText(node.data);
}

var i,
pfxCopy,
ns = this.renderNs(node, prefixesInScope, defaultNs, defaultNsForPrefix, ancestorNamespaces),
res = ["<", node.tagName, ns.rendered, this.renderAttrs(node, ns.newDefaultNs), ">"];
var i;
var pfxCopy;
var ns = this.renderNs(node, prefixesInScope, defaultNs, defaultNsForPrefix, ancestorNamespaces);
var res = ["<", node.tagName, ns.rendered, this.renderAttrs(node, ns.newDefaultNs), ">"];

for (i = 0; i < node.childNodes.length; ++i) {
pfxCopy = prefixesInScope.slice(0);
Expand All @@ -206,13 +206,13 @@ C14nCanonicalization.prototype.renderComment = function (node) {
return "";
}

var isOutsideDocument = node.ownerDocument === node.parentNode,
isBeforeDocument = null,
isAfterDocument = null;
var isOutsideDocument = node.ownerDocument === node.parentNode;
var isBeforeDocument = null;
var isAfterDocument = null;

if (isOutsideDocument) {
var nextNode = node,
previousNode = node;
var nextNode = node;
var previousNode = node;

while (nextNode !== null) {
if (nextNode === node.ownerDocument.documentElement) {
Expand Down
56 changes: 28 additions & 28 deletions lib/exclusive-canonicalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ ExclusiveCanonicalization.prototype.nsCompare = function (a, b) {
};

ExclusiveCanonicalization.prototype.renderAttrs = function (node, defaultNS) {
var a,
i,
attr,
res = [],
attrListToRender = [];
var a;
var i;
var attr;
var res = [];
var attrListToRender = [];

if (node.nodeType === 8) {
return this.renderComment(node);
Expand Down Expand Up @@ -94,14 +94,14 @@ ExclusiveCanonicalization.prototype.renderNs = function (
defaultNsForPrefix,
inclusiveNamespacesPrefixList
) {
var a,
i,
p,
attr,
res = [],
newDefaultNs = defaultNs,
nsListToRender = [],
currNs = node.namespaceURI || "";
var a;
var i;
var p;
var attr;
var res = [];
var newDefaultNs = defaultNs;
var nsListToRender = [];
var currNs = node.namespaceURI || "";

//handle the namespaceof the node itself
if (node.prefix) {
Expand Down Expand Up @@ -186,16 +186,16 @@ ExclusiveCanonicalization.prototype.processInner = function (
return utils.encodeSpecialCharactersInText(node.data);
}

var i,
pfxCopy,
ns = this.renderNs(
node,
prefixesInScope,
defaultNs,
defaultNsForPrefix,
inclusiveNamespacesPrefixList
),
res = ["<", node.tagName, ns.rendered, this.renderAttrs(node, ns.newDefaultNs), ">"];
var i;
var pfxCopy;
var ns = this.renderNs(
node,
prefixesInScope,
defaultNs,
defaultNsForPrefix,
inclusiveNamespacesPrefixList
);
var res = ["<", node.tagName, ns.rendered, this.renderAttrs(node, ns.newDefaultNs), ">"];

for (i = 0; i < node.childNodes.length; ++i) {
pfxCopy = prefixesInScope.slice(0);
Expand All @@ -220,13 +220,13 @@ ExclusiveCanonicalization.prototype.renderComment = function (node) {
return "";
}

var isOutsideDocument = node.ownerDocument === node.parentNode,
isBeforeDocument = null,
isAfterDocument = null;
var isOutsideDocument = node.ownerDocument === node.parentNode;
var isBeforeDocument = null;
var isAfterDocument = null;

if (isOutsideDocument) {
var nextNode = node,
previousNode = node;
var nextNode = node;
var previousNode = node;

while (nextNode !== null) {
if (nextNode === node.ownerDocument.documentElement) {
Expand Down
4 changes: 2 additions & 2 deletions lib/file-key-info.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var StringKeyInfo = require("./string-key-info"),
fs = require("fs");
var StringKeyInfo = require("./string-key-info");
var fs = require("fs");

/**
* A key info provider implementation
Expand Down
39 changes: 20 additions & 19 deletions lib/signed-xml.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var xpath = require("xpath"),
Dom = require("@xmldom/xmldom").DOMParser,
utils = require("./utils"),
c14n = require("./c14n-canonicalization"),
execC14n = require("./exclusive-canonicalization"),
EnvelopedSignature = require("./enveloped-signature").EnvelopedSignature,
StringKeyInfo = require("./string-key-info"),
FileKeyInfo = require("./file-key-info"),
crypto = require("crypto");
var xpath = require("xpath");
var Dom = require("@xmldom/xmldom").DOMParser;
var utils = require("./utils");
var c14n = require("./c14n-canonicalization");
var execC14n = require("./exclusive-canonicalization");
var EnvelopedSignature = require("./enveloped-signature").EnvelopedSignature;
var StringKeyInfo = require("./string-key-info");
var FileKeyInfo = require("./file-key-info");
var crypto = require("crypto");

/**
* Hash algorithm implementation
Expand Down Expand Up @@ -256,7 +256,8 @@ function findAncestorNs(doc, docSubsetXpath, namespaceResolver) {
}

function validateDigestValue(digest, expectedDigest) {
var buffer, expectedBuffer;
var buffer;
var expectedBuffer;

var majorVersion = /^v(\d+)/.exec(process.version)[1];

Expand Down Expand Up @@ -739,13 +740,13 @@ SignedXml.prototype.computeSignature = function (xml, opts, callback) {
throw new Error("Last parameter must be a callback function");
}

var doc = new Dom().parseFromString(xml),
xmlNsAttr = "xmlns",
signatureAttrs = [],
location,
attrs,
prefix,
currentPrefix;
var doc = new Dom().parseFromString(xml);
var xmlNsAttr = "xmlns";
var signatureAttrs = [];
var location;
var attrs;
var prefix;
var currentPrefix;

var validActions = ["append", "prepend", "before", "after"];

Expand Down Expand Up @@ -913,8 +914,8 @@ SignedXml.prototype.createReferences = function (doc, prefix) {
for (var n in this.references) {
if (!this.references.hasOwnProperty(n)) continue;

var ref = this.references[n],
nodes = xpath.selectWithResolver(ref.xpath, doc, this.namespaceResolver);
var ref = this.references[n];
var nodes = xpath.selectWithResolver(ref.xpath, doc, this.namespaceResolver);

if (nodes.length == 0) {
throw new Error(
Expand Down
8 changes: 4 additions & 4 deletions test/c14n-non-exclusive-unit-test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var expect = require("chai").expect;

var C14nCanonicalization = require("../lib/c14n-canonicalization").C14nCanonicalization,
Dom = require("@xmldom/xmldom").DOMParser,
select = require("xpath").select,
findAncestorNs = require("../lib/signed-xml").SignedXml.findAncestorNs;
var C14nCanonicalization = require("../lib/c14n-canonicalization").C14nCanonicalization;
var Dom = require("@xmldom/xmldom").DOMParser;
var select = require("xpath").select;
var findAncestorNs = require("../lib/signed-xml").SignedXml.findAncestorNs;

var test_C14nCanonicalization = function (xml, xpath, expected) {
var doc = new Dom().parseFromString(xml);
Expand Down
8 changes: 4 additions & 4 deletions test/c14nWithComments-unit-tests.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var expect = require("chai").expect;

var c14nWithComments =
require("../lib/exclusive-canonicalization").ExclusiveCanonicalizationWithComments,
Dom = require("@xmldom/xmldom").DOMParser,
select = require("xpath").select,
SignedXml = require("../lib/signed-xml.js").SignedXml;
require("../lib/exclusive-canonicalization").ExclusiveCanonicalizationWithComments;
var Dom = require("@xmldom/xmldom").DOMParser;
var select = require("xpath").select;
var SignedXml = require("../lib/signed-xml.js").SignedXml;

var compare = function (xml, xpath, expected, inclusiveNamespacesPrefixList) {
var doc = new Dom().parseFromString(xml);
Expand Down
8 changes: 4 additions & 4 deletions test/canonicalization-unit-tests.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var expect = require("chai").expect;

var ExclusiveCanonicalization =
require("../lib/exclusive-canonicalization").ExclusiveCanonicalization,
Dom = require("@xmldom/xmldom").DOMParser,
select = require("xpath").select,
SignedXml = require("../lib/signed-xml.js").SignedXml;
require("../lib/exclusive-canonicalization").ExclusiveCanonicalization;
var Dom = require("@xmldom/xmldom").DOMParser;
var select = require("xpath").select;
var SignedXml = require("../lib/signed-xml.js").SignedXml;

var compare = function (xml, xpath, expected, inclusiveNamespacesPrefixList, defaultNsForPrefix) {
var doc = new Dom().parseFromString(xml);
Expand Down
10 changes: 5 additions & 5 deletions test/signature-integration-tests.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var xpath = require("xpath"),
Dom = require("@xmldom/xmldom").DOMParser,
SignedXml = require("../lib/signed-xml.js").SignedXml,
fs = require("fs"),
crypto = require("../index");
var xpath = require("xpath");
var Dom = require("@xmldom/xmldom").DOMParser;
var SignedXml = require("../lib/signed-xml.js").SignedXml;
var fs = require("fs");
var crypto = require("../index");
var expect = require("chai").expect;

describe("Signature integration tests", function () {
Expand Down
12 changes: 6 additions & 6 deletions test/signature-unit-tests.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var select = require("xpath").select,
dom = require("@xmldom/xmldom").DOMParser,
SignedXml = require("../lib/signed-xml.js").SignedXml,
FileKeyInfo = require("../lib/signed-xml.js").FileKeyInfo,
fs = require("fs"),
crypto = require("crypto");
var select = require("xpath").select;
var dom = require("@xmldom/xmldom").DOMParser;
var SignedXml = require("../lib/signed-xml.js").SignedXml;
var FileKeyInfo = require("../lib/signed-xml.js").FileKeyInfo;
var fs = require("fs");
var crypto = require("crypto");
var expect = require("chai").expect;

describe("Signature unit tests", function () {
Expand Down

0 comments on commit 329e427

Please sign in to comment.