diff --git a/build/flaws.js b/build/flaws.js index 9180135fc86c..03b73d33a5c1 100644 --- a/build/flaws.js +++ b/build/flaws.js @@ -401,7 +401,7 @@ async function fixFixableFlaws(doc, options, document) { const loud = options.fixFlawsDryRun || options.fixFlawsVerbose; - // Any 'macros' of type "MacroRedirectedLinkError"... + // Any 'macros' of type "MacroRedirectedLinkError" or "MacroDeprecatedError"... for (const flaw of doc.flaws.macros || []) { if (flaw.fixable) { // Sanity check that our understanding of flaws, filepaths, and sources diff --git a/build/index.js b/build/index.js index 9cba67ee05b2..a3f1746fcc68 100644 --- a/build/index.js +++ b/build/index.js @@ -286,15 +286,21 @@ async function buildDocument(document, documentOptions = {}) { // kumascript rendering, so we "beef it up" to have convenient // attributes needed. doc.flaws.macros = flaws.map((flaw, i) => { - const fixable = + let fixable = false; + let suggestion = null; + if (flaw.name === "MacroDeprecatedError") { + fixable = true; + suggestion = ""; + } else if ( flaw.name === "MacroRedirectedLinkError" && - (!flaw.filepath || flaw.filepath === document.fileInfo.path); - const suggestion = fixable - ? flaw.macroSource.replace( - flaw.redirectInfo.current, - flaw.redirectInfo.suggested - ) - : null; + (!flaw.filepath || flaw.filepath === document.fileInfo.path) + ) { + fixable = true; + suggestion = flaw.macroSource.replace( + flaw.redirectInfo.current, + flaw.redirectInfo.suggested + ); + } const id = `macro${i}`; const explanation = flaw.error.message; return Object.assign({ id, fixable, suggestion, explanation }, flaw); diff --git a/client/src/document/toolbar/flaws.tsx b/client/src/document/toolbar/flaws.tsx index cfab297b009f..f28f09334ce1 100644 --- a/client/src/document/toolbar/flaws.tsx +++ b/client/src/document/toolbar/flaws.tsx @@ -341,7 +341,7 @@ function FixableFlawsAction({ function FixableFlawBadge() { return ( - + Fixable{" "} 👍🏼 diff --git a/testing/content/files/en-us/web/fixable_flaws/deprecated_macros/index.html b/testing/content/files/en-us/web/fixable_flaws/deprecated_macros/index.html new file mode 100644 index 000000000000..7ae1818ada06 --- /dev/null +++ b/testing/content/files/en-us/web/fixable_flaws/deprecated_macros/index.html @@ -0,0 +1,13 @@ +--- +title: Deprecated macros +slug: Web/Fixable_Flaws/Deprecated_macros +--- + +

Don't use macros no more

+ +
    +
  • {{ fx_minversion_header(3.5) }}
  • +
  • {{ fx_minversion_inline("9") }}
  • +
  • {{gecko_minversion_inline("25")}}
  • +
  • {{ gecko_minversion_header("1.9.1")}}
  • +
diff --git a/testing/tests/destructive.test.js b/testing/tests/destructive.test.js index 346e40747537..e595d1ef2bd9 100644 --- a/testing/tests/destructive.test.js +++ b/testing/tests/destructive.test.js @@ -98,10 +98,11 @@ describe("fixing flaws", () => { const dryRunNotices = stdout .split("\n") .filter((line) => regexPattern.test(line)); - expect(dryRunNotices.length).toBe(3); - expect(dryRunNotices[2]).toContain(pattern); - expect(dryRunNotices[1]).toContain(path.join(pattern, "images")); + expect(dryRunNotices.length).toBe(4); expect(dryRunNotices[0]).toContain(path.join(pattern, "bad_pre_tags")); + expect(dryRunNotices[1]).toContain(path.join(pattern, "deprecated_macros")); + expect(dryRunNotices[2]).toContain(path.join(pattern, "images")); + expect(dryRunNotices[3]).toContain(pattern); const dryrunFiles = getChangedFiles(tempContentDir); expect(dryrunFiles.length).toBe(0); }); @@ -124,7 +125,7 @@ describe("fixing flaws", () => { expect(stdout).toContain(pattern); const files = getChangedFiles(tempContentDir); - expect(files.length).toBe(3); + expect(files.length).toBe(4); const imagesFile = files.find((f) => f.includes(path.join(pattern, "images")) ); @@ -137,8 +138,18 @@ describe("fixing flaws", () => { const newRawHtmlPreWithHTML = fs.readFileSync(badPreTagFile, "utf-8"); expect(newRawHtmlPreWithHTML).not.toContain(""); + const deprecatedMacrosFile = files.find((f) => + f.includes(path.join(pattern, "deprecated_macros")) + ); + const newRawHtmlDeprecatedMacros = fs.readFileSync( + deprecatedMacrosFile, + "utf-8" + ); + expect(newRawHtmlDeprecatedMacros).not.toContain("{{"); + const regularFile = files.find( - (f) => f !== imagesFile && f !== badPreTagFile + (f) => + f !== imagesFile && f !== badPreTagFile && f !== deprecatedMacrosFile ); const newRawHtml = fs.readFileSync(regularFile, "utf-8"); expect(newRawHtml).toContain("{{CSSxRef('number')}}"); diff --git a/testing/tests/index.test.js b/testing/tests/index.test.js index e4ea5edc797d..30230d7b82b5 100644 --- a/testing/tests/index.test.js +++ b/testing/tests/index.test.js @@ -1106,3 +1106,23 @@ test("headings with HTML should be rendered as HTML", () => { "You can use escaped HTML tags like
 still"
   );
 });
+
+test("deprecated macros are fixable", () => {
+  const builtFolder = path.join(
+    buildRoot,
+    "en-us",
+    "docs",
+    "web",
+    "fixable_flaws",
+    "deprecated_macros"
+  );
+
+  const jsonFile = path.join(builtFolder, "index.json");
+  const { doc } = JSON.parse(fs.readFileSync(jsonFile));
+  expect(doc.flaws.macros.length).toBe(4);
+  // All fixable and all a suggestion of ''
+  expect(doc.flaws.macros.filter((flaw) => flaw.fixable).length).toBe(4);
+  expect(doc.flaws.macros.filter((flaw) => flaw.suggestion === "").length).toBe(
+    4
+  );
+});