Skip to content

Commit

Permalink
fix: look more thoroughly for xmldom/xmldom (#487)
Browse files Browse the repository at this point in the history
* fix: look more thoroughly for xmldom/xmldom

* update package.json to require node v20 or later

* feat: PO038 check KeyValueMapOperations MapName and identifier (#485)

* feat: PO038 check KeyValueMapOperations MapName and identifier

* add README update

* fix: BN013 correct handling of resource shortname (#486)

* fix: BN013 correct handling of resource shortname

* clean comments from test module

* fix: look more thoroughly for xmldom/xmldom

* update package.json to require node v20 or later

* fix: replace myUtil with lintUtil.js,and cleanup xmldom test
  • Loading branch information
DinoChiesa authored Nov 2, 2024
1 parent c52ef7d commit 099d2b5
Show file tree
Hide file tree
Showing 101 changed files with 3,276 additions and 238 deletions.
8 changes: 4 additions & 4 deletions lib/package/Bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const findFolders = require("./findFolders.js"),
bundleType = require("./BundleTypes.js"),
DEBUG = require("debug"),
debug = DEBUG("apigeelint:Bundle"),
myUtil = require("./myUtil.js"),
getcb = myUtil.curry(myUtil.diagcb, debug);
lintUtil = require("./lintUtil.js"),
getcb = lintUtil.curry(lintUtil.diagcb, debug);

function _buildEndpoints(folder, tag, bundle, processFunction) {
try {
Expand Down Expand Up @@ -206,7 +206,7 @@ function processFileSystem(config, bundle, cb) {
//bundle.policies = [];
//process.chdir(config.source.path);
bundle.report = {
filePath: myUtil.effectivePath(bundle.root, bundleTypeName),
filePath: lintUtil.effectivePath(bundle.root, bundleTypeName),
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
Expand Down Expand Up @@ -352,7 +352,7 @@ Bundle.prototype.getReport = function (cb) {
const docElement = new Dom().parseFromString(
fs.readFileSync(item.filePath).toString()
).documentElement;
const directives = myUtil.findDirectives(docElement);
const directives = lintUtil.findDirectives(docElement);
d(JSON.stringify(directives, null, 2));
if (directives.length > 0) {
const keep = (item) => {
Expand Down
8 changes: 4 additions & 4 deletions lib/package/Endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ const Flow = require("./Flow.js"),
RouteRule = require("./RouteRule.js"),
FaultRule = require("./FaultRule.js"),
xpath = require("xpath"),
myUtil = require("./myUtil.js"),
lintUtil = require("./lintUtil.js"),
debug = require("debug")("apigeelint:Endpoint"),
util = require("util"),
fs = require("fs"),
getcb = myUtil.curry(myUtil.diagcb, debug),
getcb = lintUtil.curry(lintUtil.diagcb, debug),
HTTPProxyConnection = require("./HTTPProxyConnection.js"),
HTTPTargetConnection = require("./HTTPTargetConnection.js"),
bundleTypes = require("./BundleTypes.js");
Expand All @@ -40,7 +40,7 @@ function Endpoint(element, parent, fname, bundletype) {
this.httpProxyConnection = null;
this.httpTargetConnection = null;
this.report = {
filePath: myUtil.effectivePath(fname, this.bundleType),
filePath: lintUtil.effectivePath(fname, this.bundleType),
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
Expand Down Expand Up @@ -132,7 +132,7 @@ Endpoint.prototype.getProxyName = function () {
this.proxyName =
this.fileName +
":" +
myUtil.buildTagBreadCrumb(this.element) +
lintUtil.buildTagBreadCrumb(this.element) +
this.getName();
}
return this.proxyName;
Expand Down
55 changes: 30 additions & 25 deletions lib/package/FaultRule.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019-2020 Google LLC
Copyright 2019-2020,2024 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -15,33 +15,33 @@
*/

const Condition = require("./Condition.js"),
xpath = require("xpath"),
debug = require("debug")("apigeelint:FaultRule"),
myUtil = require("./myUtil.js"),
getcb = myUtil.curry(myUtil.diagcb, debug);
xpath = require("xpath"),
debug = require("debug")("apigeelint:FaultRule"),
lintUtil = require("./lintUtil.js"),
getcb = lintUtil.curry(lintUtil.diagcb, debug);

function FaultRule(element, parent) {
this.parent = parent;
this.element = element;
}

FaultRule.prototype.getName = function() {
FaultRule.prototype.getName = function () {
if (!this.name) {
var attr = xpath.select("./@name", this.element);
this.name = (attr[0] && attr[0].value) || "";
}
return this.name;
};

FaultRule.prototype.getMessages = function() {
FaultRule.prototype.getMessages = function () {
return this.parent.getMessages();
};

FaultRule.prototype.getLines = function(start, stop) {
FaultRule.prototype.getLines = function (start, stop) {
return this.parent.getLines(start, stop);
};

FaultRule.prototype.getSource = function() {
FaultRule.prototype.getSource = function () {
if (!this.source) {
var start = this.element.lineNumber - 1,
stop = this.element.nextSibling.lineNumber - 1;
Expand All @@ -50,77 +50,82 @@ FaultRule.prototype.getSource = function() {
return this.source;
};

FaultRule.prototype.getType = function() {
FaultRule.prototype.getType = function () {
return this.element.tagName;
};

FaultRule.prototype.getSteps = function() {
FaultRule.prototype.getSteps = function () {
if (!this.steps) {
var doc = xpath.select("./Step", this.element),
fr = this,
Step = require("./Step.js");
fr.steps = [];
if (doc) {
doc.forEach(function(stElement) {
doc.forEach(function (stElement) {
fr.steps.push(new Step(stElement, fr));
});
}
}
return this.steps;
};

FaultRule.prototype.getCondition = function() {
FaultRule.prototype.getCondition = function () {
if (!this.condition) {
var doc = xpath.select("./Condition", this.element);
this.condition = doc && doc[0] && new Condition(doc[0], this);
}
return this.condition;
};

FaultRule.prototype.getElement = function() {
FaultRule.prototype.getElement = function () {
return this.element;
};

FaultRule.prototype.getParent = function() {
FaultRule.prototype.getParent = function () {
return this.parent;
};

FaultRule.prototype.addMessage = function(msg) {
FaultRule.prototype.addMessage = function (msg) {
if (!msg.hasOwnProperty("entity")) {
msg.entity = this;
}
this.parent.addMessage(msg);
};

FaultRule.prototype.onConditions = function(pluginFunction, callback) {
FaultRule.prototype.onConditions = function (pluginFunction, callback) {
let faultRule = this,
steps = faultRule.getSteps();
steps = faultRule.getSteps();
if (faultRule.getCondition()) {
pluginFunction(faultRule.getCondition(), getcb(`onConditions '${faultRule.getName()}'`));
pluginFunction(
faultRule.getCondition(),
getcb(`onConditions '${faultRule.getName()}'`),
);
}
if (steps && steps.length > 0) {
steps.forEach((step, ix) =>
step.onConditions(pluginFunction, getcb(`onConditions step ${ix}`)));
step.onConditions(pluginFunction, getcb(`onConditions step ${ix}`)),
);
}
callback(null, {});
};

FaultRule.prototype.onSteps = function(pluginFunction, callback) {
FaultRule.prototype.onSteps = function (pluginFunction, callback) {
let faultRule = this,
steps = faultRule.getSteps();
steps = faultRule.getSteps();
if (steps && steps.length > 0) {
steps.forEach((step, ix) =>
step.onSteps(pluginFunction, getcb(`onSteps step ${ix}`)));
step.onSteps(pluginFunction, getcb(`onSteps step ${ix}`)),
);
}
callback(null, {});
};

FaultRule.prototype.summarize = function() {
FaultRule.prototype.summarize = function () {
var summary = {};
summary.name = this.getName();
var theSteps = this.getSteps();
summary.steps = [];
theSteps.forEach(function(step) {
theSteps.forEach(function (step) {
summary.steps.push(step.summarize());
});
summary.condition =
Expand Down
6 changes: 3 additions & 3 deletions lib/package/Flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
const xpath = require("xpath"),
FlowPhase = require("./FlowPhase.js"),
Condition = require("./Condition.js"),
myUtil = require("./myUtil.js"),
lintUtil = require("./lintUtil.js"),
debug = require("debug")("apigeelint:Flow"),
getcb = myUtil.curry(myUtil.diagcb, debug);
getcb = lintUtil.curry(lintUtil.diagcb, debug);

function Flow(element, parent) {
this.parent = parent; // like ProxyEndpoint , TargetEndpoint
Expand Down Expand Up @@ -59,7 +59,7 @@ Flow.prototype.getType = function () {
Flow.prototype.getFlowName = function () {
if (!this.flowName) {
this.flowName =
myUtil.getFileName(this) + ":" + myUtil.buildTagBreadCrumb(this.element);
lintUtil.getFileName(this) + ":" + lintUtil.buildTagBreadCrumb(this.element);
if (this.getName()) {
this.flowName += this.name;
}
Expand Down
48 changes: 24 additions & 24 deletions lib/package/FlowPhase.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019 Google LLC
Copyright 2019,2024 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -15,77 +15,77 @@
*/

const xpath = require("xpath"),
Step = require("./Step.js"),
myUtil = require("./myUtil.js"),
debug = require("debug")("apigeelint:FlowPhase"),
getcb = myUtil.curry(myUtil.diagcb, debug);
Step = require("./Step.js"),
lintUtil = require("./lintUtil.js"),
debug = require("debug")("apigeelint:FlowPhase"),
getcb = lintUtil.curry(lintUtil.diagcb, debug);

function FlowPhase(element, parent) {
this.parent = parent;
this.element = element;
debug(`parent is ${parent.getType()}`);
}

FlowPhase.prototype.getType = function() {
FlowPhase.prototype.getType = function () {
if (!this.type) {
this.type = "FlowPhase";
//this.type = this.getPhase();
}
return this.type;
};

FlowPhase.prototype.getMessages = function() {
FlowPhase.prototype.getMessages = function () {
return this.parent.getMessages();
};

FlowPhase.prototype.getPhase = function() {
FlowPhase.prototype.getPhase = function () {
if (!this.phase) {
this.phase = this.element.tagName;
}
return this.phase;
};

FlowPhase.prototype.getSteps = function() {
FlowPhase.prototype.getSteps = function () {
if (!this.steps) {
let doc = xpath.select("./Step", this.element),
fp = this;
fp = this;
fp.steps = [];
if (doc) {
doc.forEach(function(stepElement) {
doc.forEach(function (stepElement) {
fp.steps.push(new Step(stepElement, fp));
});
}
}
return this.steps;
};

FlowPhase.prototype.onSteps = function(pluginFunction, cb) {
FlowPhase.prototype.onSteps = function (pluginFunction, cb) {
let steps = this.getSteps();
if (steps && steps.length > 0) {
steps.forEach( (step, ix) =>
pluginFunction(step, getcb(`step ${ix}`)));
steps.forEach((step, ix) => pluginFunction(step, getcb(`step ${ix}`)));
}
cb(null, {});
};

FlowPhase.prototype.onConditions = function(pluginFunction, cb) {
FlowPhase.prototype.onConditions = function (pluginFunction, cb) {
let steps = this.getSteps();
if (steps && steps.length > 0) {
steps.forEach( (step, ix) =>
step.onConditions(pluginFunction, getcb(`step ${ix}`)));
steps.forEach((step, ix) =>
step.onConditions(pluginFunction, getcb(`step ${ix}`)),
);
}
cb(null, {});
};

FlowPhase.prototype.getElement = function() {
FlowPhase.prototype.getElement = function () {
return this.element;
};

FlowPhase.prototype.getLines = function(start, stop) {
FlowPhase.prototype.getLines = function (start, stop) {
return this.parent.getLines(start, stop);
};

FlowPhase.prototype.getSource = function() {
FlowPhase.prototype.getSource = function () {
if (!this.source) {
var start = this.element.lineNumber - 1,
stop = this.element.nextSibling.lineNumber - 1;
Expand All @@ -94,22 +94,22 @@ FlowPhase.prototype.getSource = function() {
return this.source;
};

FlowPhase.prototype.getParent = function() {
FlowPhase.prototype.getParent = function () {
return this.parent;
};

FlowPhase.prototype.addMessage = function(msg) {
FlowPhase.prototype.addMessage = function (msg) {
if (!msg.hasOwnProperty("entity")) {
msg.entity = this;
}
this.parent.addMessage(msg);
};

FlowPhase.prototype.summarize = function() {
FlowPhase.prototype.summarize = function () {
var summary = {};
summary.steps = [];
var theSteps = this.getSteps();
theSteps.forEach(function(step) {
theSteps.forEach(function (step) {
summary.steps.push(step.summarize());
});
return summary;
Expand Down
4 changes: 2 additions & 2 deletions lib/package/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

const fs = require("fs"),
xpath = require("xpath"),
myUtil = require("./myUtil.js"),
lintUtil = require("./lintUtil.js"),
Dom = require("@xmldom/xmldom").DOMParser,
debug = require("debug")("apigeelint:Policy");

Expand All @@ -28,7 +28,7 @@ function Policy(path, fn, parent, doc) {
this.parent = parent;
if (doc) this.element = doc;
this.report = {
filePath: myUtil.effectivePath(this.filePath, this.bundleType),
filePath: lintUtil.effectivePath(this.filePath, this.bundleType),
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
Expand Down
Loading

0 comments on commit 099d2b5

Please sign in to comment.