【问题标题】:NextJS Typescript - Setup tslint configuration to force error when have unused import/declarationsNextJS Typescript - 设置 tslint 配置以在有未使用的导入/声明时强制出错
【发布时间】:2021-06-09 23:58:28
【问题描述】:

当我在下一个打字稿中编写了未使用的导入/声明时,谁能告诉我如何强制出错?

用例是: 我有的例子 import { Accordion, AccordionButton } from '@chakra-ui/react'; Accordion 组件已使用,但 AccordionButton 未使用,我希望在保存文件时出现错误编译原因,即未使用 AccordionButton。

注意: 我已经添加: "noUnusedLocals": true, "noUnusedParameters": true

在 tsconfig.json 中但仍然没有解决我的问题

【问题讨论】:

    标签: javascript reactjs typescript lint tslint


    【解决方案1】:

    这在很大程度上取决于您使用的编辑器。在 VScode 中,我将它设置为灰色未使用的导入,以便您可以轻松地注意到并删除它们。

    在您的 VScode 配置中:

    {
      "javascript.validate.enable": true,
      "editor.showUnused": true
    }
    

    至于出错,这里有一个 eslint 插件可以显示未使用的导入的 linting 错误:

    https://www.npmjs.com/package/eslint-plugin-unused-imports

    【讨论】:

      猜你喜欢
      • 2019-10-19
      • 2019-05-24
      • 2021-06-20
      • 2022-01-05
      • 2012-12-04
      • 2018-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多