如何禁用 Angular 样式指南的 tslint 规则:“选择器应以 <prefix>"为前缀? [英] How to disable tslint rule for Angular style guide: "The selector should be prefixed by <prefix>"?
问题描述
我对一些使用来自 ngb-pagination 的组件进行了 Angular 测试noreferrer">ng-bootstrap.
现在,在我的测试中,我模拟这个组件如下:
//在下一行我得到:选择器应该以"为前缀(https://angular.io/guide/styleguide#style-02-07)(组件选择器)@Component({ 模板: ``, 选择器: 'ngb-pagination' })类 DummyNgPagination {//这里有一些数据,与问题无关}
在放置 @Component
注释的行中,我收到一个 tslint 错误,指向 样式 02-07.
我尝试通过执行以下操作来禁用该规则,但结果是一样的.
//tslint:disable-next-line:directive-selector@Component({ 模板: ``, 选择器: 'ngb-pagination' })
如何为该特定行禁用该规则?
附注:
- 这里是真正的 angular 项目,以防您想查看任何资源配置.
- 有一个类似的问题(角度 2 选择器 (tslint) 中的烤肉串案例)但 OP 刚刚决定忍受它.
directive-selector
规则适用于 @Directive
装饰器.
对于 @Component
你需要使用 component-selector
例如:
//tslint:disable-next-line:component-selector@Component({ 模板: ``, 选择器: 'ngb-pagination' })
I have an Angular test for some component which uses the directive ngb-pagination
from ng-bootstrap.
Now, in my test I mock this component as follow:
// 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
}
In the line where it is placed the @Component
annotation I get a tslint error pointing to Style 02-07.
I tried to disable the rule by doing the following, but the result is the same.
// tslint:disable-next-line:directive-selector
@Component({ template: ``, selector: 'ngb-pagination' })
How can I disable that rule for that specific line?
PS:
- Here is the real angular project in case you want to check any resource configuration.
- There is a similar question (kebab-case in angular 2 selectors (tslint)) but the OP just decided to live with it.
The rule directive-selector
works for the @Directive
decorator.
For a @Component
you need to use component-selector
For example:
// tslint:disable-next-line:component-selector
@Component({ template: ``, selector: 'ngb-pagination' })
这篇关于如何禁用 Angular 样式指南的 tslint 规则:“选择器应以 <prefix>"为前缀?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!