@mui/internal-code-infra 0.0.4-canary.41 → 0.0.4-canary.42
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/internal-code-infra",
|
|
3
|
-
"version": "0.0.4-canary.
|
|
3
|
+
"version": "0.0.4-canary.42",
|
|
4
4
|
"author": "MUI Team",
|
|
5
5
|
"description": "Infra scripts and configs to be used across MUI repos.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -139,9 +139,9 @@
|
|
|
139
139
|
"unified-lint-rule": "^3.0.1",
|
|
140
140
|
"unist-util-visit": "^5.1.0",
|
|
141
141
|
"yargs": "^18.0.0",
|
|
142
|
+
"@mui/internal-babel-plugin-minify-errors": "2.0.8-canary.27",
|
|
142
143
|
"@mui/internal-babel-plugin-display-name": "1.0.4-canary.19",
|
|
143
|
-
"@mui/internal-babel-plugin-resolve-imports": "2.0.7-canary.36"
|
|
144
|
-
"@mui/internal-babel-plugin-minify-errors": "2.0.8-canary.27"
|
|
144
|
+
"@mui/internal-babel-plugin-resolve-imports": "2.0.7-canary.36"
|
|
145
145
|
},
|
|
146
146
|
"peerDependencies": {
|
|
147
147
|
"@next/eslint-plugin-next": "*",
|
|
@@ -191,7 +191,7 @@
|
|
|
191
191
|
"publishConfig": {
|
|
192
192
|
"access": "public"
|
|
193
193
|
},
|
|
194
|
-
"gitSha": "
|
|
194
|
+
"gitSha": "f2b7a9f6b2db57a03f2e16a5bb351f02a55c3e17",
|
|
195
195
|
"scripts": {
|
|
196
196
|
"build": "tsgo -p tsconfig.build.json",
|
|
197
197
|
"typescript": "tsgo -noEmit",
|
|
@@ -421,6 +421,7 @@ export function createCoreConfig(options = {}) {
|
|
|
421
421
|
'mui/consistent-production-guard': 'error',
|
|
422
422
|
'mui/add-undef-to-optional': 'off',
|
|
423
423
|
'mui/flatten-parentheses': 'warn',
|
|
424
|
+
'mui/no-presentation-role': 'off',
|
|
424
425
|
|
|
425
426
|
'react-hooks/exhaustive-deps': [
|
|
426
427
|
'error',
|
package/src/eslint/mui/index.mjs
CHANGED
|
@@ -12,6 +12,7 @@ import rulesOfUseThemeVariants from './rules/rules-of-use-theme-variants.mjs';
|
|
|
12
12
|
import straightQuotes from './rules/straight-quotes.mjs';
|
|
13
13
|
import addUndefToOptional from './rules/add-undef-to-optional.mjs';
|
|
14
14
|
import flattenParentheses from './rules/flatten-parentheses.mjs';
|
|
15
|
+
import noPresentationRole from './rules/no-presentation-role.mjs';
|
|
15
16
|
|
|
16
17
|
/** @type {import('eslint').ESLint.Plugin} */
|
|
17
18
|
const muiPlugin = {
|
|
@@ -35,6 +36,7 @@ const muiPlugin = {
|
|
|
35
36
|
// Some discrepancies between TypeScript and ESLint types - casting to any
|
|
36
37
|
'add-undef-to-optional': /** @type {any} */ (addUndefToOptional),
|
|
37
38
|
'flatten-parentheses': /** @type {any} */ (flattenParentheses),
|
|
39
|
+
'no-presentation-role': noPresentationRole,
|
|
38
40
|
},
|
|
39
41
|
};
|
|
40
42
|
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @type {import('eslint').Rule.RuleModule}
|
|
3
|
+
*/
|
|
4
|
+
const rule = {
|
|
5
|
+
meta: {
|
|
6
|
+
docs: {
|
|
7
|
+
description:
|
|
8
|
+
'Disallow role="presentation" in favor of role="none". Both are equivalent, but role="none" is clearer and shorter.',
|
|
9
|
+
},
|
|
10
|
+
messages: {
|
|
11
|
+
noPresentation:
|
|
12
|
+
'Use role="none" instead of role="presentation". They are equivalent, but role="none" is preferred.',
|
|
13
|
+
},
|
|
14
|
+
fixable: 'code',
|
|
15
|
+
type: 'suggestion',
|
|
16
|
+
schema: [],
|
|
17
|
+
},
|
|
18
|
+
create(context) {
|
|
19
|
+
return {
|
|
20
|
+
/** @param {import('estree-jsx').JSXAttribute} node */
|
|
21
|
+
JSXAttribute(node) {
|
|
22
|
+
if (node.name.type !== 'JSXIdentifier' || node.name.name !== 'role') {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const { value } = node;
|
|
27
|
+
|
|
28
|
+
// role="presentation"
|
|
29
|
+
if (value !== null && value.type === 'Literal' && value.value === 'presentation') {
|
|
30
|
+
context.report({
|
|
31
|
+
node,
|
|
32
|
+
messageId: 'noPresentation',
|
|
33
|
+
fix(fixer) {
|
|
34
|
+
return fixer.replaceText(value, '"none"');
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// role={'presentation'}
|
|
41
|
+
if (
|
|
42
|
+
value !== null &&
|
|
43
|
+
value.type === 'JSXExpressionContainer' &&
|
|
44
|
+
value.expression.type === 'Literal' &&
|
|
45
|
+
value.expression.value === 'presentation'
|
|
46
|
+
) {
|
|
47
|
+
context.report({
|
|
48
|
+
node,
|
|
49
|
+
messageId: 'noPresentation',
|
|
50
|
+
fix(fixer) {
|
|
51
|
+
return fixer.replaceText(value, '"none"');
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export default rule;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import eslint from 'eslint';
|
|
2
|
+
import parser from '@typescript-eslint/parser';
|
|
3
|
+
import rule from './no-presentation-role.mjs';
|
|
4
|
+
|
|
5
|
+
const ruleTester = new eslint.RuleTester({
|
|
6
|
+
languageOptions: {
|
|
7
|
+
parser,
|
|
8
|
+
parserOptions: {
|
|
9
|
+
ecmaFeatures: { jsx: true },
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
ruleTester.run('no-presentation-role', rule, {
|
|
15
|
+
valid: ['<div role="none" />', '<div role="button" />', '<div />', '<div role={presentation} />'],
|
|
16
|
+
invalid: [
|
|
17
|
+
{
|
|
18
|
+
code: '<div role="presentation" />',
|
|
19
|
+
errors: [{ messageId: 'noPresentation' }],
|
|
20
|
+
output: '<div role="none" />',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
code: "<div role={'presentation'} />",
|
|
24
|
+
errors: [{ messageId: 'noPresentation' }],
|
|
25
|
+
output: '<div role="none" />',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
code: '<table role="presentation"><tr><td /></tr></table>',
|
|
29
|
+
errors: [{ messageId: 'noPresentation' }],
|
|
30
|
+
output: '<table role="none"><tr><td /></tr></table>',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
});
|