Skip to content

Commit

Permalink
Improved error messaging for duplicate id attributes #3560
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Dec 10, 2024
1 parent b7f32f5 commit ba1c228
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/Plugins/IdAttributePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ function IdAttributePlugin(eleventyConfig, options = {}) {
} else if (options.checkDuplicates === "error") {
// Existing `id` conflicts with assigned heading id, throw error
throw new Error(
"Duplicate `id` attribute (" +
'You have more than one HTML `id` attribute using the same value (id="' +
id +
") in markup on " +
pluginOptions.page.inputPath,
'") in your template (' +
pluginOptions.page.inputPath +
"). You can disable this error in the IdAttribute plugin with the `checkDuplicates: false` option.",
);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion test/IdAttributePluginTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ test("Issue #3424, id attribute conflicts (two hard coded id conflicts)", async
elev.disableLogger();

let e = await t.throwsAsync(() => elev.toJSON());
t.is(e.originalError.originalError.toString(), "Error: Duplicate `id` attribute (testing) in markup on ./test/stubs-virtual/test.html");
t.is(e.originalError.originalError.toString(), `Error: You have more than one HTML \`id\` attribute using the same value (id="testing") in your template (./test/stubs-virtual/test.html). You can disable this error in the IdAttribute plugin with the \`checkDuplicates: false\` option.`);
});

test("Issue #3424, filter callback skips", async (t) => {
Expand Down

0 comments on commit ba1c228

Please sign in to comment.