【问题标题】:Configure eslint to use the default import配置 eslint 使用默认导入
【发布时间】:2021-06-22 22:46:03
【问题描述】:

我正在尝试使用这种特定情况为 @material-ui 配置 eslint:
我想这样导入:import Typography from '@material-ui/core/Typography';
并禁用导入,例如:import { Typography } from '@material-ui/core';

我已将no-restricted-imports 规则配置为:

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

在我的逻辑中,它应该像这样工作:禁用来自@material-ui/core 的所有导入,除了@material-ui/core/*。我做错了什么以及如何根据我的情况进行配置?

【问题讨论】:

    标签: material-ui eslint


    【解决方案1】:

    我使用了路径:

    {
    ...
    "no-restricted-imports": [
          "error",
          {
            paths: [
              { name: "@material-ui/core", message: "no named import from material ui core" },
              { name: "@material-ui/lab", message: "no named import from material ui lab" },
            ],
          },
        ],
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-31
      • 2016-04-14
      • 2016-07-10
      相关资源
      最近更新 更多