Skip to content

Commit

Permalink
fix: correct validation for duration flags's default value
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Aug 15, 2022
1 parent 8cabbca commit 9fd41be
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/rules/flagMinMaxDefault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export const flagMinMaxDefault = ESLintUtils.RuleCreator.withoutDocs({
(flagPropertyIsNamed(property, 'min') || flagPropertyIsNamed(property, 'max'))
) &&
!node.value.arguments[0].properties.some(
(property) => property.type === 'Property' && flagPropertyIsNamed(property, 'default')
(property) =>
property.type === 'Property' &&
// defaultValue for DurationFlags
(flagPropertyIsNamed(property, 'default') || flagPropertyIsNamed(property, 'defaultValue'))
)
) {
context.report({
Expand Down
35 changes: 34 additions & 1 deletion test/rules/flagMinMaxDefault.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> {
}
}
`,
},

// duration flags use defaultValue instead of default
{
filename: path.normalize('src/commands/foo.ts'),
code: `
export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> {
public static flags = {
alias: Flags.duration({
min: 1,
max: 5,
defaultValue: 2
}),
}
}
`,
},
],
Expand All @@ -51,7 +68,6 @@ export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> {
errors: [
{
messageId: 'message',
data: { flagName: 'Alias' },
},
],
code: `
Expand All @@ -62,6 +78,23 @@ export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> {
}),
}
}
`,
},
{
filename: path.normalize('src/commands/foo.ts'),
errors: [
{
messageId: 'message',
},
],
code: `
export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> {
public static flags = {
foo: Flags.duration({
min: 5
}),
}
}
`,
},
{
Expand Down

0 comments on commit 9fd41be

Please sign in to comment.