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

MacroDeprecatedError should be fixable #2746

Merged
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
2 changes: 1 addition & 1 deletion build/flaws.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 14 additions & 8 deletions build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion client/src/document/toolbar/flaws.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ function FixableFlawsAction({

function FixableFlawBadge() {
return (
<span className="macro-fixable" title="This flaw is fixable.">
<span title="This flaw is fixable.">
Fixable{" "}
<span role="img" aria-label="Thumbs up">
👍🏼
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: Deprecated macros
slug: Web/Fixable_Flaws/Deprecated_macros
---

<p class="summary">Don't use macros no more</p>

<ul>
<li>{{ fx_minversion_header(3.5) }}</li>
<li>{{ fx_minversion_inline("9") }}</li>
<li>{{gecko_minversion_inline("25")}}</li>
<li>{{ gecko_minversion_header("1.9.1")}}</li>
</ul>
21 changes: 16 additions & 5 deletions testing/tests/destructive.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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"))
);
Expand All @@ -137,8 +138,18 @@ describe("fixing flaws", () => {
const newRawHtmlPreWithHTML = fs.readFileSync(badPreTagFile, "utf-8");
expect(newRawHtmlPreWithHTML).not.toContain("<code>");

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')}}");
Expand Down
20 changes: 20 additions & 0 deletions testing/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1106,3 +1106,23 @@ test("headings with HTML should be rendered as HTML", () => {
"You can use escaped HTML tags like <pre> 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
);
});