我使用了 Angular 13。“@angular/core”:“~13.3.11”“codelyzer”:“^6.0.2”。当我使用 npm install 时,它会安装所有依赖项,并出现以下警告。我尝试 npmaudit --force 因此它将 codelyzer 版本转换为 0.0.28,现在 npm install 抛出错误,codelyzer@0.0.28 不支持 angular13。所以我现在处于循环状态。
npm i -> 抛出警告以审计从 codelyzer@6.0.2 到 @0.0.28
npm Audit --force:现在更改 codelyzer@0.0.28 的版本 npm 我抛出错误 codelyzer@0.0.28 不支持 angular13。
如何退出这个循环呢?
Angular 4+提供了一种在模板文件中执行if/else逻辑的方法,例如
<ng-container *ngIf="isSaveSuccess; else elseBlock">
Save succeeded.
</ng-container>
<ng-template #elseBlock>
Save failed.
</ng-template>
Run Code Online (Sandbox Code Playgroud)
但是,这需要您指定唯一的ng-template ID.我们对使用这种方法意外引入重复的"elseBlock"模板感到担心,例如
<ng-container *ngIf="isSaveSuccess; else elseBlock">
Save succeeded.
</ng-container>
<ng-template #elseBlock>
Save failed.
</ng-template>
...
<ng-container *ngIf="isUpdateSuccess; else elseBlock">
Update succeeded.
</ng-container>
<ng-template #elseBlock> <!-- duplicate id -->
Update failed.
</ng-template>
Run Code Online (Sandbox Code Playgroud)
有没有办法lint Angular模板文件来检测重复的ng-template ID?
ngb-pagination
我对某些使用ng-bootstrap指令的组件进行了 Angular 测试。
现在,在我的测试中,我模拟这个组件如下:
// on next line I get: The selector should be prefixed by "<prefix>" (https://angular.io/guide/styleguide#style-02-07) (component-selector)
@Component({ template: ``, selector: 'ngb-pagination' })
class DummyNgPagination {
// some data here, not relevant in to the question
}
Run Code Online (Sandbox Code Playgroud)
在放置@Component
注释的行中,我收到指向Style 02-07 的tslint错误。
我尝试通过执行以下操作来禁用该规则,但结果是相同的。
// tslint:disable-next-line:directive-selector
@Component({ template: ``, selector: 'ngb-pagination' })
Run Code Online (Sandbox Code Playgroud)
如何禁用该特定行的该规则?
附:
正在寻找 Angular 静态分析工具。使用了最流行的工具之一codelyzer,但我在这里看不到报告选项。
任何人都可以建议更好的 Angular 静态分析工具,或者是否有任何选项可以使用codelyzer生成报告。
我的 Angular 项目从 TSLint 迁移到 ESLint 时遇到了重大问题。我的工作方式是创建一个全新的项目(当前在 Angular 9 中),然后升级到 Angular 10.2。我遵循了@angular-eslint/schematic process中的指南,并且运行了 npx tslint-to-eslint-config。但是,当我尝试通过 Visual Studio Code 扩展运行 ESLint 时,当它尝试对我的 app.component.ts 文件进行 ESLint 时,出现以下错误:
Error while loading rule '@angular-eslint/template/banana-in-box': You have used a rule which requires '@angular-eslint/template-parser' to be used as the 'parser' in your ESLint config.
Run Code Online (Sandbox Code Playgroud)
以下是我的 .eslintrc.js 文件配置:
module.exports = {
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking"
],
"ignorePatterns": ["node_modules/**/*", "**/node_modules/**/*", "dist/**/*"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json", …
Run Code Online (Sandbox Code Playgroud) 我正在使用Angular 入门套件
我正在尝试让 tslint 使用 --fix 标志自动修复我所有的 lint 问题。
我正在运行脚本:
npm run tslint --fix src/**/*.ts
它只会生成与我已经被告知的相同错误,tslint
而不是自动修复它:
控制台输出:
ERROR: src/app/app-routing.module.ts[10, 5]: comment must start with a space
ERROR: src/app/app-routing.module.ts[2, 20]: Too many spaces before 'from'
Run Code Online (Sandbox Code Playgroud)
我是否缺少允许它实施更改的东西?
我的版本是:
"tslint": "^5.6.0"
"codelyzer": "^3.1.2"
Run Code Online (Sandbox Code Playgroud)
问题:如何让 tslint 对我的 lint 错误实施自动修复?
npm ls -json
当我在 Node.js 项目中运行命令时,出现以下错误:
npm ERR! missing: @angular/core@9.0.0, required by codelyzer@6.0.2
npm ERR! missing: @angular/compiler@9.0.0, required by codelyzer@6.0.2
Run Code Online (Sandbox Code Playgroud)
@angular/core
并@angular/compiler
已安装在我的项目的依赖项中,但版本为 10.2.4
yarn install
该错误仅在我运行安装软件包时发生。如果我使用npm install
一切正常,但需要一段时间。
是否有任何版本的 codelyzer 使用 Angular 10 而不是 Angular 9 或其他解决相同问题的软件包?
环境:
操作系统:Windows
包管理器:纱线
角度版本:10