Skip to content

Commit 85d4246

Browse files
committed
refactor(validator): add validator suffix to generated file
1 parent 5a71f46 commit 85d4246

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

commands/Make/Validator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default class MakeValidator extends BaseGenerator {
1919
/**
2020
* Required by BaseGenerator
2121
*/
22-
protected $suffix = ''
22+
protected $suffix = 'Validator'
2323
protected $form = 'singular' as const
2424
protected $pattern = 'pascalcase' as const
2525
protected $resourceName: string

templates/validator.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { schema, validator } from '@ioc:Adonis/Core/Validator'
22

3-
class ${filename}Validator {
3+
class ${filename} {
44
/**
55
* Using a pre-compiled schema you can validate the "shape", "type",
66
* "formatting" and "integrity" of data.
@@ -37,4 +37,4 @@ class ${filename}Validator {
3737
public messages = {}
3838
}
3939

40-
export default new ${filename}Validator()
40+
export default new ${filename}()

test/make-validator.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ test.group('Make Validator', (group) => {
4242
validator.name = 'user'
4343
await validator.handle()
4444

45-
const UserValidator = await fs.get('app/Validators/User.ts')
45+
const UserValidator = await fs.get('app/Validators/UserValidator.ts')
4646
const ValidatorTemplate = await templates.get('validator.txt')
4747
assert.deepEqual(
4848
toNewlineArray(UserValidator),
49-
toNewlineArray(ValidatorTemplate.replace(new RegExp('\\${filename}', 'g'), 'User')),
49+
toNewlineArray(ValidatorTemplate.replace(new RegExp('\\${filename}', 'g'), 'UserValidator')),
5050
)
5151
})
5252

@@ -66,11 +66,11 @@ test.group('Make Validator', (group) => {
6666
validator.name = 'user'
6767
await validator.handle()
6868

69-
const UserValidator = await fs.get('app/User.ts')
69+
const UserValidator = await fs.get('app/UserValidator.ts')
7070
const ValidatorTemplate = await templates.get('validator.txt')
7171
assert.deepEqual(
7272
toNewlineArray(UserValidator),
73-
toNewlineArray(ValidatorTemplate.replace(new RegExp('\\${filename}', 'g'), 'User')),
73+
toNewlineArray(ValidatorTemplate.replace(new RegExp('\\${filename}', 'g'), 'UserValidator')),
7474
)
7575
})
7676
})

0 commit comments

Comments
 (0)