Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Recommend no-restricted-imports to catch treeshake issues #21035

Merged
merged 3 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ module.exports = {
// Airbnb use error
'no-param-reassign': 'off',
'no-prototype-builtins': 'off',
'no-restricted-imports': [
'error',
{
patterns: ['@material-ui/*/*/*', '!@material-ui/core/test-utils/*'],
},
],
'nonblock-statement-body-position': 'error',
// Airbnb restricts isNaN and isFinite which are necessary for IE 11
// we have to be disciplined about the usage and ensure the Number type for its
Expand All @@ -55,7 +61,6 @@ module.exports = {
'jsx-a11y/no-autofocus': 'off', // We are a library, people do what they want.

'material-ui/docgen-ignore-before-comment': 'error',
'material-ui/restricted-path-imports': 'error',

// This rule is great for raising people awareness of what a key is and how it works.
'react/no-array-index-key': 'off',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-disable material-ui/restricted-path-imports */
import React from 'react';
// import of a small, pure module in a private demo
// bundle size and module duplication is negligible
/* eslint-disable-next-line no-restricted-imports */
import { convertLength } from '@material-ui/core/styles/cssUtils';
import { makeStyles, createMuiTheme, responsiveFontSizes } from '@material-ui/core/styles';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ import TabIndicator from '@material-ui/core/Tabs/TabIndicator';
// ^^^^^^^^^^^^ 3rd level
```

If you're using `eslint` you can catch problematic imports with the [`no-restricted-imports` rule](https://eslint.org/docs/rules/no-restricted-imports). The following `.eslintrc` configuration will highlight problematic imports from `@material-ui` packages:

```json
{
"rules": {
"no-restricted-imports": [
"error",
{
"patterns": ["@material-ui/*/*/*", "!@material-ui/core/test-utils/*"]
}
]
}
}
```

### Option 2

This option provides the best User Experience and Developer Experience:
Expand Down
17 changes: 15 additions & 2 deletions packages/eslint-plugin-material-ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Custom eslint rules for Material-UI.
- `disallow-active-element-as-key-event-target`
- `docgen-ignore-before-comment`
- `no-hardcoded-labels`
- `restricted-path-imports`
- ~~`restricted-path-imports`~~

### disallow-active-element-as-key-event-target

Expand All @@ -26,4 +26,17 @@ The docs are translated via crowdin, we prefer to use `t` from the redux store.

### restricted-path-imports

Prevent the import of modules at a level depth strictly over 1.
Removed in favor of [`no-restricted-imports`](https://eslint.org/docs/rules/no-restricted-imports) using the following configuration:

```json
{
"rules": {
"no-restricted-imports": [
"error",
{
"patterns": ["@material-ui/*/*/*", "!@material-ui/core/test-utils/*"]
}
]
}
}
```
1 change: 0 additions & 1 deletion packages/eslint-plugin-material-ui/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ module.exports.rules = {
'disallow-active-element-as-key-event-target': require('./rules/disallow-active-element-as-key-event-target'),
'docgen-ignore-before-comment': require('./rules/docgen-ignore-before-comment'),
'no-hardcoded-labels': require('./rules/no-hardcoded-labels'),
'restricted-path-imports': require('./rules/restricted-path-imports'),
};

This file was deleted.

This file was deleted.