@mui/internal-code-infra 0.0.4-canary.9 → 0.0.4-canary.91
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +19 -8
- package/build/babel-config.d.mts +5 -1
- package/build/brokenLinksChecker/crawlWorker.d.mts +1 -0
- package/build/brokenLinksChecker/index.d.mts +45 -2
- package/build/changelog/types.d.ts +3 -1
- package/build/cli/cmdArgosPush.d.mts +2 -2
- package/build/cli/cmdBuild.d.mts +3 -2
- package/build/cli/cmdCopyFiles.d.mts +2 -2
- package/build/cli/cmdExtractErrorCodes.d.mts +2 -2
- package/build/cli/cmdGenerateChangelog.d.mts +2 -2
- package/build/cli/cmdGithubAuth.d.mts +2 -2
- package/build/cli/cmdListWorkspaces.d.mts +6 -4
- package/build/cli/cmdNetlifyIgnore.d.mts +3 -2
- package/build/cli/cmdPublish.d.mts +4 -2
- package/build/cli/cmdPublishCanary.d.mts +3 -3
- package/build/cli/cmdPublishNewPackage.d.mts +4 -2
- package/build/cli/cmdSetVersionOverrides.d.mts +2 -2
- package/build/cli/cmdVale.d.mts +46 -0
- package/build/cli/cmdValidateBuiltTypes.d.mts +2 -2
- package/build/eslint/baseConfig.d.mts +3 -1
- package/build/eslint/mui/rules/disallow-react-api-in-server-components.d.mts +2 -2
- package/build/eslint/mui/rules/docgen-ignore-before-comment.d.mts +2 -2
- package/build/eslint/mui/rules/no-floating-cleanup.d.mts +5 -0
- package/build/eslint/mui/rules/no-guarded-throw.d.mts +31 -0
- package/build/eslint/mui/rules/no-presentation-role.d.mts +5 -0
- package/build/eslint/mui/rules/no-restricted-resolved-imports.d.mts +2 -2
- package/build/eslint/mui/rules/nodeEnvUtils.d.mts +18 -0
- package/build/remark/config.d.mts +43 -0
- package/build/remark/createLintTester.d.mts +10 -0
- package/build/remark/firstBlockHeading.d.mts +4 -0
- package/build/remark/gitDiff.d.mts +2 -0
- package/build/remark/noSpaceInLinks.d.mts +2 -0
- package/build/remark/straightQuotes.d.mts +2 -0
- package/build/remark/tableAlignment.d.mts +2 -0
- package/build/remark/terminalLanguage.d.mts +2 -0
- package/build/utils/babel.d.mts +1 -1
- package/build/utils/build.d.mts +56 -37
- package/build/utils/git.d.mts +7 -0
- package/build/utils/github.d.mts +1 -1
- package/build/utils/pnpm.d.mts +81 -2
- package/build/utils/testUtils.d.mts +7 -0
- package/build/utils/typescript.d.mts +6 -16
- package/package.json +74 -50
- package/src/babel-config.mjs +3 -1
- package/src/brokenLinksChecker/crawlWorker.mjs +240 -0
- package/src/brokenLinksChecker/index.mjs +263 -188
- package/src/changelog/fetchChangelogs.mjs +8 -2
- package/src/changelog/renderChangelog.mjs +1 -1
- package/src/changelog/types.ts +3 -1
- package/src/cli/cmdBuild.mjs +51 -85
- package/src/cli/cmdListWorkspaces.mjs +12 -27
- package/src/cli/cmdNetlifyIgnore.mjs +34 -93
- package/src/cli/cmdPublish.mjs +95 -20
- package/src/cli/cmdPublishCanary.mjs +128 -132
- package/src/cli/cmdPublishNewPackage.mjs +27 -6
- package/src/cli/cmdSetVersionOverrides.mjs +8 -9
- package/src/cli/cmdVale.mjs +513 -0
- package/src/cli/index.mjs +2 -0
- package/src/cli/packageJson.d.ts +2 -3
- package/src/eslint/baseConfig.mjs +51 -19
- package/src/eslint/docsConfig.mjs +2 -1
- package/src/eslint/mui/config.mjs +24 -4
- package/src/eslint/mui/index.mjs +6 -0
- package/src/eslint/mui/rules/no-floating-cleanup.mjs +187 -0
- package/src/eslint/mui/rules/no-guarded-throw.mjs +115 -0
- package/src/eslint/mui/rules/no-presentation-role.mjs +60 -0
- package/src/eslint/mui/rules/nodeEnvUtils.mjs +52 -0
- package/src/eslint/mui/rules/require-dev-wrapper.mjs +25 -40
- package/src/estree-typescript.d.ts +1 -1
- package/src/remark/config.mjs +157 -0
- package/src/remark/createLintTester.mjs +19 -0
- package/src/remark/firstBlockHeading.mjs +87 -0
- package/src/remark/gitDiff.mjs +43 -0
- package/src/remark/noSpaceInLinks.mjs +42 -0
- package/src/remark/straightQuotes.mjs +31 -0
- package/src/remark/tableAlignment.mjs +23 -0
- package/src/remark/terminalLanguage.mjs +19 -0
- package/src/untyped-plugins.d.ts +11 -11
- package/src/utils/build.mjs +604 -270
- package/src/utils/git.mjs +27 -7
- package/src/utils/pnpm.mjs +277 -10
- package/src/utils/testUtils.mjs +18 -0
- package/src/utils/typescript.mjs +23 -42
- package/vale/.vale.ini +1 -0
- package/vale/styles/MUI/CorrectReferenceAllCases.yml +42 -0
- package/vale/styles/MUI/CorrectRererenceCased.yml +14 -0
- package/vale/styles/MUI/GoogleLatin.yml +11 -0
- package/vale/styles/MUI/MuiBrandName.yml +22 -0
- package/vale/styles/MUI/NoBritish.yml +112 -0
- package/vale/styles/MUI/NoCompanyName.yml +17 -0
- package/build/markdownlint/duplicate-h1.d.mts +0 -56
- package/build/markdownlint/git-diff.d.mts +0 -11
- package/build/markdownlint/index.d.mts +0 -52
- package/build/markdownlint/straight-quotes.d.mts +0 -11
- package/build/markdownlint/table-alignment.d.mts +0 -11
- package/build/markdownlint/terminal-language.d.mts +0 -11
- package/src/brokenLinksChecker/__fixtures__/static-site/broken-links.html +0 -20
- package/src/brokenLinksChecker/__fixtures__/static-site/broken-targets.html +0 -22
- package/src/brokenLinksChecker/__fixtures__/static-site/example.md +0 -20
- package/src/brokenLinksChecker/__fixtures__/static-site/external-links.html +0 -21
- package/src/brokenLinksChecker/__fixtures__/static-site/ignored-page.html +0 -17
- package/src/brokenLinksChecker/__fixtures__/static-site/index.html +0 -28
- package/src/brokenLinksChecker/__fixtures__/static-site/known-targets.json +0 -5
- package/src/brokenLinksChecker/__fixtures__/static-site/nested/page.html +0 -21
- package/src/brokenLinksChecker/__fixtures__/static-site/orphaned-page.html +0 -20
- package/src/brokenLinksChecker/__fixtures__/static-site/page-with-api-links.html +0 -20
- package/src/brokenLinksChecker/__fixtures__/static-site/page-with-custom-targets.html +0 -24
- package/src/brokenLinksChecker/__fixtures__/static-site/page-with-ignored-content.html +0 -28
- package/src/brokenLinksChecker/__fixtures__/static-site/page-with-known-target-links.html +0 -19
- package/src/brokenLinksChecker/__fixtures__/static-site/unclosed-tags.html +0 -1
- package/src/brokenLinksChecker/__fixtures__/static-site/valid.html +0 -20
- package/src/brokenLinksChecker/__fixtures__/static-site/with-anchors.html +0 -31
- package/src/brokenLinksChecker/index.test.ts +0 -261
- package/src/changelog/categorizeCommits.test.ts +0 -319
- package/src/changelog/filterCommits.test.ts +0 -363
- package/src/changelog/parseCommitLabels.test.ts +0 -509
- package/src/changelog/renderChangelog.test.ts +0 -378
- package/src/changelog/sortSections.test.ts +0 -199
- package/src/eslint/mui/rules/add-undef-to-optional.test.mjs +0 -361
- package/src/eslint/mui/rules/consistent-production-guard.test.mjs +0 -162
- package/src/eslint/mui/rules/disallow-active-elements-as-key-event-target.test.mjs +0 -66
- package/src/eslint/mui/rules/disallow-react-api-in-server-components.test.mjs +0 -305
- package/src/eslint/mui/rules/docgen-ignore-before-comment.test.mjs +0 -52
- package/src/eslint/mui/rules/flatten-parentheses.test.mjs +0 -245
- package/src/eslint/mui/rules/mui-name-matches-component-name.test.mjs +0 -247
- package/src/eslint/mui/rules/no-empty-box.test.mjs +0 -40
- package/src/eslint/mui/rules/no-styled-box.test.mjs +0 -73
- package/src/eslint/mui/rules/require-dev-wrapper.test.mjs +0 -265
- package/src/eslint/mui/rules/rules-of-use-theme-variants.test.mjs +0 -149
- package/src/eslint/mui/rules/straight-quotes.test.mjs +0 -67
- package/src/markdownlint/duplicate-h1.mjs +0 -69
- package/src/markdownlint/git-diff.mjs +0 -31
- package/src/markdownlint/index.mjs +0 -62
- package/src/markdownlint/straight-quotes.mjs +0 -26
- package/src/markdownlint/table-alignment.mjs +0 -42
- package/src/markdownlint/terminal-language.mjs +0 -19
- package/src/utils/build.test.mjs +0 -705
- package/src/utils/template.test.mjs +0 -133
- package/src/utils/typescript.test.mjs +0 -380
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
import { minimatch } from 'minimatch';
|
|
3
|
+
import { unified } from 'unified';
|
|
4
|
+
import remarkFrontmatter from 'remark-frontmatter';
|
|
5
|
+
import remarkGfm from 'remark-gfm';
|
|
6
|
+
import remarkLint from 'remark-lint';
|
|
7
|
+
import remarkLintCodeBlockStyle from 'remark-lint-code-block-style';
|
|
8
|
+
import remarkLintFencedCodeFlag from 'remark-lint-fenced-code-flag';
|
|
9
|
+
import remarkLintHeadingIncrement from 'remark-lint-heading-increment';
|
|
10
|
+
import remarkLintHeadingStyle from 'remark-lint-heading-style';
|
|
11
|
+
import remarkLintNoDuplicateHeadings from 'remark-lint-no-duplicate-headings';
|
|
12
|
+
import remarkLintNoEmptyUrl from 'remark-lint-no-empty-url';
|
|
13
|
+
import remarkLintNoHeadingPunctuation from 'remark-lint-no-heading-punctuation';
|
|
14
|
+
import remarkLintNoMultipleToplevelHeadings from 'remark-lint-no-multiple-toplevel-headings';
|
|
15
|
+
import remarkLintNoUndefinedReferences from 'remark-lint-no-undefined-references';
|
|
16
|
+
import remarkLintNoUnusedDefinitions from 'remark-lint-no-unused-definitions';
|
|
17
|
+
import remarkLintTablePipes from 'remark-lint-table-pipes';
|
|
18
|
+
import muiFirstBlockHeading from './firstBlockHeading.mjs';
|
|
19
|
+
import muiGitDiff from './gitDiff.mjs';
|
|
20
|
+
import muiNoSpaceInLinks from './noSpaceInLinks.mjs';
|
|
21
|
+
import muiStraightQuotes from './straightQuotes.mjs';
|
|
22
|
+
import muiTableAlignment from './tableAlignment.mjs';
|
|
23
|
+
import muiTerminalLanguage from './terminalLanguage.mjs';
|
|
24
|
+
|
|
25
|
+
const GITHUB_ALERT_LABELS = ['!NOTE', '!TIP', '!WARNING', '!IMPORTANT', '!CAUTION'];
|
|
26
|
+
|
|
27
|
+
const RULES = {
|
|
28
|
+
'no-duplicate-headings': [remarkLintNoDuplicateHeadings, ['error']],
|
|
29
|
+
'no-multiple-toplevel-headings': [remarkLintNoMultipleToplevelHeadings, ['error']],
|
|
30
|
+
'no-undefined-references': [
|
|
31
|
+
remarkLintNoUndefinedReferences,
|
|
32
|
+
['error', { allow: GITHUB_ALERT_LABELS, allowShortcutLink: true }],
|
|
33
|
+
],
|
|
34
|
+
'no-unused-definitions': [remarkLintNoUnusedDefinitions, ['error']],
|
|
35
|
+
'heading-style': [remarkLintHeadingStyle, ['error', 'atx']],
|
|
36
|
+
'heading-increment': [remarkLintHeadingIncrement, ['error']],
|
|
37
|
+
'no-heading-punctuation': [remarkLintNoHeadingPunctuation, ['error', '.,;:!']],
|
|
38
|
+
'code-block-style': [remarkLintCodeBlockStyle, ['error', 'fenced']],
|
|
39
|
+
'fenced-code-flag': [remarkLintFencedCodeFlag, ['error']],
|
|
40
|
+
'no-empty-url': [remarkLintNoEmptyUrl, ['error']],
|
|
41
|
+
'table-pipes': [remarkLintTablePipes, ['error']],
|
|
42
|
+
'mui-first-block-heading': [muiFirstBlockHeading, ['error']],
|
|
43
|
+
'mui-git-diff': [muiGitDiff, ['error']],
|
|
44
|
+
'mui-no-space-in-links': [muiNoSpaceInLinks, ['error']],
|
|
45
|
+
'mui-straight-quotes': [muiStraightQuotes, ['error']],
|
|
46
|
+
'mui-table-alignment': [muiTableAlignment, ['error']],
|
|
47
|
+
'mui-terminal-language': [muiTerminalLanguage, ['error']],
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {string | undefined} filePath
|
|
52
|
+
*/
|
|
53
|
+
function relativePath(filePath) {
|
|
54
|
+
if (!filePath) {
|
|
55
|
+
return filePath;
|
|
56
|
+
}
|
|
57
|
+
if (path.isAbsolute(filePath)) {
|
|
58
|
+
return path.relative(process.cwd(), filePath);
|
|
59
|
+
}
|
|
60
|
+
return filePath;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Wraps a remark-lint plugin so its transformer dispatches at runtime based on
|
|
65
|
+
* `file.path`. Each variant (base + per-override) runs through its own mini
|
|
66
|
+
* unified pipeline so severity, baked in by `unified-lint-rule` at attach time,
|
|
67
|
+
* is preserved correctly.
|
|
68
|
+
*
|
|
69
|
+
* @param {string} name
|
|
70
|
+
* @param {import('unified').Plugin<any[], any, any>} plugin
|
|
71
|
+
* @param {any} baseSettings
|
|
72
|
+
* @param {Array<{ files: string | string[], settings: false | any }>} overrideEntries
|
|
73
|
+
*/
|
|
74
|
+
function withOverrides(name, plugin, baseSettings, overrideEntries) {
|
|
75
|
+
const baseProcessor = unified().use(plugin, baseSettings);
|
|
76
|
+
const variants = overrideEntries.map(({ files, settings }) => ({
|
|
77
|
+
files: Array.isArray(files) ? files : [files],
|
|
78
|
+
processor: settings === false ? null : unified().use(plugin, settings),
|
|
79
|
+
}));
|
|
80
|
+
function wrapper() {
|
|
81
|
+
/** @type {import('unified').Transformer} */
|
|
82
|
+
return async function transformer(tree, file) {
|
|
83
|
+
const candidate = relativePath(file.path);
|
|
84
|
+
const matched = candidate
|
|
85
|
+
? variants.find((variant) => variant.files.some((pattern) => minimatch(candidate, pattern)))
|
|
86
|
+
: undefined;
|
|
87
|
+
if (matched) {
|
|
88
|
+
if (matched.processor) {
|
|
89
|
+
await matched.processor.run(tree, file);
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
await baseProcessor.run(tree, file);
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
Object.defineProperty(wrapper, 'name', { value: `mui-remark-overrides(${name})` });
|
|
97
|
+
return wrapper;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Returns a remark preset wiring the MUI-authored remark-lint plugins together
|
|
102
|
+
* with a curated set of community plugins. Drop this into `.remarkrc.mjs`:
|
|
103
|
+
*
|
|
104
|
+
* ```js
|
|
105
|
+
* import { createRemarkConfig } from '@mui/internal-code-infra/remark';
|
|
106
|
+
* export default createRemarkConfig();
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* Pass `overrides` to scope rule changes to a glob. Each entry's `rules` map
|
|
110
|
+
* is keyed by the rule name (the key used in `RULES`); `false` disables the
|
|
111
|
+
* rule for matching files, a settings tuple replaces its severity/options:
|
|
112
|
+
*
|
|
113
|
+
* ```js
|
|
114
|
+
* createRemarkConfig({
|
|
115
|
+
* overrides: [
|
|
116
|
+
* { files: 'docs/special/**', rules: { 'mui-no-space-in-links': false } },
|
|
117
|
+
* { files: '**\/CHANGELOG.md', rules: { 'heading-style': ['warn', 'atx'] } },
|
|
118
|
+
* ],
|
|
119
|
+
* });
|
|
120
|
+
* ```
|
|
121
|
+
*
|
|
122
|
+
* @param {Object} [options]
|
|
123
|
+
* @param {Array<{ files: string | string[], rules: Record<string, false | unknown[]> }>} [options.overrides]
|
|
124
|
+
*/
|
|
125
|
+
export function createRemarkConfig({ overrides = [] } = {}) {
|
|
126
|
+
for (const override of overrides) {
|
|
127
|
+
const unknown = Object.keys(override.rules).filter((ruleName) => !(ruleName in RULES));
|
|
128
|
+
if (unknown.length > 0) {
|
|
129
|
+
throw new Error(`Unknown remark-lint rule name(s): ${unknown.join(', ')}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const entries = Object.entries(RULES).map(([name, entry]) => {
|
|
134
|
+
const [plugin, baseSettings] = /** @type {[import('unified').Plugin<any[], any, any>, any]} */ (
|
|
135
|
+
entry
|
|
136
|
+
);
|
|
137
|
+
const overrideEntries = overrides
|
|
138
|
+
.filter((override) => name in override.rules)
|
|
139
|
+
.map((override) => ({ files: override.files, settings: override.rules[name] }));
|
|
140
|
+
if (overrideEntries.length === 0) {
|
|
141
|
+
return [plugin, baseSettings];
|
|
142
|
+
}
|
|
143
|
+
return [withOverrides(name, plugin, baseSettings, overrideEntries)];
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
settings: {
|
|
148
|
+
bullet: '-',
|
|
149
|
+
emphasis: '_',
|
|
150
|
+
fence: '`',
|
|
151
|
+
listItemIndent: 'one',
|
|
152
|
+
resourceLink: true,
|
|
153
|
+
rule: '-',
|
|
154
|
+
},
|
|
155
|
+
plugins: [[remarkFrontmatter, ['yaml', 'toml']], remarkGfm, remarkLint, ...entries],
|
|
156
|
+
};
|
|
157
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { remark } from 'remark';
|
|
2
|
+
import remarkGfm from 'remark-gfm';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {unknown} plugin
|
|
6
|
+
* @param {unknown} [options]
|
|
7
|
+
* @returns {(input: string) => Array<{ reason: string, line: number, column: number }>}
|
|
8
|
+
*/
|
|
9
|
+
export function createLintTester(plugin, options) {
|
|
10
|
+
const entry = /** @type {any} */ (options === undefined ? plugin : [plugin, options]);
|
|
11
|
+
return function lint(input) {
|
|
12
|
+
const file = remark().use(remarkGfm).use(entry).processSync(input);
|
|
13
|
+
return file.messages.map((message) => ({
|
|
14
|
+
reason: message.reason,
|
|
15
|
+
line: message.line ?? 0,
|
|
16
|
+
column: message.column ?? 0,
|
|
17
|
+
}));
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { lintRule } from 'unified-lint-rule';
|
|
2
|
+
|
|
3
|
+
const FRONTMATTER_TYPES = new Set(['yaml', 'toml']);
|
|
4
|
+
const INVISIBLE_TAGS = new Set(['style', 'script']);
|
|
5
|
+
const DEFAULT_FRONT_MATTER_TITLE = /^\s*"?title"?\s*[:=]/m;
|
|
6
|
+
|
|
7
|
+
/** @param {import('mdast').RootContent} node */
|
|
8
|
+
const isSkippable = (node) => {
|
|
9
|
+
const type = /** @type {string} */ (node.type);
|
|
10
|
+
if (FRONTMATTER_TYPES.has(type)) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
if (type === 'html') {
|
|
14
|
+
const value = /** @type {{ value: string }} */ (/** @type {unknown} */ (node)).value.trim();
|
|
15
|
+
if (value.startsWith('<!--')) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
const match = value.match(/^<\s*([a-zA-Z][a-zA-Z0-9-]*)/);
|
|
19
|
+
if (match && INVISIBLE_TAGS.has(match[1].toLowerCase())) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (type === 'mdxJsxFlowElement') {
|
|
24
|
+
const name = /** @type {{ name: string | null }} */ (/** @type {unknown} */ (node)).name;
|
|
25
|
+
if (name && INVISIBLE_TAGS.has(name.toLowerCase())) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (type === 'mdxjsEsm') {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
if (type === 'mdxFlowExpression') {
|
|
33
|
+
const value = /** @type {{ value: string }} */ (/** @type {unknown} */ (node)).value.trim();
|
|
34
|
+
if (
|
|
35
|
+
value === '' ||
|
|
36
|
+
(value.startsWith('/*') && value.endsWith('*/')) ||
|
|
37
|
+
value.startsWith('//')
|
|
38
|
+
) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @param {import('mdast').Root} tree
|
|
47
|
+
* @param {RegExp | false} pattern
|
|
48
|
+
*/
|
|
49
|
+
const hasFrontMatterTitle = (tree, pattern) => {
|
|
50
|
+
if (!pattern) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
const frontMatter = tree.children.find((child) => FRONTMATTER_TYPES.has(child.type));
|
|
54
|
+
if (!frontMatter) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
return pattern.test(
|
|
58
|
+
/** @type {{ value: string }} */ (/** @type {unknown} */ (frontMatter)).value,
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const remarkLintMuiFirstBlockHeading = lintRule(
|
|
63
|
+
{
|
|
64
|
+
origin: 'remark-lint:mui-first-block-heading',
|
|
65
|
+
url: 'https://github.com/mui/mui-public',
|
|
66
|
+
},
|
|
67
|
+
/** @type {import('unified-lint-rule').Rule<import('mdast').Root, { frontMatterTitle?: RegExp | false } | undefined>} */
|
|
68
|
+
(tree, file, options) => {
|
|
69
|
+
const frontMatterTitle =
|
|
70
|
+
options?.frontMatterTitle === undefined
|
|
71
|
+
? DEFAULT_FRONT_MATTER_TITLE
|
|
72
|
+
: options.frontMatterTitle;
|
|
73
|
+
if (hasFrontMatterTitle(tree, frontMatterTitle)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const firstBlock = tree.children.find((child) => !isSkippable(child));
|
|
77
|
+
if (!firstBlock) {
|
|
78
|
+
file.message('Documents must begin with a top-level heading.');
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (firstBlock.type !== 'heading' || firstBlock.depth !== 1) {
|
|
82
|
+
file.message('Documents must begin with a top-level heading.', firstBlock);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
export default remarkLintMuiFirstBlockHeading;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { lintRule } from 'unified-lint-rule';
|
|
2
|
+
import { visit } from 'unist-util-visit';
|
|
3
|
+
|
|
4
|
+
const singleCharPrefixes = new Set([' ', '-', '+']);
|
|
5
|
+
const linePrefixes = ['@@ ', 'diff --git ', 'index '];
|
|
6
|
+
|
|
7
|
+
const remarkLintMuiGitDiff = lintRule(
|
|
8
|
+
{
|
|
9
|
+
origin: 'remark-lint:mui-git-diff',
|
|
10
|
+
url: 'https://github.com/mui/mui-public',
|
|
11
|
+
},
|
|
12
|
+
/** @param {import('mdast').Root} tree */
|
|
13
|
+
(tree, file) => {
|
|
14
|
+
visit(tree, 'code', (node) => {
|
|
15
|
+
if (node.lang !== 'diff' || !node.position) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const contentStartLine = node.position.start.line + 1;
|
|
19
|
+
const lines = node.value.split('\n');
|
|
20
|
+
lines.forEach((line, index) => {
|
|
21
|
+
if (line === '') {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (singleCharPrefixes.has(line[0])) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (linePrefixes.some((prefix) => line.startsWith(prefix))) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const lineNumber = contentStartLine + index;
|
|
31
|
+
file.message(
|
|
32
|
+
'Line in a `diff` code block must start with " ", "+", "-", "@@ ", "diff --git ", or "index ".',
|
|
33
|
+
{
|
|
34
|
+
start: { line: lineNumber, column: 1 },
|
|
35
|
+
end: { line: lineNumber, column: line.length + 1 },
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
export default remarkLintMuiGitDiff;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { lintRule } from 'unified-lint-rule';
|
|
2
|
+
import { visit } from 'unist-util-visit';
|
|
3
|
+
|
|
4
|
+
const remarkLintMuiNoSpaceInLinks = lintRule(
|
|
5
|
+
{
|
|
6
|
+
origin: 'remark-lint:mui-no-space-in-links',
|
|
7
|
+
url: 'https://github.com/mui/mui-public',
|
|
8
|
+
},
|
|
9
|
+
/** @param {import('mdast').Root} tree */
|
|
10
|
+
(tree, file) => {
|
|
11
|
+
const source = String(file.value);
|
|
12
|
+
visit(tree, 'link', (node) => {
|
|
13
|
+
if (!node.position || node.children.length === 0) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const first = node.children[0];
|
|
17
|
+
const last = node.children[node.children.length - 1];
|
|
18
|
+
if (!first.position || !last.position) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const textStart = first.position.start.offset;
|
|
22
|
+
const textEnd = last.position.end.offset;
|
|
23
|
+
if (textStart === undefined || textEnd === undefined) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const openBracket = source.lastIndexOf('[', textStart);
|
|
27
|
+
const closeBracket = source.indexOf(']', textEnd);
|
|
28
|
+
if (openBracket === -1 || closeBracket === -1) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const innerText = source.slice(openBracket + 1, closeBracket);
|
|
32
|
+
if (innerText.length === 0) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (innerText !== innerText.trim()) {
|
|
36
|
+
file.message('Link text should not start or end with whitespace.', node);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
export default remarkLintMuiNoSpaceInLinks;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { lintRule } from 'unified-lint-rule';
|
|
2
|
+
|
|
3
|
+
const curlyQuotes = new Set(['‘', '’', '“', '”']);
|
|
4
|
+
|
|
5
|
+
const remarkLintMuiStraightQuotes = lintRule(
|
|
6
|
+
{
|
|
7
|
+
origin: 'remark-lint:mui-straight-quotes',
|
|
8
|
+
url: 'https://github.com/mui/mui-public',
|
|
9
|
+
},
|
|
10
|
+
/** @param {import('mdast').Root} _tree */
|
|
11
|
+
(_tree, file) => {
|
|
12
|
+
const text = String(file.value);
|
|
13
|
+
let line = 1;
|
|
14
|
+
let lineStart = 0;
|
|
15
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
16
|
+
const char = text[index];
|
|
17
|
+
if (char === '\n') {
|
|
18
|
+
line += 1;
|
|
19
|
+
lineStart = index + 1;
|
|
20
|
+
} else if (curlyQuotes.has(char)) {
|
|
21
|
+
const column = index - lineStart + 1;
|
|
22
|
+
file.message('Use straight quotes instead of curly quotes.', {
|
|
23
|
+
start: { line, column },
|
|
24
|
+
end: { line, column: column + 1 },
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export default remarkLintMuiStraightQuotes;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { lintRule } from 'unified-lint-rule';
|
|
2
|
+
import { visit } from 'unist-util-visit';
|
|
3
|
+
|
|
4
|
+
const remarkLintMuiTableAlignment = lintRule(
|
|
5
|
+
{
|
|
6
|
+
origin: 'remark-lint:mui-table-alignment',
|
|
7
|
+
url: 'https://github.com/mui/mui-public',
|
|
8
|
+
},
|
|
9
|
+
/** @param {import('mdast').Root} tree */
|
|
10
|
+
(tree, file) => {
|
|
11
|
+
visit(tree, 'table', (node) => {
|
|
12
|
+
const align = node.align ?? [];
|
|
13
|
+
if (align.some((value) => value == null)) {
|
|
14
|
+
file.message(
|
|
15
|
+
'Table columns should declare an explicit alignment (`:---`, `---:`, or `:---:`).',
|
|
16
|
+
node,
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
},
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export default remarkLintMuiTableAlignment;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { lintRule } from 'unified-lint-rule';
|
|
2
|
+
import { visit } from 'unist-util-visit';
|
|
3
|
+
|
|
4
|
+
const remarkLintMuiTerminalLanguage = lintRule(
|
|
5
|
+
{
|
|
6
|
+
origin: 'remark-lint:mui-terminal-language',
|
|
7
|
+
url: 'https://github.com/mui/mui-public',
|
|
8
|
+
},
|
|
9
|
+
/** @param {import('mdast').Root} tree */
|
|
10
|
+
(tree, file) => {
|
|
11
|
+
visit(tree, 'code', (node) => {
|
|
12
|
+
if (node.lang === 'sh' && node.position) {
|
|
13
|
+
file.message('Use `bash` instead of `sh` as the code block language.', node);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export default remarkLintMuiTerminalLanguage;
|
package/src/untyped-plugins.d.ts
CHANGED
|
@@ -13,77 +13,77 @@ declare module 'eslint-config-airbnb' {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
declare module 'eslint-config-airbnb-base/rules/best-practices' {
|
|
16
|
-
import { Linter } from 'eslint';
|
|
16
|
+
import type { Linter } from 'eslint';
|
|
17
17
|
|
|
18
18
|
declare const config: Omit<Linter.LegacyConfig, 'extends' | 'plugins'>;
|
|
19
19
|
export default config;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
declare module 'eslint-config-airbnb-base/rules/errors' {
|
|
23
|
-
import { Linter } from 'eslint';
|
|
23
|
+
import type { Linter } from 'eslint';
|
|
24
24
|
|
|
25
25
|
declare const config: Omit<Linter.LegacyConfig, 'extends' | 'plugins'>;
|
|
26
26
|
export default config;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
declare module 'eslint-config-airbnb-base/rules/es6' {
|
|
30
|
-
import { Linter } from 'eslint';
|
|
30
|
+
import type { Linter } from 'eslint';
|
|
31
31
|
|
|
32
32
|
declare const config: Omit<Linter.LegacyConfig, 'extends' | 'plugins'>;
|
|
33
33
|
export default config;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
declare module 'eslint-config-airbnb-base/rules/imports' {
|
|
37
|
-
import { Linter } from 'eslint';
|
|
37
|
+
import type { Linter } from 'eslint';
|
|
38
38
|
|
|
39
39
|
declare const config: Omit<Linter.LegacyConfig, 'extends' | 'plugins'>;
|
|
40
40
|
export default config;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
declare module 'eslint-config-airbnb-base/rules/node' {
|
|
44
|
-
import { Linter } from 'eslint';
|
|
44
|
+
import type { Linter } from 'eslint';
|
|
45
45
|
|
|
46
46
|
declare const config: Omit<Linter.LegacyConfig, 'extends' | 'plugins'>;
|
|
47
47
|
export default config;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
declare module 'eslint-config-airbnb-base/rules/strict' {
|
|
51
|
-
import { Linter } from 'eslint';
|
|
51
|
+
import type { Linter } from 'eslint';
|
|
52
52
|
|
|
53
53
|
declare const config: Omit<Linter.LegacyConfig, 'extends' | 'plugins'>;
|
|
54
54
|
export default config;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
declare module 'eslint-config-airbnb-base/rules/style' {
|
|
58
|
-
import { Linter } from 'eslint';
|
|
58
|
+
import type { Linter } from 'eslint';
|
|
59
59
|
|
|
60
60
|
declare const config: Omit<Linter.LegacyConfig, 'extends' | 'plugins'>;
|
|
61
61
|
export default config;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
declare module 'eslint-config-airbnb-base/rules/variables' {
|
|
65
|
-
import { Linter } from 'eslint';
|
|
65
|
+
import type { Linter } from 'eslint';
|
|
66
66
|
|
|
67
67
|
declare const config: Omit<Linter.LegacyConfig, 'extends' | 'plugins'>;
|
|
68
68
|
export default config;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
declare module 'eslint-config-airbnb/rules/react' {
|
|
72
|
-
import { Linter } from 'eslint';
|
|
72
|
+
import type { Linter } from 'eslint';
|
|
73
73
|
|
|
74
74
|
declare const config: Omit<Linter.LegacyConfig, 'extends' | 'plugins'>;
|
|
75
75
|
export default config;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
declare module 'eslint-config-airbnb/rules/react-a11y' {
|
|
79
|
-
import { Linter } from 'eslint';
|
|
79
|
+
import type { Linter } from 'eslint';
|
|
80
80
|
|
|
81
81
|
declare const config: Omit<Linter.LegacyConfig, 'extends' | 'plugins'>;
|
|
82
82
|
export default config;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
declare module '@next/eslint-plugin-next' {
|
|
86
|
-
import { Linter } from 'eslint';
|
|
86
|
+
import type { Linter } from 'eslint';
|
|
87
87
|
|
|
88
88
|
interface NextEslintPluginConfig extends Linter.LegacyConfig {
|
|
89
89
|
flatConfig: {
|