Skip to content

Commit 7099737

Browse files
JanpotDaniel Rabe
authored and
Daniel Rabe
committed
[core] Upgrade eslint-config-airbnb-typescript (mui#34642)
Signed-off-by: Jan Potoms <[email protected]>
1 parent d97035a commit 7099737

File tree

14 files changed

+91
-116
lines changed

14 files changed

+91
-116
lines changed

.eslintrc.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module.exports = {
2222
extends: [
2323
'plugin:eslint-plugin-import/recommended',
2424
'plugin:eslint-plugin-import/typescript',
25+
'eslint-config-airbnb',
2526
'eslint-config-airbnb-typescript',
2627
'eslint-config-prettier',
2728
],
@@ -160,8 +161,7 @@ module.exports = {
160161
'react/state-in-constructor': 'off',
161162
// stylistic opinion. For conditional assignment we want it outside, otherwise as static
162163
'react/static-property-placement': 'off',
163-
// Currently not in recommended ruleset but catches real bugs.
164-
'react/no-unstable-nested-components': 'error',
164+
165165
'no-restricted-syntax': [
166166
// See https://github.com/eslint/eslint/issues/9192 for why it's needed
167167
...baseStyleRules['no-restricted-syntax'],
@@ -171,6 +171,15 @@ module.exports = {
171171
selector: 'ImportDeclaration[source.value="react"] ImportDefaultSpecifier',
172172
},
173173
],
174+
175+
// We re-export default in many places, remove when https://github.com/airbnb/javascript/issues/2500 gets resolved
176+
'no-restricted-exports': 'off',
177+
// Some of these occurences are deliberate and fixing them will break things in repos that use @monorepo dependency
178+
'import/no-relative-packages': 'off',
179+
// Avoid accidental auto-"fixes" https://github.com/jsx-eslint/eslint-plugin-react/issues/3458
180+
'react/no-invalid-html-attribute': 'off',
181+
182+
'react/jsx-no-useless-fragment': ['error', { allowExpressions: true }],
174183
},
175184
overrides: [
176185
{
@@ -355,6 +364,7 @@ module.exports = {
355364
'react/require-default-props': 'off',
356365
'react/state-in-constructor': 'off',
357366
'react/static-property-placement': 'off',
367+
'react/function-component-definition': 'off',
358368
},
359369
},
360370
{

docs/data/joy/customization/dark-mode/IdentifySystemMode.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import { CssVarsProvider, useColorScheme } from '@mui/joy/styles';
33
import Typography from '@mui/joy/Typography';
44

5-
const Identifier = () => {
5+
function Identifier() {
66
const { systemMode } = useColorScheme();
77
const [mounted, setMounted] = React.useState(false);
88
React.useEffect(() => {
@@ -32,7 +32,7 @@ const Identifier = () => {
3232
mode.
3333
</Typography>
3434
);
35-
};
35+
}
3636

3737
export default function IdentifySystemMode() {
3838
return (

docs/data/joy/customization/dark-mode/IdentifySystemMode.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import { CssVarsProvider, useColorScheme } from '@mui/joy/styles';
33
import Typography from '@mui/joy/Typography';
44

5-
const Identifier = () => {
5+
function Identifier() {
66
const { systemMode } = useColorScheme();
77
const [mounted, setMounted] = React.useState(false);
88
React.useEffect(() => {
@@ -32,7 +32,7 @@ const Identifier = () => {
3232
mode.
3333
</Typography>
3434
);
35-
};
35+
}
3636

3737
export default function IdentifySystemMode() {
3838
return (

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@
131131
"dtslint": "^4.2.1",
132132
"enzyme": "^3.11.0",
133133
"eslint": "^8.27.0",
134-
"eslint-config-airbnb-typescript": "^12.3.1",
134+
"eslint-config-airbnb": "^19.0.4",
135+
"eslint-config-airbnb-typescript": "^17.0.0",
135136
"eslint-config-prettier": "^8.5.0",
136137
"eslint-import-resolver-webpack": "^0.13.2",
137138
"eslint-plugin-babel": "^5.3.1",

packages/mui-joy/src/Autocomplete/Autocomplete.test.tsx

+32-28
Original file line numberDiff line numberDiff line change
@@ -547,17 +547,19 @@ describe('Joy <Autocomplete />', () => {
547547

548548
it('should trigger a form expectedly', () => {
549549
const handleSubmit = spy();
550-
const Test = (props: any) => (
551-
<div
552-
onKeyDown={(event) => {
553-
if (!event.defaultPrevented && event.key === 'Enter') {
554-
handleSubmit();
555-
}
556-
}}
557-
>
558-
<Autocomplete autoFocus options={['one', 'two']} {...props} />
559-
</div>
560-
);
550+
function Test(props: any) {
551+
return (
552+
<div
553+
onKeyDown={(event) => {
554+
if (!event.defaultPrevented && event.key === 'Enter') {
555+
handleSubmit();
556+
}
557+
}}
558+
>
559+
<Autocomplete autoFocus options={['one', 'two']} {...props} />
560+
</div>
561+
);
562+
}
561563
const { setProps } = render(<Test />);
562564
let textbox = screen.getByRole('combobox');
563565

@@ -2031,26 +2033,28 @@ describe('Joy <Autocomplete />', () => {
20312033
it('should prevent the default event handlers', () => {
20322034
const handleChange = spy();
20332035
const handleSubmit = spy();
2034-
const Test = () => (
2035-
<div
2036-
onKeyDown={(event) => {
2037-
if (!event.defaultPrevented && event.key === 'Enter') {
2038-
handleSubmit();
2039-
}
2040-
}}
2041-
>
2042-
<Autocomplete
2043-
autoFocus
2044-
options={['one', 'two']}
2045-
onChange={handleChange}
2036+
function Test() {
2037+
return (
2038+
<div
20462039
onKeyDown={(event) => {
2047-
if (event.key === 'Enter') {
2048-
event.defaultMuiPrevented = true;
2040+
if (!event.defaultPrevented && event.key === 'Enter') {
2041+
handleSubmit();
20492042
}
20502043
}}
2051-
/>
2052-
</div>
2053-
);
2044+
>
2045+
<Autocomplete
2046+
autoFocus
2047+
options={['one', 'two']}
2048+
onChange={handleChange}
2049+
onKeyDown={(event) => {
2050+
if (event.key === 'Enter') {
2051+
event.defaultMuiPrevented = true;
2052+
}
2053+
}}
2054+
/>
2055+
</div>
2056+
);
2057+
}
20542058
render(<Test />);
20552059
const textbox = screen.getByRole('combobox');
20562060
fireEvent.keyDown(textbox, { key: 'ArrowDown' });

packages/mui-joy/src/styles/ColorInversion.test.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import ThemeProvider from './ThemeProvider';
77
import ColorInversion, { useColorInversion } from './ColorInversion';
88
import { createSolidInversion } from './variantUtils';
99

10-
const Parent = ({ children, invertedColors }) => (
11-
<ColorInversion.Provider
12-
value={invertedColors ? ['plain', 'outlined', 'soft', 'solid'] : undefined}
13-
>
14-
{children}
15-
</ColorInversion.Provider>
16-
);
10+
const OVERRIDABLE_VARIANT = ['plain', 'outlined', 'soft', 'solid'];
11+
12+
function Parent({ children, invertedColors }) {
13+
return (
14+
<ColorInversion.Provider value={invertedColors ? OVERRIDABLE_VARIANT : undefined}>
15+
{children}
16+
</ColorInversion.Provider>
17+
);
18+
}
1719

1820
const Child = (inProps) => {
1921
const props = useThemeProps({ name: 'Child', props: inProps });

packages/mui-joy/src/styles/ColorInversion.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ interface ColorInversionProviderProps {
2929
variant?: VariantProp;
3030
}
3131

32-
export const ColorInversionProvider = ({ children, variant }: ColorInversionProviderProps) => {
32+
export function ColorInversionProvider({ children, variant }: ColorInversionProviderProps) {
3333
const theme = useSystemTheme(defaultTheme);
3434
return (
3535
<VariantOverride.Provider value={variant ? theme.colorInversionConfig[variant] : undefined}>
3636
{children}
3737
</VariantOverride.Provider>
3838
);
39-
};
39+
}
4040

4141
export default VariantOverride;

packages/mui-joy/src/styles/CssVarsProvider.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -537,10 +537,10 @@ describe('[Joy] CssVarsProvider', () => {
537537
});
538538

539539
it('contain expected colorInversion', function test() {
540-
const Text = () => {
540+
function Text() {
541541
const theme = useTheme();
542542
return <div>{Object.keys(theme.colorInversion).join(',')}</div>;
543-
};
543+
}
544544

545545
const { container } = render(
546546
<CssVarsProvider>

packages/mui-joy/src/utils/useSlot.test.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ describe('useSlot', () => {
142142
});
143143
const ItemOption = styled('div')({});
144144

145-
const Item = (props: {
145+
function Item(props: {
146146
component?: React.ElementType;
147147
components?: {
148148
root?: React.ElementType;
@@ -154,7 +154,7 @@ describe('useSlot', () => {
154154
listbox?: SlotComponentProps<'span', Record<string, any>, {}>;
155155
option?: SlotComponentProps<'div', Record<string, any>, {}>;
156156
};
157-
}) => {
157+
}) {
158158
const ref = React.useRef(null);
159159
const [SlotRoot, rootProps] = useSlot('root', {
160160
ref,
@@ -194,7 +194,7 @@ describe('useSlot', () => {
194194
</SlotListbox>
195195
</React.Fragment>
196196
);
197-
};
197+
}
198198

199199
it('should render popper with styled-component', () => {
200200
const { getByRole } = render(<Item />);
@@ -205,9 +205,9 @@ describe('useSlot', () => {
205205
});
206206

207207
it('the listbox slot should be replaceable', () => {
208-
const Listbox = ({ component }: { component?: React.ElementType }) => (
209-
<ul data-component={component} />
210-
);
208+
function Listbox({ component }: { component?: React.ElementType }) {
209+
return <ul data-component={component} />;
210+
}
211211
const { getByRole } = render(<Item components={{ listbox: Listbox }} />);
212212
expect(getByRole('list')).toBeVisible();
213213
expect(getByRole('list')).not.to.have.attribute('class');

packages/mui-lab/src/TreeView/TreeView.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,8 @@ const TreeView = React.forwardRef(function TreeView(inProps, ref) {
792792

793793
return (
794794
<TreeViewContext.Provider
795-
// TODO: fix lint error:
796-
/// eslint-disable-next-line react/jsx-no-constructed-context-values
795+
// TODO: fix this lint error
796+
// eslint-disable-next-line react/jsx-no-constructed-context-values
797797
value={{
798798
icons: { defaultCollapseIcon, defaultExpandIcon, defaultParentIcon, defaultEndIcon },
799799
focus,

packages/mui-material/src/Accordion/Accordion.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ describe('<Accordion />', () => {
169169
Accordion.propTypes,
170170
{
171171
classes: {},
172+
// eslint-disable-next-line react/jsx-no-useless-fragment
172173
children: <React.Fragment />,
173174
},
174175
'prop',

packages/mui-material/src/Menu/Menu.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ describe('<Menu />', () => {
249249
expect(() => {
250250
render(
251251
<Menu anchorEl={document.createElement('div')} open={false}>
252+
{/* eslint-disable-next-line react/jsx-no-useless-fragment */}
252253
<React.Fragment />
253254
</Menu>,
254255
);

packages/mui-utils/src/elementAcceptingRef.test.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ describe('elementAcceptingRef', () => {
103103

104104
// undesired behavior
105105
it('accepts Fragment', () => {
106+
// eslint-disable-next-line react/jsx-no-useless-fragment
106107
assertPass(<React.Fragment />);
107108
});
108109
});

0 commit comments

Comments
 (0)