forked from cwoolum/ionicV4-tslint
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rules): add ion-list-header-ion-label-required rule (#35)
* feat(rules): add ion-list-header-ion-label-required rule * docs(readme): mark rule as complete
- Loading branch information
Showing
4 changed files
with
114 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { NgWalker } from 'codelyzer/angular/ngWalker'; | ||
import * as Lint from 'tslint'; | ||
import * as ts from 'typescript'; | ||
|
||
import { createIonLabelRequiredTemplateVisitorClass } from './helpers/ionLabelRequired'; | ||
|
||
export const ruleName = 'ion-list-header-ion-label-required'; | ||
|
||
const TemplateVisitor = createIonLabelRequiredTemplateVisitorClass('ion-list-header'); | ||
|
||
export class Rule extends Lint.Rules.AbstractRule { | ||
public static metadata: Lint.IRuleMetadata = { | ||
ruleName: ruleName, | ||
type: 'functionality', | ||
description: 'The ion-list-header component requires an ion-label component. It is no longer automatically added.', | ||
options: null, | ||
optionsDescription: 'Not configurable.', | ||
typescriptOnly: false, | ||
hasFix: true | ||
}; | ||
|
||
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { | ||
return this.applyWithWalker( | ||
new NgWalker(sourceFile, this.getOptions(), { | ||
templateVisitorCtrl: TemplateVisitor | ||
}) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { ruleName } from '../src/ionListHeaderIonLabelRequiredRule'; | ||
import { assertAnnotated, assertSuccess } from './testHelper'; | ||
|
||
describe(ruleName, () => { | ||
describe('success', () => { | ||
it('should work with ion-label child', () => { | ||
let source = ` | ||
@Component({ | ||
template: \` | ||
<ion-list-header> | ||
<ion-thumbnail slot="start"> | ||
<img src="http://pngimg.com/upload/dog_png2402.png"> | ||
</ion-thumbnail> | ||
<ion-label>Dog</ion-label> | ||
</ion-list-header> | ||
\` | ||
}) | ||
class Bar{} | ||
`; | ||
assertSuccess(ruleName, source); | ||
}); | ||
|
||
it('should work with single ion-label child', () => { | ||
let source = ` | ||
@Component({ | ||
template: \` | ||
<ion-list-header> | ||
<ion-label>Dog</ion-label> | ||
</ion-list-header> | ||
\` | ||
}) | ||
class Bar{} | ||
`; | ||
assertSuccess(ruleName, source); | ||
}); | ||
}); | ||
|
||
describe('failure', () => { | ||
it('should fail when ion-label missing', () => { | ||
let source = ` | ||
@Component({ | ||
template: \` | ||
<ion-list-header> | ||
~~~~~~~~~~~~~~~ | ||
<ion-thumbnail slot="start"> | ||
<img src="http://pngimg.com/upload/dog_png2402.png"> | ||
</ion-thumbnail> | ||
Dog | ||
</ion-toolbar> | ||
\` | ||
}) | ||
class Bar{} | ||
`; | ||
|
||
assertAnnotated({ | ||
ruleName, | ||
message: 'The ion-list-header requires an ion-label component. It is no longer automatically added.', | ||
source | ||
}); | ||
}); | ||
|
||
it('should fail with only text', () => { | ||
let source = ` | ||
@Component({ | ||
template: \` | ||
<ion-list-header>Dog</ion-list-header> | ||
~~~~~~~~~~~~~~~ | ||
\` | ||
}) | ||
class Bar{} | ||
`; | ||
|
||
assertAnnotated({ | ||
ruleName, | ||
message: 'The ion-list-header requires an ion-label component. It is no longer automatically added.', | ||
source | ||
}); | ||
}); | ||
}); | ||
}); |