Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a source property to Warnings #160

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 },
fabnguess marked this conversation as resolved.
Show resolved Hide resolved
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