Skip to content

Commit

Permalink
Fix validation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed Oct 16, 2024
1 parent a3cbf3c commit 76877f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/languages/json-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ export class JSONLanguage {
"allowTrailingCommas must be a boolean if provided.",
);
}
}

// we know that allowTrailingCommas is a boolean here
// we know that allowTrailingCommas is a boolean here

// only allowed in JSONC mode
if (this.#mode !== "jsonc") {
throw new Error(
"allowTrailingCommas option is only available in JSONC.",
);
// only allowed in JSONC mode
if (this.#mode !== "jsonc") {
throw new Error(
"allowTrailingCommas option is only available in JSONC.",
);
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions tests/languages/json-language.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ describe("JSONLanguage", () => {
language.validateLanguageOptions({});
});
});

it("should not throw an error when allowTrailingCommas is not provided and other keys are present", () => {
const language = new JSONLanguage({ mode: "jsonc" });
assert.doesNotThrow(() => {
language.validateLanguageOptions({ foo: "bar" });
});
});
});

describe("parse()", () => {
Expand Down

0 comments on commit 76877f4

Please sign in to comment.