Skip to content

Commit

Permalink
Merge pull request #5 from gitblit/Equality-Fixes
Browse files Browse the repository at this point in the history
Adjust equality checks after a lint scan
  • Loading branch information
vasan-agrostar authored Jun 2, 2024
2 parents 3c539a6 + 9427f7c commit 805ae6a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
16 changes: 8 additions & 8 deletions src/convertPostman.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ function reformatVariables(text: string): string {
// Recursive function to replace variables in an object in-situ
function reformatVariablesInObject(object: any): void {
for (const key in object) {
if (typeof object[key] == "string") {
if (typeof object[key] === "string") {
object[key] = reformatVariables(object[key]);
} else if (typeof object[key] == "object") {
} else if (typeof object[key] === "object") {
reformatVariablesInObject(object[key]);
}
// else: boolean, null etc: these can't hold variable strings
Expand Down Expand Up @@ -43,7 +43,7 @@ function addRequest(prefix: string, element: any, requests: any): void {
request.headers = {};
for (const h of r.header) {
request.headers[h.key] = reformatVariables(h.value);
if (h.key.toLowerCase() == "content-type") {
if (h.key.toLowerCase() === "content-type") {
contentType = h.value;
}
}
Expand All @@ -65,8 +65,8 @@ function addRequest(prefix: string, element: any, requests: any): void {
}
}

if (r.body && r.body.mode == "raw") {
if (r.body?.options?.raw?.language == "json" || contentType == "application/json") {
if (r.body && r.body.mode === "raw") {
if (r.body?.options?.raw?.language === "json" || contentType === "application/json") {
try {
request.body = JSON.parse(r.body.raw);
reformatVariablesInObject(request.body);
Expand Down Expand Up @@ -97,7 +97,7 @@ export default function convertCollection(filePath: string): string {
const contents = fs.readFileSync(filePath, "utf-8");
const collection = JSON.parse(contents);
if (
collection?.info?.schema != "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
collection?.info?.schema !== "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
) {
throw Error("Not a Postman v2.1.0 collection. Cannot import");
}
Expand All @@ -113,13 +113,13 @@ export default function convertCollection(filePath: string): string {
const yamlDoc = new YAML.Document(bundle);
YAML.visit(yamlDoc, {
Pair(_, node: any) {
if (node?.key?.value == "requests") {
if (node?.key?.value === "requests") {
node.key.spaceBefore = true;
node.value.items.forEach((i: any) => {
i.key.spaceBefore = true;
});
}
if (node?.key?.value == "headers" || node?.key?.value == "params") {
if (node?.key?.value === "headers" || node?.key?.value === "params") {
node.value.items.forEach((i: any) => {
i.flow = true;
});
Expand Down
14 changes: 7 additions & 7 deletions src/mergeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ function getMergedHeaders(
function getMergedOptions(cOptions: RawOptions = {}, rOptions: RawOptions = {}): Options {
const options = Object.assign(cOptions, rOptions);

const follow = options.follow == true;
const verifySSL = options.verifySSL == true;
const keepRawJSON = options.keepRawJSON == true;
const showHeaders = options.showHeaders == true;
const rawParams = options.rawParams == true;
const stopOnFailure = options.stopOnFailure == true;
const follow = options.follow === true;
const verifySSL = options.verifySSL === true;
const keepRawJSON = options.keepRawJSON === true;
const showHeaders = options.showHeaders === true;
const rawParams = options.rawParams === true;
const stopOnFailure = options.stopOnFailure === true;

return { follow, verifySSL, keepRawJSON, showHeaders, rawParams, stopOnFailure };
}
Expand Down Expand Up @@ -122,7 +122,7 @@ function getMergedSetVars(
} else if (spec.startsWith("$h.")) {
type = "header";
spec = spec.replace(/^\$h\./, "");
} else if (spec == "status" || spec == "body") {
} else if (spec === "status" || spec === "body") {
type = spec;
} else {
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function runObjectTests(
let message = "";
if (op === "$eq") {
pass = received === expected;
} else if (op == "$ne") {
} else if (op === "$ne") {
pass = received !== expected;
} else if (op === "$lt") {
pass = received < expected;
Expand Down Expand Up @@ -116,7 +116,7 @@ function runObjectTests(
}
}
} else if (op === "$exists") {
const exists = received != undefined;
const exists = received !== undefined;
pass = exists === expected;
} else if (op === "$type") {
const receivedType = getType(receivedObject);
Expand Down

0 comments on commit 805ae6a

Please sign in to comment.