如何解决如何运行@angular-eslint/schematics:convert-tslint-to-eslint
我正在尝试按照 angular-eslint github repo 中的说明将 Angular 项目从 TSLint 切换到 ESLint。
我运行了 ng add @angular-eslint/schematics
,它向我的 package.json 添加了以下依赖项:
"@angular-eslint/builder": "1.2.0","@angular-eslint/eslint-plugin": "1.2.0","@angular-eslint/eslint-plugin-template": "1.2.0","@angular-eslint/schematics": "1.2.0","@angular-eslint/template-parser": "1.2.0","@typescript-eslint/eslint-plugin": "4.3.0","@typescript-eslint/parser": "4.3.0","eslint": "7.6.0","eslint-plugin-import": "2.22.1","eslint-plugin-jsdoc": "30.7.6","eslint-plugin-prefer-arrow": "1.2.2",
还运行 npm install
以确保这些都已安装。
现在我被指示运行:
ng g @angular-eslint/schematics:convert-tslint-to-eslint --remove-tslint-if-no-more-tslint-targets --ignore-existing-tslint-config
然而,这会导致错误:
UnkNown option: '--remove-tslint-if-no-more-tslint-targets'
UnkNown option: '--ignore-existing-tslint-config'
Invalid rule result: Instance of class Promise.
这个 angular-eslint 示意图似乎没有正确安装。但是,我对这些原理图完全是新手。我一定在这里遗漏了一些明显的东西。
使用@angular/cli 10.2.3。
解决方法
如果您要迁移现有项目,则应该运行其中之一
ng g @angular-eslint/schematics:convert-tslint-to-eslint
或
ng g @angular-eslint/schematics:convert-tslint-to-eslint {{YOUR_PROJECT_NAME_GOES_HERE}}
代替
ng g @angular-eslint/schematics:convert-tslint-to-eslint --remove-tslint-if-no-more-tslint-targets --ignore-existing-tslint-config
,
这取决于您项目的 Angular 版本,
步骤将是:
A.将@angular-eslint 添加到您的项目中:
ng add @angular-eslint/schematics
B.如果你有一个 Angular 12 项目,你就大功告成了!对于 Angular 11,运行以下命令:
ng g @angular-eslint/schematics:convert-tslint-to-eslint --remove-tslint-if-no-more-tslint-targets
(仅当您想忽略旧的 tslint 配置时才使用:--ignore-existing-tslint-config
标志)
如果您使用的是 Angular 9 或 10,则会安装旧版本的原理图,并且转换命令略有不同。在转换为 ESLint 之前,您可能希望优先升级 Angular。但是如果你真的想先升级linting,使用这个命令:
ng g @angular-eslint/schematics:convert-tslint-to-eslint <project-name-here>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。