-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed3619d
commit 4ca9523
Showing
8 changed files
with
90 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
7 changes: 7 additions & 0 deletions
7
eslint-plugin-tsoa/docs/rules/require-property-example-decorator.md
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,7 @@ | ||
# require-property-example-decorator | ||
|
||
Require the `@Example` decorator on class properties. | ||
|
||
💼 This rule is enabled in the ✅ `recommended` config. | ||
|
||
<!-- end auto-generated rule header --> |
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
42 changes: 42 additions & 0 deletions
42
eslint-plugin-tsoa/src/rules/require-property-example-decorator.test.ts
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,42 @@ | ||
import requirePropertyExampleDecorator from './require-property-example-decorator'; | ||
import { RuleTester } from '@typescript-eslint/rule-tester'; | ||
import { normalizeIndent } from '../test-utils'; | ||
|
||
const ruleTester = new RuleTester(); | ||
|
||
// Throws error if the tests in ruleTester.run() do not pass | ||
ruleTester.run( | ||
'require-property-example-decorator', // rule name | ||
requirePropertyExampleDecorator, // rule code | ||
{ | ||
// checks | ||
// 'valid' checks cases that should pass | ||
valid: [ | ||
{ | ||
name: 'when the property has an `@Example` decorator', | ||
code: normalizeIndent` | ||
class Pet { | ||
@Example<string>("Max") | ||
name: string; | ||
} | ||
`, | ||
}, | ||
], | ||
// 'invalid' checks cases that should not pass | ||
invalid: [ | ||
{ | ||
name: "when the property doesn't have an `@Example` decorator", | ||
code: normalizeIndent` | ||
class Pet { | ||
name: string; | ||
} | ||
`, | ||
errors: [ | ||
{ | ||
messageId: 'missingExampleDecorator', | ||
}, | ||
], | ||
}, | ||
], | ||
} | ||
); |
30 changes: 30 additions & 0 deletions
30
eslint-plugin-tsoa/src/rules/require-property-example-decorator.ts
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,30 @@ | ||
import { createRule, hasDecoratorWithName } from '../utils.js'; | ||
|
||
export default createRule({ | ||
name: 'require-property-example-decorator', | ||
meta: { | ||
messages: { | ||
missingExampleDecorator: | ||
"The '@Example' decorator is required on class properties", | ||
}, | ||
type: 'problem', | ||
docs: { | ||
description: 'require the `@Example` decorator on class properties', | ||
recommended: true, | ||
}, | ||
schema: [], | ||
}, | ||
defaultOptions: [], | ||
create(context) { | ||
return { | ||
PropertyDefinition(node) { | ||
if (!hasDecoratorWithName({ node, decoratorName: 'Example' })) { | ||
context.report({ | ||
node, | ||
messageId: 'missingExampleDecorator', | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}); |
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