Skip to content

Commit

Permalink
refactor:Add a source property to Warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fabnguess committed Nov 26, 2023
1 parent c91a37e commit f681446
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ export const warnings = Object.freeze({
});

export function generateWarning(kind, options) {
const { location, file = null, value = null } = options;
const { location, file = null, value = null, source = "JS-X-Ray" } = options;

if (kind === "encoded-literal") {
return Object.assign(
{ kind, value, location: [utils.toArrayLocation(location)] },
{ kind, value, location: [utils.toArrayLocation(location)], source },
warnings[kind]
);
}

const result = { kind, location: utils.toArrayLocation(location) };
const result = { kind, location: utils.toArrayLocation(location), source };
if (utils.notNullOrUndefined(file)) {
result.file = file;
}
Expand Down
2 changes: 2 additions & 0 deletions test/warnings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ test("Given an encoded-literal kind it should generate a warning with deep locat
assert.deepEqual(result, {
kind: "encoded-literal",
value: null,
source: "JS-X-Ray",
location: [
[[0, 0], [0, 0]]
],
Expand All @@ -33,6 +34,7 @@ test("Given a weak-crypto kind it should generate a warning with value, simple l
kind: "weak-crypto",
value: "md5",
file: "hello.js",
source: "JS-X-Ray",
location: [
[0, 0], [0, 0]
],
Expand Down
1 change: 1 addition & 0 deletions types/warnings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface WarningDefault {
kind: WarningName;
file?: string;
value: string;
source: string;
location: WarningLocation | WarningLocation[];
i18n: string;
severity: "Information" | "Warning" | "Critical";
Expand Down

0 comments on commit f681446

Please sign in to comment.