是否有可能以更漂亮的方式删除未使用的进口?

发布于 2025-02-10 12:52:12 字数 156 浏览 0 评论 0 原文

我有一个Expo React Antive应用程序,该应用程序中有大量未使用的进口量。

我对代码格式的设置更漂亮,是否可以配置更漂亮的还可以删除整个项目中的任何未使用的导入?

我看不到文档中的任何东西,我不知道是否有一种方法可以在更漂亮的地方添加额外的Eslint插件。

I have an Expo React Native app that has a ton of unused imports in components.

I have Prettier setup for code formatting, is it possible to configure Prettier to also remove any unused imports across the project?

I can't see anything in the docs and I don't know if there is a way to add extra eslint plugins to Prettier.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

久光 2025-02-17 12:52:12

您可以使用VS Code .vscode/settings.json 来组织导入。

"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
  "source.organizeImports": true
}

You can use VS Code .vscode/settings.json to organize imports.

"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
  "source.organizeImports": true
}
咿呀咿呀哟 2025-02-17 12:52:12

我认为默认情况下没有支持。

但是您可以使用此Prettier-Plugin

I don't think this is supported by default.

But you can use this prettier-plugin https://www.npmjs.com/package/prettier-plugin-organize-imports

肩上的翅膀 2025-02-17 12:52:12
 "editor.codeActionsOnSave": {
    "source.organizeImports": "always",
    "source.fixAll": "explicit"
  },

您需要在设置中添加这些行。

 "editor.codeActionsOnSave": {
    "source.organizeImports": "always",
    "source.fixAll": "explicit"
  },

You need to add these lines in your settings.json

红颜悴 2025-02-17 12:52:12

在上面提到的@quicksort构建方面,这是我们使用Prettier SDK所做的:

prettier.format(text, {
    plugins: ['prettier-plugin-organize-imports']
  })

Building off what @QuickSort mentioned above, this is what we did using the Prettier sdk:

prettier.format(text, {
    plugins: ['prettier-plugin-organize-imports']
  })
生生不灭 2025-02-17 12:52:12

可以与Yarn 一起使用

正如@quicksort所述, ,您可以使用 Prettier-Plugin-Organize-Imports
安装插件,将其添加到您的.prettierrc.cjs文件中:

module.exports = {
    plugins: [require.resolve('prettier-plugin-organize-imports')]
};

并运行更漂亮。

works with yarn

As @QuickSort mentioned, you can use prettier-plugin-organize-imports.
Install plugin, add this to your .prettierrc.cjs file:

module.exports = {
    plugins: [require.resolve('prettier-plugin-organize-imports')]
};

and run prettier.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文