-
Notifications
You must be signed in to change notification settings - Fork 235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: support validation directives and extra suffixes #407
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,122 +1,156 @@ | ||
import { assertAnnotated, assertSuccess } from './testHelper'; | ||
|
||
describe('directive-class-suffix', () => { | ||
describe('invalid directive class suffix', () => { | ||
it('should fail when directive class is with the wrong suffix', () => { | ||
let source = ` | ||
describe('invalid directive class suffix', () => { | ||
it('should fail when directive class is with the wrong suffix', () => { | ||
let source = ` | ||
@Directive({ | ||
selector: 'sgBarFoo' | ||
}) | ||
class Test {} | ||
~~~~ | ||
`; | ||
assertAnnotated({ | ||
ruleName: 'directive-class-suffix', | ||
message: 'The name of the class Test should end with the suffix Directive (https://angular.io/styleguide#style-02-03)', | ||
source | ||
}); | ||
}); | ||
assertAnnotated({ | ||
ruleName: 'directive-class-suffix', | ||
message: 'The name of the class Test should end with the suffix Directive (https://angular.io/styleguide#style-02-03)', | ||
source | ||
}); | ||
}); | ||
|
||
describe('valid directive class name', () => { | ||
it('should succeed when the directive class name ends with Directive', () => { | ||
let source = ` | ||
it('should fail when directive class is with the wrong suffix', () => { | ||
let source = ` | ||
@Directive({ | ||
selector: 'sgBarFoo' | ||
}) | ||
class Test {} | ||
~~~~ | ||
`; | ||
assertAnnotated({ | ||
ruleName: 'directive-class-suffix', | ||
message: 'The name of the class Test should end with the suffix Directive, Page, Validator (https://angular.io/styleguide#style-02-03)', | ||
source, | ||
options: ['Directive', 'Page', 'Validator'] | ||
}); | ||
}); | ||
}); | ||
|
||
describe('valid directive class name', () => { | ||
it('should succeed when the directive class name ends with Directive', () => { | ||
let source = ` | ||
@Directive({ | ||
selector: 'sgBarFoo' | ||
}) | ||
class TestDirective {}`; | ||
assertSuccess('directive-class-suffix', source); | ||
}); | ||
assertSuccess('directive-class-suffix', source); | ||
}); | ||
|
||
it('should succeed when the directive class name ends with Validator and implements Validator', () => { | ||
const source = ` | ||
@Directive({ | ||
selector: 'sgBarFoo' | ||
}) | ||
class TestValidator implements Validator {}`; | ||
assertSuccess('directive-class-suffix', source); | ||
}); | ||
|
||
describe('not called decorator', () => { | ||
it('should not fail when @Directive is not called', () => { | ||
let source = ` | ||
it('should succeed when the directive class name ends with Validator and implements AsyncValidator', () => { | ||
const source = ` | ||
@Directive({ | ||
selector: 'sgBarFoo' | ||
}) | ||
class TestValidator implements AsyncValidator {}`; | ||
assertSuccess('directive-class-suffix', source); | ||
}); | ||
}); | ||
|
||
describe('not called decorator', () => { | ||
it('should not fail when @Directive is not called', () => { | ||
let source = ` | ||
@Directive | ||
class TestDirective {}`; | ||
assertSuccess('directive-class-suffix', source); | ||
}); | ||
assertSuccess('directive-class-suffix', source); | ||
}); | ||
}); | ||
|
||
describe('valid directive class', () => { | ||
it('should succeed when is used @Component decorator', () => { | ||
let source = ` | ||
describe('valid directive class', () => { | ||
it('should succeed when is used @Component decorator', () => { | ||
let source = ` | ||
@Component({ | ||
selector: 'sg-foo-bar' | ||
}) | ||
class TestComponent {}`; | ||
assertSuccess('directive-class-suffix', source); | ||
}); | ||
assertSuccess('directive-class-suffix', source); | ||
}); | ||
}); | ||
|
||
describe('valid pipe class', () => { | ||
it('should succeed when is used @Pipe decorator', () => { | ||
let source = ` | ||
describe('valid pipe class', () => { | ||
it('should succeed when is used @Pipe decorator', () => { | ||
let source = ` | ||
@Pipe({ | ||
selector: 'sg-test-pipe' | ||
}) | ||
class TestPipe {}`; | ||
assertSuccess('directive-class-suffix', source); | ||
}); | ||
assertSuccess('directive-class-suffix', source); | ||
}); | ||
}); | ||
|
||
describe('valid service class', () => { | ||
it('should succeed when is used @Injectable decorator', () => { | ||
let source = ` | ||
describe('valid service class', () => { | ||
it('should succeed when is used @Injectable decorator', () => { | ||
let source = ` | ||
@Injectable() | ||
class TestService {}`; | ||
assertSuccess('directive-class-suffix', source); | ||
}); | ||
assertSuccess('directive-class-suffix', source); | ||
}); | ||
}); | ||
|
||
describe('valid empty class', () => { | ||
it('should succeed when the class is empty', () => { | ||
let source = ` | ||
describe('valid empty class', () => { | ||
it('should succeed when the class is empty', () => { | ||
let source = ` | ||
class TestEmpty {}`; | ||
assertSuccess('directive-class-suffix', source); | ||
}); | ||
assertSuccess('directive-class-suffix', source); | ||
}); | ||
}); | ||
|
||
describe('changed suffix', () => { | ||
it('should suceed when different sufix is set', () => { | ||
let source = ` | ||
describe('changed suffix', () => { | ||
it('should suceed when different sufix is set', () => { | ||
let source = ` | ||
@Directive({ | ||
selector: 'sgBarFoo' | ||
}) | ||
class TestPage {}`; | ||
assertSuccess('directive-class-suffix', source, ['Page']); | ||
}); | ||
assertSuccess('directive-class-suffix', source, ['Page']); | ||
}); | ||
|
||
it('should fail when different sufix is set and doesnt match', () => { | ||
let source = ` | ||
it('should fail when different sufix is set and doesnt match', () => { | ||
let source = ` | ||
@Directive({ | ||
selector: 'sgBarFoo' | ||
}) | ||
class TestPage {} | ||
~~~~~~~~ | ||
`; | ||
assertAnnotated({ | ||
ruleName: 'directive-class-suffix', | ||
message: 'The name of the class TestPage should end with the suffix Directive (https://angular.io/styleguide#style-02-03)', | ||
source, | ||
options: ['Directive'] | ||
}); | ||
}); | ||
assertAnnotated({ | ||
ruleName: 'directive-class-suffix', | ||
message: 'The name of the class TestPage should end with the suffix Directive (https://angular.io/styleguide#style-02-03)', | ||
source, | ||
options: ['Directive'] | ||
}); | ||
}); | ||
|
||
it('should fail when different sufix is set and doesnt match', () => { | ||
let source = ` | ||
it('should fail when different sufix is set and doesnt match', () => { | ||
let source = ` | ||
@Directive({ | ||
selector: 'sgBarFoo' | ||
}) | ||
class TestDirective {} | ||
~~~~~~~~~~~~~ | ||
`; | ||
assertAnnotated({ | ||
ruleName: 'directive-class-suffix', | ||
message: 'The name of the class TestDirective should end with the suffix Page (https://angular.io/styleguide#style-02-03)', | ||
source, | ||
options: ['Page'] | ||
}); | ||
}); | ||
assertAnnotated({ | ||
ruleName: 'directive-class-suffix', | ||
message: 'The name of the class TestDirective should end with the suffix Page (https://angular.io/styleguide#style-02-03)', | ||
source, | ||
options: ['Page'] | ||
}); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t.expression
is never null ? if this is the case =>if (t.expression.name)