@mui/internal-code-infra 0.0.3-canary.1 → 0.0.3-canary.3
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/package.json +5 -4
- package/src/markdownlint/duplicate-h1.mjs +69 -0
- package/src/markdownlint/git-diff.mjs +31 -0
- package/src/markdownlint/index.mjs +62 -0
- package/src/markdownlint/straight-quotes.mjs +26 -0
- package/src/markdownlint/table-alignment.mjs +42 -0
- package/src/markdownlint/terminal-language.mjs +19 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/internal-code-infra",
|
|
3
|
-
"version": "0.0.3-canary.
|
|
3
|
+
"version": "0.0.3-canary.3",
|
|
4
4
|
"description": "Infra scripts and configs to be used across MUI repos.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
"./package.json": "./package.json",
|
|
15
15
|
"./prettier": "./src/prettier.mjs",
|
|
16
16
|
"./eslint": "./src/eslint/index.mjs",
|
|
17
|
-
"./babel-config": "./src/babel-config.mjs"
|
|
17
|
+
"./babel-config": "./src/babel-config.mjs",
|
|
18
|
+
"./markdownlint": "./src/markdownlint/index.mjs"
|
|
18
19
|
},
|
|
19
20
|
"bin": {
|
|
20
21
|
"code-infra": "./bin/code-infra.mjs"
|
|
@@ -58,8 +59,8 @@
|
|
|
58
59
|
"semver": "^7.7.2",
|
|
59
60
|
"typescript-eslint": "^8.40.0",
|
|
60
61
|
"yargs": "^18.0.0",
|
|
61
|
-
"@mui/internal-babel-plugin-minify-errors": "2.0.8-canary.7",
|
|
62
62
|
"@mui/internal-babel-plugin-display-name": "1.0.4-canary.6",
|
|
63
|
+
"@mui/internal-babel-plugin-minify-errors": "2.0.8-canary.8",
|
|
63
64
|
"@mui/internal-babel-plugin-resolve-imports": "2.0.7-canary.19"
|
|
64
65
|
},
|
|
65
66
|
"peerDependencies": {
|
|
@@ -91,7 +92,7 @@
|
|
|
91
92
|
"publishConfig": {
|
|
92
93
|
"access": "public"
|
|
93
94
|
},
|
|
94
|
-
"gitSha": "
|
|
95
|
+
"gitSha": "6a3e097acfa56e9838d2edb7f05755bda41f365d",
|
|
95
96
|
"scripts": {
|
|
96
97
|
"typescript": "tsc -p tsconfig.json",
|
|
97
98
|
"test": "pnpm -w test --project @mui/internal-code-infra",
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {[string, string]} Attr
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {Object} Token
|
|
7
|
+
* @property {string} type
|
|
8
|
+
* @property {string} info
|
|
9
|
+
* @property {string} tag
|
|
10
|
+
* @property {string} content
|
|
11
|
+
* @property {number} lineNumber
|
|
12
|
+
* @property {Attr[]} attrs
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {Object} OnErrorObj
|
|
17
|
+
* @property {number} lineNumber
|
|
18
|
+
* @property {string} [detail]
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {(err: OnErrorObj) => void} OnError
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @typedef {Object} MdParams
|
|
27
|
+
* @property {string} name
|
|
28
|
+
* @property {string[]} lines
|
|
29
|
+
* @property {Token[]} tokens
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
// This rule is an extension of MD025/no-multiple-top-level-headings.
|
|
33
|
+
// The rule is buggy https://github.com/DavidAnson/markdownlint/pull/1109
|
|
34
|
+
// but also blog headers don't tell you that h1 is already injected.
|
|
35
|
+
export default {
|
|
36
|
+
names: ['duplicateH1'],
|
|
37
|
+
description: 'Multiple top-level headings in the same document.',
|
|
38
|
+
tags: ['headings'],
|
|
39
|
+
/**
|
|
40
|
+
* @param {import('./duplicate-h1.mjs').MdParams} params
|
|
41
|
+
* @param {import('./duplicate-h1.mjs').OnError} onError
|
|
42
|
+
*/
|
|
43
|
+
function: (params, onError) => {
|
|
44
|
+
/**
|
|
45
|
+
* @type {number|boolean}
|
|
46
|
+
*/
|
|
47
|
+
let hasTopLevelHeading = false;
|
|
48
|
+
params.tokens.forEach((token) => {
|
|
49
|
+
if (token.type === 'heading_open' && token.tag === 'h1') {
|
|
50
|
+
// Avoid duplicate errors with MD025.
|
|
51
|
+
if (hasTopLevelHeading !== false && hasTopLevelHeading !== 1) {
|
|
52
|
+
onError({
|
|
53
|
+
lineNumber: token.lineNumber,
|
|
54
|
+
});
|
|
55
|
+
} else if (params.name.includes('/docs/pages/blog/')) {
|
|
56
|
+
onError({
|
|
57
|
+
lineNumber: token.lineNumber,
|
|
58
|
+
detail: 'In the blog, the h1 is already added using the markdown header.title value.',
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Store the first h1 of the page.
|
|
63
|
+
if (hasTopLevelHeading === false) {
|
|
64
|
+
hasTopLevelHeading = token.lineNumber;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
names: ['gitDiff'],
|
|
3
|
+
description: 'Respect the format output of git diff.',
|
|
4
|
+
tags: ['spaces'],
|
|
5
|
+
/**
|
|
6
|
+
* @param {import('./duplicate-h1.mjs').MdParams} params
|
|
7
|
+
* @param {import('./duplicate-h1.mjs').OnError} onError
|
|
8
|
+
*/
|
|
9
|
+
function: (params, onError) => {
|
|
10
|
+
params.tokens.forEach((token) => {
|
|
11
|
+
if (token.type === 'fence' && token.info === 'diff') {
|
|
12
|
+
token.content.split('\n').forEach((line, index) => {
|
|
13
|
+
if (
|
|
14
|
+
line[0] !== ' ' &&
|
|
15
|
+
line[0] !== '-' &&
|
|
16
|
+
line[0] !== '+' &&
|
|
17
|
+
line !== '' &&
|
|
18
|
+
line.indexOf('@@ ') !== 0 &&
|
|
19
|
+
line.indexOf('diff --git ') !== 0 &&
|
|
20
|
+
line.indexOf('index ') !== 0
|
|
21
|
+
) {
|
|
22
|
+
onError({
|
|
23
|
+
lineNumber: token.lineNumber + index + 1,
|
|
24
|
+
detail: `The line start with "+" or "-" or " ": ${line}`,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import straightQuotes from './straight-quotes.mjs';
|
|
2
|
+
import gitDiff from './git-diff.mjs';
|
|
3
|
+
import tableAlignment from './table-alignment.mjs';
|
|
4
|
+
import terminalLanguage from './terminal-language.mjs';
|
|
5
|
+
import duplicateH1 from './duplicate-h1.mjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Create a base configuration for markdownlint.
|
|
9
|
+
* @param {Object} options
|
|
10
|
+
* @param {(typeof straightQuotes)[]} [options.rules] - An array of custom rules to include.
|
|
11
|
+
* @param {string[]} [options.ignores] - An array of glob patterns to ignore.
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export function createBaseConfig(options = {}) {
|
|
15
|
+
const { rules = [], ignores = [] } = options;
|
|
16
|
+
// https://github.com/DavidAnson/markdownlint#rules--aliases
|
|
17
|
+
return {
|
|
18
|
+
config: {
|
|
19
|
+
default: true,
|
|
20
|
+
MD004: false, // MD004/ul-style. Buggy
|
|
21
|
+
MD009: {
|
|
22
|
+
// MD009/no-trailing-spaces
|
|
23
|
+
br_spaces: 0,
|
|
24
|
+
strict: true,
|
|
25
|
+
list_item_empty_lines: false,
|
|
26
|
+
},
|
|
27
|
+
MD013: false, // MD013/line-length. Already handled by Prettier.
|
|
28
|
+
MD014: false, // MD014/commands-show-output. It's OK.
|
|
29
|
+
MD024: { siblings_only: true }, // MD024/no-duplicate-heading/no-duplicate-header
|
|
30
|
+
MD025: {
|
|
31
|
+
// Heading level
|
|
32
|
+
level: 1,
|
|
33
|
+
// RegExp for matching title in front matter
|
|
34
|
+
front_matter_title: '',
|
|
35
|
+
},
|
|
36
|
+
MD033: false, // MD033/no-inline-html. We use it from time to time, it's fine.
|
|
37
|
+
MD034: false, // MD034/no-bare-urls. Not a concern for us, our Markdown interpreter supports it.
|
|
38
|
+
MD028: false, // MD028/no-blanks-blockquote prevent double blockquote
|
|
39
|
+
MD029: false, // MD029/ol-prefix. Buggy
|
|
40
|
+
MD031: false, // MD031/blanks-around-fences Some code blocks inside li
|
|
41
|
+
MD036: false, // MD036/no-emphasis-as-heading/no-emphasis-as-header. It's OK.
|
|
42
|
+
MD051: false, // MD051/link-fragments. Many false positives in the changelog.
|
|
43
|
+
MD052: false, // MD052/reference-links-images. Many false positives in the changelog.
|
|
44
|
+
MD059: false, // MD059/descriptive-link-text. Does not allow links on text like "link", whereas we redirect to "Link" component.
|
|
45
|
+
straightQuotes: true,
|
|
46
|
+
gitDiff: true,
|
|
47
|
+
tableAlignment: true,
|
|
48
|
+
terminalLanguage: true,
|
|
49
|
+
duplicateH1: true,
|
|
50
|
+
},
|
|
51
|
+
customRules: [straightQuotes, gitDiff, tableAlignment, terminalLanguage, duplicateH1, ...rules],
|
|
52
|
+
ignores: [
|
|
53
|
+
'CHANGELOG.old.md',
|
|
54
|
+
'**/node_modules/**',
|
|
55
|
+
'**/build/**',
|
|
56
|
+
'.github/PULL_REQUEST_TEMPLATE.md',
|
|
57
|
+
'docs/public/**',
|
|
58
|
+
'docs/export/**',
|
|
59
|
+
...ignores,
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const nonStraightQuotes = /[‘’“”]/;
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
names: ['straightQuotes'],
|
|
5
|
+
description: 'Only allow straight quotes.',
|
|
6
|
+
tags: ['spelling'],
|
|
7
|
+
/**
|
|
8
|
+
* @param {import('./duplicate-h1.mjs').MdParams} params
|
|
9
|
+
* @param {import('./duplicate-h1.mjs').OnError} onError
|
|
10
|
+
*/
|
|
11
|
+
function: (params, onError) => {
|
|
12
|
+
params.lines.forEach((line, lineNumber) => {
|
|
13
|
+
// It will match
|
|
14
|
+
// opening single quote: \xE2\x80\x98
|
|
15
|
+
// closing single quote: \xE2\x80\x99
|
|
16
|
+
// opening double quote: \xE2\x80\x9C
|
|
17
|
+
// closing double quote: \xE2\x80\x9D
|
|
18
|
+
if (nonStraightQuotes.test(line)) {
|
|
19
|
+
onError({
|
|
20
|
+
lineNumber: lineNumber + 1,
|
|
21
|
+
detail: `For line: ${line}`,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {import('./duplicate-h1.mjs').Attr[]} attrs
|
|
3
|
+
* @returns {Record<string, string>}
|
|
4
|
+
*/
|
|
5
|
+
function attr(attrs) {
|
|
6
|
+
return (attrs || []).reduce((acc, item) => ({ ...acc, [item[0]]: item[1] }), {});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
names: ['tableAlignment'],
|
|
11
|
+
description: 'Set table alignment.',
|
|
12
|
+
tags: ['table'],
|
|
13
|
+
/**
|
|
14
|
+
* @param {import('./duplicate-h1.mjs').MdParams} params
|
|
15
|
+
* @param {import('./duplicate-h1.mjs').OnError} onError
|
|
16
|
+
*/
|
|
17
|
+
function: (params, onError) => {
|
|
18
|
+
params.tokens.forEach((token) => {
|
|
19
|
+
// This is wrong:
|
|
20
|
+
// | Version | Supported |
|
|
21
|
+
// | ------- | ------------------ |
|
|
22
|
+
//
|
|
23
|
+
// The second column should be left aligned because it contains text:
|
|
24
|
+
// | Version | Supported |
|
|
25
|
+
// | ------- | :----------------- |
|
|
26
|
+
//
|
|
27
|
+
// However, columns that includes numbers should be right aligned:
|
|
28
|
+
// | Version | Supported |
|
|
29
|
+
// | ------: | :----------------- |
|
|
30
|
+
//
|
|
31
|
+
// More details: https://ux.stackexchange.com/questions/24066/what-is-the-best-practice-for-data-table-cell-content-alignment
|
|
32
|
+
//
|
|
33
|
+
// In this check we expect the style to be 'text-align:right' or equivalent.
|
|
34
|
+
if (token.type === 'th_open' && attr(token.attrs).style == null) {
|
|
35
|
+
onError({
|
|
36
|
+
lineNumber: token.lineNumber,
|
|
37
|
+
detail: `${params.lines[token.lineNumber - 1]}`,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
names: ['terminalLanguage'],
|
|
3
|
+
description: 'Set the right language for terminal code.',
|
|
4
|
+
tags: ['code'],
|
|
5
|
+
/**
|
|
6
|
+
* @param {import('./duplicate-h1.mjs').MdParams} params
|
|
7
|
+
* @param {import('./duplicate-h1.mjs').OnError} onError
|
|
8
|
+
*/
|
|
9
|
+
function: (params, onError) => {
|
|
10
|
+
params.tokens.forEach((token) => {
|
|
11
|
+
if (token.type === 'fence' && token.info === 'sh') {
|
|
12
|
+
onError({
|
|
13
|
+
lineNumber: token.lineNumber,
|
|
14
|
+
detail: `Use "bash" instead of "sh".`,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
};
|