help-beta: Add option to format mdx documents.

Partially fixes #35129.

Prettier could not be used because of prettier issue number 12209, not
linked here to avoid spam backlinks on the original issue. Prettier does
not have support for mdx v2 and v3.

We are using remarkLintRulesLintRecommended and
remarkPresentLintMarkdownStyleGuide as our starting set of rules.
None of the rules were giving an error on the starting set, but some
rules were giving lots of warnings on the generated mdx. They are
set to false in this file, we can add them back later as and when
required.

We have not inserted this in the main lint tool, we should do that in
the final cutover PR since we don't want the lint here to give any
unexpected warnings when people are linting stuff unrelated to the mdx
files.

This commit has been tested out on the current state of help center to
not produce any errors or warnings. The first run of format will produce
tons of warnings which are the issues being auto-fixed by the linter.
After that, the second run should produce zero errors.
This commit is contained in:
Shubham Padia
2025-07-17 08:59:10 +00:00
committed by Tim Abbott
parent 48c8e0a700
commit 4dc802aa9a
5 changed files with 1271 additions and 4 deletions

View File

@@ -7,7 +7,8 @@
"start": "astro dev",
"build": "astro check && astro build",
"preview": "astro preview",
"astro": "astro"
"astro": "astro",
"format": "remark --ext mdx --frail --output --quiet --use remark-mdx -- ."
},
"dependencies": {
"@astrojs/check": "^0.9.3",
@@ -26,6 +27,26 @@
"unplugin-icons": "^22.1.0"
},
"devDependencies": {
"@types/mdast": "^4.0.4"
"@types/mdast": "^4.0.4",
"remark-cli": "^12.0.1",
"remark-frontmatter": "^5.0.0",
"remark-lint-fenced-code-flag": "^4.2.0",
"remark-lint-file-extension": "^3.0.1",
"remark-lint-final-definition": "^4.0.2",
"remark-lint-heading-increment": "^4.0.1",
"remark-lint-list-item-indent": "^4.0.1",
"remark-lint-list-item-spacing": "^5.0.1",
"remark-lint-maximum-heading-length": "^4.1.1",
"remark-lint-maximum-line-length": "^4.1.1",
"remark-lint-no-duplicate-definitions": "^4.0.1",
"remark-lint-no-duplicate-headings": "^4.0.1",
"remark-lint-no-file-name-irregular-characters": "^3.0.1",
"remark-lint-no-file-name-mixed-case": "^3.0.1",
"remark-lint-no-unused-definitions": "^4.0.2",
"remark-lint-ordered-list-marker-value": "^4.0.1",
"remark-lint-unordered-list-marker-style": "^4.0.1",
"remark-preset-lint-markdown-style-guide": "^6.0.1",
"remark-preset-lint-recommended": "^7.0.1",
"unified": "^11.0.5"
}
}

View File

@@ -0,0 +1,58 @@
// We are using remarkLintRulesLintRecommended and
// remarkPresentLintMarkdownStyleGuide as our starting set of rules.
// None of the rules were giving an error on the starting set, but some
// rules were giving lots of warnings on the generated mdx. They are
// set to false in this file, we can add them back later as and when
// required.
/**
* @import {Preset} from 'unified'
*/
import remarkFrontmatter from "remark-frontmatter";
import remarkLintFencedCodeFlag from "remark-lint-fenced-code-flag";
import remarkLintFileExtension from "remark-lint-file-extension";
import remarkLintFinalDefinition from "remark-lint-final-definition";
import remarkLintHeadingIncrement from "remark-lint-heading-increment";
import remarkLintListItemIndent from "remark-lint-list-item-indent";
import remarkLintListItemSpacing from "remark-lint-list-item-spacing";
import remarkLintMaximumHeadingLength from "remark-lint-maximum-heading-length";
import remarkLintMaximumLineLength from "remark-lint-maximum-line-length";
import remarkLintNoDuplicateDefinitions from "remark-lint-no-duplicate-definitions";
import remarkLintNoDuplicateHeadings from "remark-lint-no-duplicate-headings";
import remarkLintNoFileNameIrregularCharacters from "remark-lint-no-file-name-irregular-characters";
import remarkLintNoFileNameMixedCase from "remark-lint-no-file-name-mixed-case";
import remarkLintNoUnusedDefinitions from "remark-lint-no-unused-definitions";
import remarkLintOrderedListMarkerValue from "remark-lint-ordered-list-marker-value";
import remarkLintUnorderedListMarkerStyle from "remark-lint-unordered-list-marker-style";
import remarkPresentLintMarkdownStyleGuide from "remark-preset-lint-markdown-style-guide";
import remarkLintRulesLintRecommended from "remark-preset-lint-recommended";
const remarkLintRules = {
plugins: [
remarkLintRulesLintRecommended,
remarkPresentLintMarkdownStyleGuide,
[remarkLintFinalDefinition, false],
[remarkLintListItemSpacing, false],
[remarkLintFileExtension, ["mdx"]],
[remarkLintNoUnusedDefinitions, false],
[remarkLintMaximumLineLength, false],
[remarkLintListItemIndent, false],
[remarkLintOrderedListMarkerValue, false],
[remarkLintFencedCodeFlag, false],
[remarkLintNoFileNameIrregularCharacters, false],
[remarkLintNoFileNameMixedCase, false],
[remarkLintMaximumHeadingLength, false],
[remarkLintNoDuplicateHeadings, false],
[remarkLintHeadingIncrement, false],
[remarkLintNoDuplicateDefinitions, false],
[remarkLintUnorderedListMarkerStyle, "*"],
],
};
/** @type {Preset} */
const config = {
plugins: [[remarkFrontmatter, ["yaml"]], remarkLintRules],
};
export default config;

View File

@@ -30,6 +30,6 @@
"types": ["unplugin-icons/types/astro"],
},
"include": [".astro/types.d.ts", "**/*"],
"include": [".astro/types.d.ts", "**/*", "src/.remarkrc.js"],
"exclude": ["dist"],
}