From 17e392bb15a3ef1d1b8695feec738f13a53e01a3 Mon Sep 17 00:00:00 2001 From: Cristian Dominguez Date: Tue, 23 Jul 2024 14:59:49 -0300 Subject: [PATCH] fix: handle import aliases --- src/rules/command-example.ts | 2 +- src/rules/command-summary.ts | 2 +- src/rules/dash-h.ts | 2 +- src/rules/dash-o.ts | 2 +- src/rules/extract-message-command.ts | 2 +- src/rules/extract-message-flags.ts | 2 +- src/rules/flag-casing.ts | 2 +- src/rules/flag-cross-references.ts | 2 +- src/rules/flag-min-max-default.ts | 2 +- src/rules/flag-summary.ts | 2 +- src/rules/get-connections-with-version.ts | 2 +- src/rules/id-flag-suggestions.ts | 2 +- .../migration/encourage-alias-deprecation.ts | 4 +-- src/rules/migration/no-builtin-flags.ts | 2 +- .../migration/no-deprecated-properties.ts | 2 +- src/rules/migration/no-filepath-flags.ts | 2 +- src/rules/migration/no-id-flags.ts | 2 +- src/rules/migration/no-number-flags.ts | 2 +- src/rules/migration/no-this-flags.ts | 4 +-- src/rules/migration/no-this-org.ts | 4 +-- src/rules/migration/no-this-ux.ts | 2 +- src/rules/migration/no-time-flags.ts | 2 +- src/rules/migration/no-username-properties.ts | 4 +-- src/rules/migration/sfdx-flags-property.ts | 2 +- src/rules/migration/should-parse-flags.ts | 2 +- src/rules/migration/use-sf-command-flags.ts | 2 +- .../no-args-parse-without-strict-false.ts | 3 +- src/rules/no-default-depends-on-flags.ts | 2 +- src/rules/no-duplicate-short-characters.ts | 2 +- src/rules/no-hyphens-aliases.ts | 2 +- src/rules/no-json-flag.ts | 2 +- src/rules/no-split-examples.ts | 2 +- src/rules/no-unnecessary-aliases.ts | 2 +- src/rules/no-unnecessary-properties.ts | 2 +- src/rules/only-extend-sfCommand.ts | 24 ++++++++++++++- src/rules/read-only-properties.ts | 2 +- src/rules/run-matches-class-type.ts | 2 +- src/shared/commands.ts | 30 +++++++++++++++---- test/rules/command-example.test.ts | 3 ++ test/rules/command-summary.test.ts | 4 +++ test/rules/dash-h.test.ts | 3 ++ test/rules/dash-o.test.ts | 5 ++++ test/rules/extract-message-command.test.ts | 6 ++++ test/rules/extract-message-flags.test.ts | 15 ++++++++++ test/rules/flag-casing.test.ts | 6 ++++ test/rules/flag-cross-feferences.test.ts | 8 +++++ test/rules/flag-min-max-default.test.ts | 7 +++++ test/rules/flag-summary.test.ts | 7 +++++ .../get-connections-with-version.test.ts | 3 ++ test/rules/id-flag-suggestions.test.ts | 12 ++++++++ .../encourageAliasDeprecation.test.ts | 7 +++++ test/rules/migration/no-builtin-flags.test.ts | 6 ++++ .../no-deprecated-properties.test.ts | 6 ++++ .../rules/migration/no-filepath-flags.test.ts | 4 +++ test/rules/migration/no-id-flags.test.ts | 4 +++ test/rules/migration/no-number-flags.test.ts | 4 +++ test/rules/migration/no-this-flags.test.ts | 7 +++++ test/rules/migration/no-this-org.test.ts | 7 +++++ test/rules/migration/no-this-ux.test.ts | 8 +++++ test/rules/migration/no-time-flags.test.ts | 4 +++ .../migration/no-username-properties.test.ts | 14 +++++++++ .../migration/sfdx-flags-property.test.ts | 6 ++++ .../migration/should-parse-flags.test.ts | 5 ++++ .../migration/use-sf-command-flags.test.ts | 4 +++ ...no-args-parse-without-strict-false.test.ts | 7 +++++ .../no-classes-in-command-return-type.test.ts | 6 ++++ .../rules/no-default-depends-on-flags.test.ts | 6 ++++ test/rules/no-duplicate-short-chars.test.ts | 8 +++++ test/rules/no-hyphen-aliases.test.ts | 7 +++++ test/rules/no-json-flag.test.ts | 3 ++ test/rules/no-split-examples.test.ts | 4 +++ test/rules/no-uneccessary-properties.test.ts | 8 +++++ test/rules/no-unnecessary-aliases.test.ts | 8 +++++ test/rules/only-extend-sfCommand.test.ts | 18 +++++++++++ test/rules/read-only-properties.test.ts | 10 +++++++ test/rules/run-matches-class-type.test.ts | 5 ++++ test/rules/spread-base-flags.test.ts | 2 ++ 77 files changed, 344 insertions(+), 48 deletions(-) diff --git a/src/rules/command-example.ts b/src/rules/command-example.ts index e854dd2e..36842f3b 100644 --- a/src/rules/command-example.ts +++ b/src/rules/command-example.ts @@ -28,7 +28,7 @@ export const commandExamples = createRule({ ? { ClassDeclaration(node): void { // verify it extends SfCommand - if (extendsSfCommand(node) && node.id) { + if (extendsSfCommand(node,context) && node.id) { if (!node.body.body.some((member) => getClassPropertyIdentifierName(member) === 'examples')) { context.report({ node: node.id, diff --git a/src/rules/command-summary.ts b/src/rules/command-summary.ts index 33884e81..658b1c91 100644 --- a/src/rules/command-summary.ts +++ b/src/rules/command-summary.ts @@ -27,7 +27,7 @@ export const commandSummary = RuleCreator.withoutDocs({ ? { ClassDeclaration(node): void { // verify it extends SfCommand - if (extendsSfCommand(node) && node.id) { + if (extendsSfCommand(node, context) && node.id) { if (!node.body.body.some((member) => getClassPropertyIdentifierName(member) === 'summary')) { const descriptionNode = node.body.body.find( (member) => getClassPropertyIdentifierName(member) === 'description' diff --git a/src/rules/dash-h.ts b/src/rules/dash-h.ts index a8fca399..48c5c90c 100644 --- a/src/rules/dash-h.ts +++ b/src/rules/dash-h.ts @@ -29,7 +29,7 @@ export const dashH = RuleCreator.withoutDocs({ // is a flag if ( isFlag(node) && - ancestorsContainsSfCommand(context.getAncestors()) && + ancestorsContainsSfCommand(context) && node.value?.type === AST_NODE_TYPES.CallExpression && node.value.arguments?.[0]?.type === AST_NODE_TYPES.ObjectExpression ) { diff --git a/src/rules/dash-o.ts b/src/rules/dash-o.ts index eda3d524..43b3bafa 100644 --- a/src/rules/dash-o.ts +++ b/src/rules/dash-o.ts @@ -30,7 +30,7 @@ export const dashO = RuleCreator.withoutDocs({ // is a flag if ( isFlag(node) && - ancestorsContainsSfCommand(context.getAncestors()) && + ancestorsContainsSfCommand(context) && node.value?.type === AST_NODE_TYPES.CallExpression && node.value.callee?.type === AST_NODE_TYPES.MemberExpression && node.value.callee.property.type === AST_NODE_TYPES.Identifier && diff --git a/src/rules/extract-message-command.ts b/src/rules/extract-message-command.ts index 0ed4458c..919395e8 100644 --- a/src/rules/extract-message-command.ts +++ b/src/rules/extract-message-command.ts @@ -29,7 +29,7 @@ export const extractMessageCommand = RuleCreator.withoutDocs({ ? { ClassDeclaration(node): void { // verify it extends SfCommand - if (extendsSfCommand(node)) { + if (extendsSfCommand(node, context)) { node.body.body .filter((prop) => // this could be `undefined` but that works okay with `.includes` diff --git a/src/rules/extract-message-flags.ts b/src/rules/extract-message-flags.ts index 01e78f5e..e05d4c8d 100644 --- a/src/rules/extract-message-flags.ts +++ b/src/rules/extract-message-flags.ts @@ -37,7 +37,7 @@ export const extractMessageFlags = RuleCreator.withoutDocs({ node.key.type === AST_NODE_TYPES.Identifier && (node.key.name === 'summary' || node.key.name === 'description') && ancestors.some((a) => isFlag(a)) && - ancestorsContainsSfCommand(ancestors) + ancestorsContainsSfCommand(context) ) { if (node.value.type === AST_NODE_TYPES.Literal) { context.report({ diff --git a/src/rules/flag-casing.ts b/src/rules/flag-casing.ts index 85a7e2aa..58ad57f3 100644 --- a/src/rules/flag-casing.ts +++ b/src/rules/flag-casing.ts @@ -32,7 +32,7 @@ export const flagCasing = RuleCreator.withoutDocs({ return isInCommandDirectory(context) ? { Property(node): void { - if (isFlag(node) && ancestorsContainsSfCommand(context.getAncestors())) { + if (isFlag(node) && ancestorsContainsSfCommand(context)) { const flagName = resolveFlagName(node); if (flagName && toLowerKebabCase(flagName) !== flagName) { context.report({ diff --git a/src/rules/flag-cross-references.ts b/src/rules/flag-cross-references.ts index fd6671cf..0b455a3a 100644 --- a/src/rules/flag-cross-references.ts +++ b/src/rules/flag-cross-references.ts @@ -35,7 +35,7 @@ export const flagCrossReferences = RuleCreator.withoutDocs({ node.value.type === AST_NODE_TYPES.ArrayExpression && node.value.elements.every((e) => e?.type === AST_NODE_TYPES.Literal && e?.raw) && propertyNames.includes(node.key.name) && - ancestorsContainsSfCommand(ancestors) && + ancestorsContainsSfCommand(context) && ancestors.some((a) => isFlag(a)) ) { const flagsNode = ancestors diff --git a/src/rules/flag-min-max-default.ts b/src/rules/flag-min-max-default.ts index 373c10c5..81a2fe70 100644 --- a/src/rules/flag-min-max-default.ts +++ b/src/rules/flag-min-max-default.ts @@ -27,7 +27,7 @@ export const flagMinMaxDefault = RuleCreator.withoutDocs({ return isInCommandDirectory(context) ? { Property(node): void { - if (isFlag(node) && ancestorsContainsSfCommand(context.getAncestors())) { + if (isFlag(node) && ancestorsContainsSfCommand(context)) { if ( node.value?.type === AST_NODE_TYPES.CallExpression && node.value.arguments?.[0]?.type === AST_NODE_TYPES.ObjectExpression && diff --git a/src/rules/flag-summary.ts b/src/rules/flag-summary.ts index 4e16451d..795da52a 100644 --- a/src/rules/flag-summary.ts +++ b/src/rules/flag-summary.ts @@ -30,7 +30,7 @@ export const flagSummary = RuleCreator.withoutDocs({ Property(node): void { if ( isFlag(node) && - ancestorsContainsSfCommand(context.getAncestors()) && + ancestorsContainsSfCommand(context) && node.value?.type === AST_NODE_TYPES.CallExpression && node.value.arguments?.[0]?.type === AST_NODE_TYPES.ObjectExpression ) { diff --git a/src/rules/get-connections-with-version.ts b/src/rules/get-connections-with-version.ts index c2e62dab..c683bb6b 100644 --- a/src/rules/get-connections-with-version.ts +++ b/src/rules/get-connections-with-version.ts @@ -33,7 +33,7 @@ export const getConnectionWithVersion = RuleCreator.withoutDocs({ node.callee?.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property?.name === 'getConnection' && - ancestorsContainsSfCommand(context.getAncestors()) + ancestorsContainsSfCommand(context) ) { context.report({ node: node.callee.property, diff --git a/src/rules/id-flag-suggestions.ts b/src/rules/id-flag-suggestions.ts index 812e7c48..f6c21948 100644 --- a/src/rules/id-flag-suggestions.ts +++ b/src/rules/id-flag-suggestions.ts @@ -32,7 +32,7 @@ export const idFlagSuggestions = RuleCreator.withoutDocs({ return isInCommandDirectory(context) ? { Property(node): void { - if (isFlag(node) && ancestorsContainsSfCommand(context.getAncestors())) { + if (isFlag(node) && ancestorsContainsSfCommand(context)) { if ( (node.key.type === AST_NODE_TYPES.Identifier || node.key.type === AST_NODE_TYPES.Literal) && node.value?.type === AST_NODE_TYPES.CallExpression && diff --git a/src/rules/migration/encourage-alias-deprecation.ts b/src/rules/migration/encourage-alias-deprecation.ts index 7cb8e95b..60082609 100644 --- a/src/rules/migration/encourage-alias-deprecation.ts +++ b/src/rules/migration/encourage-alias-deprecation.ts @@ -32,7 +32,7 @@ export const encourageAliasDeprecation = RuleCreator.withoutDocs({ return isInCommandDirectory(context) ? { PropertyDefinition(node): void { - if (ancestorsContainsSfCommand(context.getAncestors())) { + if (ancestorsContainsSfCommand(context)) { if (node.key.type === AST_NODE_TYPES.Identifier && node.key.name === 'aliases') { // but you don't have deprecateAliases = true then add id if ( @@ -63,7 +63,7 @@ export const encourageAliasDeprecation = RuleCreator.withoutDocs({ isFlag(node) && node.value?.type === AST_NODE_TYPES.CallExpression && node.value.arguments?.[0]?.type === AST_NODE_TYPES.ObjectExpression && - ancestorsContainsSfCommand(context.getAncestors()) + ancestorsContainsSfCommand(context) ) { const argProps = node.value.arguments[0].properties.filter( ASTUtils.isNodeOfType(AST_NODE_TYPES.Property) diff --git a/src/rules/migration/no-builtin-flags.ts b/src/rules/migration/no-builtin-flags.ts index b4d08271..9fc4fb14 100644 --- a/src/rules/migration/no-builtin-flags.ts +++ b/src/rules/migration/no-builtin-flags.ts @@ -33,7 +33,7 @@ export const noBuiltinFlags = RuleCreator.withoutDocs({ isFlag(node) && node.key.type === AST_NODE_TYPES.Identifier && builtInFlagTypes.includes(node.key.name) && - ancestorsContainsSfCommand(context.getAncestors()) + ancestorsContainsSfCommand(context) ) { const toReplace = getCalleePropertyByName(node, 'builtin'); if (toReplace) { diff --git a/src/rules/migration/no-deprecated-properties.ts b/src/rules/migration/no-deprecated-properties.ts index 45b024f4..e8782ac6 100644 --- a/src/rules/migration/no-deprecated-properties.ts +++ b/src/rules/migration/no-deprecated-properties.ts @@ -25,7 +25,7 @@ export const noDeprecatedProperties = RuleCreator.withoutDocs({ return isInCommandDirectory(context) ? { PropertyDefinition(node): void { - if (ancestorsContainsSfCommand(context.getAncestors())) { + if (ancestorsContainsSfCommand(context)) { if ( node.key.type === AST_NODE_TYPES.Identifier && ['supportsDevhubUsername', 'varargs'].includes(node.key.name) diff --git a/src/rules/migration/no-filepath-flags.ts b/src/rules/migration/no-filepath-flags.ts index e851a82f..6b040601 100644 --- a/src/rules/migration/no-filepath-flags.ts +++ b/src/rules/migration/no-filepath-flags.ts @@ -27,7 +27,7 @@ export const noFilepathFlags = RuleCreator.withoutDocs({ return isInCommandDirectory(context) ? { Property(node): void { - if (isFlag(node) && ancestorsContainsSfCommand(context.getAncestors())) { + if (isFlag(node) && ancestorsContainsSfCommand(context)) { const toReplace = getCalleePropertyByName(node, 'filepath'); if (toReplace) { context.report({ diff --git a/src/rules/migration/no-id-flags.ts b/src/rules/migration/no-id-flags.ts index a426ad78..560f744d 100644 --- a/src/rules/migration/no-id-flags.ts +++ b/src/rules/migration/no-id-flags.ts @@ -27,7 +27,7 @@ export const noIdFlags = RuleCreator.withoutDocs({ return isInCommandDirectory(context) ? { Property(node): void { - if (isFlag(node) && ancestorsContainsSfCommand(context.getAncestors())) { + if (isFlag(node) && ancestorsContainsSfCommand(context)) { const toReplace = getCalleePropertyByName(node, 'id'); if (toReplace) { context.report({ diff --git a/src/rules/migration/no-number-flags.ts b/src/rules/migration/no-number-flags.ts index 63ad85a4..533cb4d3 100644 --- a/src/rules/migration/no-number-flags.ts +++ b/src/rules/migration/no-number-flags.ts @@ -27,7 +27,7 @@ export const noNumberFlags = RuleCreator.withoutDocs({ return isInCommandDirectory(context) ? { Property(node): void { - if (isFlag(node) && ancestorsContainsSfCommand(context.getAncestors())) { + if (isFlag(node) && ancestorsContainsSfCommand(context)) { const toReplace = getCalleePropertyByName(node, 'number'); if (toReplace) { context.report({ diff --git a/src/rules/migration/no-this-flags.ts b/src/rules/migration/no-this-flags.ts index 1d776a12..ee8b3862 100644 --- a/src/rules/migration/no-this-flags.ts +++ b/src/rules/migration/no-this-flags.ts @@ -37,9 +37,9 @@ export const noThisFlags = RuleCreator.withoutDocs({ return isInCommandDirectory(context) ? { MemberExpression(node): void { - if (MemberExpressionIsThisDotFoo(node, 'flags') && ancestorsContainsSfCommand(context.getAncestors())) { + if (MemberExpressionIsThisDotFoo(node, 'flags') && ancestorsContainsSfCommand(context)) { // it's ok if there's a this.flags on the class... - const classAbove = getSfCommand(context.getAncestors()); + const classAbove = getSfCommand(context); if (!classAbove) { return; } diff --git a/src/rules/migration/no-this-org.ts b/src/rules/migration/no-this-org.ts index c0e2fb48..3253af08 100644 --- a/src/rules/migration/no-this-org.ts +++ b/src/rules/migration/no-this-org.ts @@ -32,9 +32,9 @@ export const noThisOrg = RuleCreator.withoutDocs({ return isInCommandDirectory(context) ? { MemberExpression(node): void { - if (MemberExpressionIsThisDotFoo(node, 'org') && ancestorsContainsSfCommand(context.getAncestors())) { + if (MemberExpressionIsThisDotFoo(node, 'org') && ancestorsContainsSfCommand(context)) { // it's ok if there's a this.org on the class... - const classAbove = getSfCommand(context.getAncestors()); + const classAbove = getSfCommand(context); if (!classAbove) { return; } diff --git a/src/rules/migration/no-this-ux.ts b/src/rules/migration/no-this-ux.ts index 9baa3fad..cc266e76 100644 --- a/src/rules/migration/no-this-ux.ts +++ b/src/rules/migration/no-this-ux.ts @@ -35,7 +35,7 @@ export const noThisUx = RuleCreator.withoutDocs({ MemberExpression(node): void { if ( MemberExpressionContainsMemberExpressionThisDotFoo(node, 'ux') && - ancestorsContainsSfCommand(context.getAncestors()) + ancestorsContainsSfCommand(context) ) { // spinner cases if (node.property.type === AST_NODE_TYPES.Identifier && spinnerMigration.has(node.property.name)) { diff --git a/src/rules/migration/no-time-flags.ts b/src/rules/migration/no-time-flags.ts index ca274adf..a9339839 100644 --- a/src/rules/migration/no-time-flags.ts +++ b/src/rules/migration/no-time-flags.ts @@ -29,7 +29,7 @@ export const noTimeFlags = RuleCreator.withoutDocs({ return isInCommandDirectory(context) ? { Property(node): void { - if (isFlag(node) && ancestorsContainsSfCommand(context.getAncestors())) { + if (isFlag(node) && ancestorsContainsSfCommand(context)) { if ( (node.key.type === AST_NODE_TYPES.Identifier || node.key.type === AST_NODE_TYPES.Literal) && node.value.type === AST_NODE_TYPES.CallExpression && diff --git a/src/rules/migration/no-username-properties.ts b/src/rules/migration/no-username-properties.ts index e1a79bfe..66a74522 100644 --- a/src/rules/migration/no-username-properties.ts +++ b/src/rules/migration/no-username-properties.ts @@ -61,7 +61,7 @@ export const noUsernameProperties = RuleCreator.withoutDocs({ return isInCommandDirectory(context) ? { PropertyDefinition(node): void { - if (ancestorsContainsSfCommand(context.getAncestors())) { + if (ancestorsContainsSfCommand(context)) { if (node.key.type === AST_NODE_TYPES.Identifier && propertyMap.has(node.key.name)) { const mappedMetadata = propertyMap.get(node.key.name); if (!mappedMetadata) { @@ -85,7 +85,7 @@ export const noUsernameProperties = RuleCreator.withoutDocs({ // add the flag if not already present - const outerClass = getSfCommand(ancestors); + const outerClass = getSfCommand(context); if (!outerClass) { return; } diff --git a/src/rules/migration/sfdx-flags-property.ts b/src/rules/migration/sfdx-flags-property.ts index 58b2de89..afc4e40c 100644 --- a/src/rules/migration/sfdx-flags-property.ts +++ b/src/rules/migration/sfdx-flags-property.ts @@ -28,7 +28,7 @@ export const sfdxFlagsProperty = RuleCreator.withoutDocs({ return isInCommandDirectory(context) ? { PropertyDefinition(node): void { - if (ancestorsContainsSfCommand(context.getAncestors())) { + if (ancestorsContainsSfCommand(context)) { if (node.key.type === AST_NODE_TYPES.Identifier && node.key.name === 'flagsConfig') { context.report({ node, diff --git a/src/rules/migration/should-parse-flags.ts b/src/rules/migration/should-parse-flags.ts index e53e2c6c..eaf18fb1 100644 --- a/src/rules/migration/should-parse-flags.ts +++ b/src/rules/migration/should-parse-flags.ts @@ -30,7 +30,7 @@ export const shouldParseFlags = RuleCreator.withoutDocs({ if (isRunMethod(node) && node.value?.body?.body) { // OK, looks like a run method has a type annotation const ancestors = context.getAncestors(); - const classDeclaration = getSfCommand(ancestors); + const classDeclaration = getSfCommand(context); if ( // and it has flags to be parsed classDeclaration?.body?.body?.some((prop) => isFlagsStaticProperty(prop)) diff --git a/src/rules/migration/use-sf-command-flags.ts b/src/rules/migration/use-sf-command-flags.ts index ee539a5c..2ece1bc6 100644 --- a/src/rules/migration/use-sf-command-flags.ts +++ b/src/rules/migration/use-sf-command-flags.ts @@ -32,7 +32,7 @@ export const useSfCommandFlags = RuleCreator.withoutDocs({ node.value?.callee?.type === AST_NODE_TYPES.MemberExpression && node.value?.callee?.object?.type === AST_NODE_TYPES.Identifier && node.value?.callee?.object?.name === 'flags' && - ancestorsContainsSfCommand(context.getAncestors()) + ancestorsContainsSfCommand(context) ) { const range = node.value.callee.object.range; context.report({ diff --git a/src/rules/no-args-parse-without-strict-false.ts b/src/rules/no-args-parse-without-strict-false.ts index 7f3bbe80..0c9fcc15 100644 --- a/src/rules/no-args-parse-without-strict-false.ts +++ b/src/rules/no-args-parse-without-strict-false.ts @@ -43,8 +43,7 @@ export const noArgsParseWithoutStrictFalse = RuleCreator.withoutDocs({ ) ) { // Verify that the class has strict = false - const ancestors = context.getAncestors(); - const sfCommand = getSfCommand(ancestors); + const sfCommand = getSfCommand(context); if (!sfCommand) { return; } diff --git a/src/rules/no-default-depends-on-flags.ts b/src/rules/no-default-depends-on-flags.ts index efbe272b..ef159079 100644 --- a/src/rules/no-default-depends-on-flags.ts +++ b/src/rules/no-default-depends-on-flags.ts @@ -29,7 +29,7 @@ export const noDefaultDependsOnFlags = RuleCreator.withoutDocs({ // is a flag if ( isFlag(node) && - ancestorsContainsSfCommand(context.getAncestors()) && + ancestorsContainsSfCommand(context) && node.value?.type === AST_NODE_TYPES.CallExpression && node.value.arguments?.[0]?.type === AST_NODE_TYPES.ObjectExpression ) { diff --git a/src/rules/no-duplicate-short-characters.ts b/src/rules/no-duplicate-short-characters.ts index e8803904..f91af9e7 100644 --- a/src/rules/no-duplicate-short-characters.ts +++ b/src/rules/no-duplicate-short-characters.ts @@ -30,7 +30,7 @@ export const noDuplicateShortCharacters = RuleCreator.withoutDocs({ PropertyDefinition(node): void { // is "public static flags" property if ( - ancestorsContainsSfCommand(context.getAncestors()) && + ancestorsContainsSfCommand(context) && node.value?.type === AST_NODE_TYPES.ObjectExpression && isFlagsStaticProperty(node) ) { diff --git a/src/rules/no-hyphens-aliases.ts b/src/rules/no-hyphens-aliases.ts index 2d64908d..ff6b1f76 100644 --- a/src/rules/no-hyphens-aliases.ts +++ b/src/rules/no-hyphens-aliases.ts @@ -37,7 +37,7 @@ export const noHyphenAliases = RuleCreator.withoutDocs({ node.parent.parent.key.name === 'aliases' && node.parent.parent.parent?.parent?.parent && isFlag(node.parent.parent.parent?.parent?.parent) && - ancestorsContainsSfCommand(context.getAncestors()) + ancestorsContainsSfCommand(context) ) { context.report({ node, diff --git a/src/rules/no-json-flag.ts b/src/rules/no-json-flag.ts index be5e395c..8ca2c18f 100644 --- a/src/rules/no-json-flag.ts +++ b/src/rules/no-json-flag.ts @@ -26,7 +26,7 @@ export const jsonFlag = RuleCreator.withoutDocs({ return isInCommandDirectory(context) ? { Property(node): void { - if (isFlag(node) && ancestorsContainsSfCommand(context.getAncestors())) { + if (isFlag(node) && ancestorsContainsSfCommand(context)) { if (node.key.type === AST_NODE_TYPES.Identifier && node.key.name === 'json') { context.report({ node, diff --git a/src/rules/no-split-examples.ts b/src/rules/no-split-examples.ts index c850f9d2..76306863 100644 --- a/src/rules/no-split-examples.ts +++ b/src/rules/no-split-examples.ts @@ -40,7 +40,7 @@ export const noSplitExamples = RuleCreator.withoutDocs({ node.value.callee.object.callee.property.name === 'getMessage' && node.value.callee.property.type === AST_NODE_TYPES.Identifier && node.value.callee.property.name === 'split' && - extendsSfCommand(node.parent.parent) + extendsSfCommand(node.parent.parent, context) ) { const target = node.value; const fixedText = context diff --git a/src/rules/no-unnecessary-aliases.ts b/src/rules/no-unnecessary-aliases.ts index 3fcde16d..271eb175 100644 --- a/src/rules/no-unnecessary-aliases.ts +++ b/src/rules/no-unnecessary-aliases.ts @@ -34,7 +34,7 @@ export const noUnnecessaryAliases = RuleCreator.withoutDocs({ node.parent.parent.key.type === AST_NODE_TYPES.Identifier && node.parent.parent.key.name === 'aliases' && context.getPhysicalFilename && - ancestorsContainsSfCommand(context.getAncestors()) + ancestorsContainsSfCommand(context) ) { const parentLength = node.parent.elements.length; const cmdParts = getCommandNameParts(context.getPhysicalFilename()); diff --git a/src/rules/no-unnecessary-properties.ts b/src/rules/no-unnecessary-properties.ts index 971eaf85..54073433 100644 --- a/src/rules/no-unnecessary-properties.ts +++ b/src/rules/no-unnecessary-properties.ts @@ -36,7 +36,7 @@ export const noUnnecessaryProperties = RuleCreator.withoutDocs({ node.parent?.type === AST_NODE_TYPES.ClassBody && node.parent.parent?.type === AST_NODE_TYPES.ClassDeclaration && node.value && - extendsSfCommand(node.parent.parent) + extendsSfCommand(node.parent.parent, context) ) { // properties that default to false if ( diff --git a/src/rules/only-extend-sfCommand.ts b/src/rules/only-extend-sfCommand.ts index 670695cb..e70dabf5 100644 --- a/src/rules/only-extend-sfCommand.ts +++ b/src/rules/only-extend-sfCommand.ts @@ -24,11 +24,33 @@ export const onlyExtendSfCommand = RuleCreator.withoutDocs({ }, defaultOptions: [], create(context) { + // function extendsSfCommand(node: TSESTree.ClassDeclaration, context: RuleContext): boolean { + // // Track imported classes and their aliases + // const importedClasses = new Map(); + // + // for (const node of (context.sourceCode).ast.body) { + // if (node.type === 'ImportDeclaration') { + // node.specifiers.forEach(specifier => { + // if (specifier.type === 'ImportSpecifier' && specifier.imported.name === 'SfCommand') { + // importedClasses.set(specifier.local.name, 'SfCommand'); + // } + // // Handle import aliases + // else if (specifier.type === 'ImportSpecifier' && specifier.local.name !== specifier.imported.name) { + // importedClasses.set(specifier.local.name, specifier.imported.name); + // } + // }) + // } + // } + // + // return node.superClass?.type === AST_NODE_TYPES.Identifier && (importedClasses.get(node.superClass.name) == 'SfCommand'); + // } + return isInCommandDirectory(context) ? { ClassDeclaration(node): void { // verify it extends SfCommand - if (!extendsSfCommand(node) && node.id) { + // importedClasses.has() + if (!extendsSfCommand(node, context) && node.id) { context.report({ node: node.id, messageId: 'message', diff --git a/src/rules/read-only-properties.ts b/src/rules/read-only-properties.ts index d0dcd8cf..9681d557 100644 --- a/src/rules/read-only-properties.ts +++ b/src/rules/read-only-properties.ts @@ -35,7 +35,7 @@ export const readOnlyProperties = RuleCreator.withoutDocs({ props.includes(node.key.name) && node.parent?.type === AST_NODE_TYPES.ClassBody && node.parent.parent?.type === AST_NODE_TYPES.ClassDeclaration && - extendsSfCommand(node.parent.parent) + extendsSfCommand(node.parent.parent,context) ) { if (!node.readonly) { context.report({ diff --git a/src/rules/run-matches-class-type.ts b/src/rules/run-matches-class-type.ts index 406475dd..35575ea5 100644 --- a/src/rules/run-matches-class-type.ts +++ b/src/rules/run-matches-class-type.ts @@ -31,7 +31,7 @@ export const runMatchesClassType = RuleCreator.withoutDocs({ if (isRunMethod(node) && node.value.returnType?.typeAnnotation.type === AST_NODE_TYPES.TSTypeReference) { // OK, run method has a type annotation. Now we need to check if the class extends SfCommand and get the const ancestors = context.getAncestors(); - const classDeclaration = getSfCommand(ancestors); + const classDeclaration = getSfCommand(context); if (classDeclaration) { // get the text for the two nodes diff --git a/src/shared/commands.ts b/src/shared/commands.ts index 062e47c4..87fc0937 100644 --- a/src/shared/commands.ts +++ b/src/shared/commands.ts @@ -9,14 +9,32 @@ import { sep, parse } from 'path'; import { AST_NODE_TYPES, TSESTree, ASTUtils } from '@typescript-eslint/utils'; import { RuleContext } from '@typescript-eslint/utils/ts-eslint'; -export const ancestorsContainsSfCommand = (ancestors: TSESTree.Node[]): boolean => - ancestors.some((a) => a.type === AST_NODE_TYPES.ClassDeclaration && extendsSfCommand(a)); +export const ancestorsContainsSfCommand = (context: RuleContext): boolean => + context.getAncestors().some((a) => a.type === AST_NODE_TYPES.ClassDeclaration && extendsSfCommand(a,context)); -export const getSfCommand = (ancestors: TSESTree.Node[]): TSESTree.ClassDeclaration | undefined => - ancestors.filter(ASTUtils.isNodeOfType(AST_NODE_TYPES.ClassDeclaration)).find((a) => a && extendsSfCommand(a)); +export const getSfCommand = (context: RuleContext): TSESTree.ClassDeclaration | undefined => + context.getAncestors().filter(ASTUtils.isNodeOfType(AST_NODE_TYPES.ClassDeclaration)).find((a) => a && extendsSfCommand(a,context)); -export const extendsSfCommand = (node: TSESTree.ClassDeclaration): boolean => - node.superClass?.type === AST_NODE_TYPES.Identifier && node.superClass.name === 'SfCommand'; +export const extendsSfCommand = (node: TSESTree.ClassDeclaration, context: RuleContext): boolean => { + // Track imported classes and their aliases + const importedClasses = new Map(); + + for (const node of (context.sourceCode).ast.body) { + if (node.type === 'ImportDeclaration') { + node.specifiers.forEach(specifier => { + if (specifier.type === 'ImportSpecifier' && specifier.imported.name === 'SfCommand') { + importedClasses.set(specifier.local.name, 'SfCommand'); + } + // Handle import aliases + else if (specifier.type === 'ImportSpecifier' && specifier.local.name !== specifier.imported.name) { + importedClasses.set(specifier.local.name, specifier.imported.name); + } + }) + } + } + + return node.superClass?.type === AST_NODE_TYPES.Identifier && (importedClasses.get(node.superClass.name) == 'SfCommand'); +} export const getClassPropertyIdentifierName = (node: TSESTree.ClassElement): string | undefined => node.type === AST_NODE_TYPES.PropertyDefinition && node.key.type === AST_NODE_TYPES.Identifier diff --git a/test/rules/command-example.test.ts b/test/rules/command-example.test.ts index 21aea63d..dbeae0bd 100644 --- a/test/rules/command-example.test.ts +++ b/test/rules/command-example.test.ts @@ -18,6 +18,7 @@ ruleTester.run('commandExamples', commandExamples, { { name: 'correct example for a command', code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly summary = 'foo' public static readonly examples = 'baz' @@ -37,6 +38,7 @@ export default class EnvCreateScratch extends somethingElse { public static readonly description = 'bar' public static readonly summary = 'baz' @@ -54,6 +56,7 @@ export default class EnvCreateScratch extends SfCommand { }, ], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly description = 'bar' public static readonly summary = 'baz' diff --git a/test/rules/command-summary.test.ts b/test/rules/command-summary.test.ts index 2a5075d0..3c3aaebe 100644 --- a/test/rules/command-summary.test.ts +++ b/test/rules/command-summary.test.ts @@ -21,6 +21,7 @@ ruleTester.run('commandSummary', commandSummary, { code: // example with different chars ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly summary = 'foo' public static readonly examples = 'baz' @@ -68,6 +69,7 @@ export abstract class StagedProgress { ], filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly examples = 'baz' } @@ -84,12 +86,14 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), // allow formatter to handle the newline/indent stuff output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly summary = 'bar';public static readonly description = 'bar' public static readonly examples = 'baz' } `, code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly description = 'bar' public static readonly examples = 'baz' diff --git a/test/rules/dash-h.test.ts b/test/rules/dash-h.test.ts index 2afb1577..6fc8e2df 100644 --- a/test/rules/dash-h.test.ts +++ b/test/rules/dash-h.test.ts @@ -19,6 +19,7 @@ ruleTester.run('dashH', dashH, { name: 'does not use -h', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -34,6 +35,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'not in commands directory', filename: path.normalize('foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { json: Flags.boolean({ @@ -51,6 +53,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'message' }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { json: Flags.boolean({ diff --git a/test/rules/dash-o.test.ts b/test/rules/dash-o.test.ts index 9a916fd6..c3b536f3 100644 --- a/test/rules/dash-o.test.ts +++ b/test/rules/dash-o.test.ts @@ -19,6 +19,7 @@ ruleTester.run('dashO', dashO, { name: 'does not use -o', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -33,6 +34,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'uses -o for an org-like flag', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { hub: Flags.requiredOrgFlag({ @@ -47,6 +49,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'uses -o for an hub-like flag', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { hub: Flags.requiredHubFlag({ @@ -61,6 +64,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'not in commands directory', filename: path.normalize('foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { json: Flags.boolean({ @@ -77,6 +81,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'message' }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { json: Flags.boolean({ diff --git a/test/rules/extract-message-command.test.ts b/test/rules/extract-message-command.test.ts index 053cf636..e72079d0 100644 --- a/test/rules/extract-message-command.test.ts +++ b/test/rules/extract-message-command.test.ts @@ -19,6 +19,7 @@ ruleTester.run('no hardcoded summary/description on command', extractMessageComm name: 'messages for command description and summary', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly description = messages.getMessage('description'); public static readonly summary = messages.getMessage('summary'); @@ -29,6 +30,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'messages for command description', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly description = messages.getMessage('description'); } @@ -38,6 +40,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'messages for command summary', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly summary = messages.getMessage('summary'); } @@ -57,6 +60,7 @@ export default class EnvCreateScratch extends SomethingElse { public static readonly description = 'foo'; public static readonly summary = 'bar'; @@ -74,6 +78,7 @@ export default class EnvCreateScratch extends SfCommand { }, ], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly description = 'foo'; public static readonly summary = messages.getMessage('summary'); @@ -93,6 +98,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly description = 'foo'; public static readonly summary = 'bar'; diff --git a/test/rules/extract-message-flags.test.ts b/test/rules/extract-message-flags.test.ts index e8baa745..5aa4c262 100644 --- a/test/rules/extract-message-flags.test.ts +++ b/test/rules/extract-message-flags.test.ts @@ -19,6 +19,7 @@ ruleTester.run('summary/description messages format', extractMessageFlags, { name: 'no messages', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -32,6 +33,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'summary uses messages', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -45,6 +47,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'summary and description use messages', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -59,6 +62,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'description uses messages', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -72,6 +76,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'flag with a hyphen', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { 'hyphen-flag': Flags.string({ @@ -85,6 +90,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'not in commands dir', filename: path.normalize('src/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -106,6 +112,7 @@ export default class EnvCreateScratch extends SfCommand { }, ], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -127,6 +134,7 @@ export default class EnvCreateScratch extends SfCommand { output: null, code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -151,6 +159,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -171,6 +180,7 @@ export default class EnvCreateScratch extends SfCommand { }, ], output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { name: Flags.string({ @@ -180,6 +190,7 @@ export default class EnvCreateScratch extends SfCommand { } `, code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { name: Flags.string({ @@ -199,6 +210,7 @@ export default class EnvCreateScratch extends SfCommand { }, ], output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -208,6 +220,7 @@ export default class EnvCreateScratch extends SfCommand { } `, code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -227,6 +240,7 @@ export default class EnvCreateScratch extends SfCommand { }, ], output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { 'hyphen-flag': Flags.string({ @@ -236,6 +250,7 @@ export default class EnvCreateScratch extends SfCommand { } `, code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { 'hyphen-flag': Flags.string({ diff --git a/test/rules/flag-casing.test.ts b/test/rules/flag-casing.test.ts index 5e9293a0..9b957373 100644 --- a/test/rules/flag-casing.test.ts +++ b/test/rules/flag-casing.test.ts @@ -19,6 +19,7 @@ ruleTester.run('flagCasing', flagCasing, { name: 'correct flag casing for hyphenated and non-hyphenated', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({}), @@ -31,6 +32,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'not in commands directory', filename: path.normalize('src/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { Alias: Flags.string({}), @@ -51,6 +53,7 @@ export default class EnvCreateScratch extends SfCommand { ], filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { Alias: Flags.string({}), @@ -59,6 +62,7 @@ export default class EnvCreateScratch extends SfCommand { } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { 'alias': Flags.string({}), @@ -81,6 +85,7 @@ export default class EnvCreateScratch extends SfCommand { ], filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { Alias: Flags.string({}), @@ -89,6 +94,7 @@ export default class EnvCreateScratch extends SfCommand { } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { 'alias': Flags.string({}), diff --git a/test/rules/flag-cross-feferences.test.ts b/test/rules/flag-cross-feferences.test.ts index 91e11d40..9f8549c6 100644 --- a/test/rules/flag-cross-feferences.test.ts +++ b/test/rules/flag-cross-feferences.test.ts @@ -19,6 +19,7 @@ ruleTester.run('cross-references exist for dependsOn, exclusive, exactlyOne', fl name: 'dependent flag exists', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -33,6 +34,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'non-static definition of flags is supported', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -48,6 +50,7 @@ export default class EnvCreateScratch extends SfCommand { name: '2 exclusive flags that refer to each other', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -64,6 +67,7 @@ export default class EnvCreateScratch extends SfCommand { name: '2 exactlyOne flags that refer to each other', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -80,6 +84,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/foo.ts'), name: 'anything is ok outside the commands directory', code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -102,6 +107,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -122,6 +128,7 @@ export default class EnvCreateScratch extends SfCommand { ], filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -146,6 +153,7 @@ export default class EnvCreateScratch extends SfCommand { ], filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ diff --git a/test/rules/flag-min-max-default.test.ts b/test/rules/flag-min-max-default.test.ts index a7c7bfc2..a89c0013 100644 --- a/test/rules/flag-min-max-default.test.ts +++ b/test/rules/flag-min-max-default.test.ts @@ -19,6 +19,7 @@ ruleTester.run('flagMinMaxDefault', flagMinMaxDefault, { name: 'has min, max, default', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.integer({ @@ -36,6 +37,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'not commands directory', filename: path.normalize('foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.integer({ @@ -53,6 +55,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'correct setup for a Duration flag', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.duration({ @@ -76,6 +79,7 @@ export default class EnvCreateScratch extends SfCommand { }, ], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: Flags.integer({ @@ -94,6 +98,7 @@ export default class EnvCreateScratch extends SfCommand { }, ], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: Flags.duration({ @@ -112,6 +117,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: Flags.integer({ @@ -130,6 +136,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: Flags.integer({ diff --git a/test/rules/flag-summary.test.ts b/test/rules/flag-summary.test.ts index d5b6d8b1..ed4fb519 100644 --- a/test/rules/flag-summary.test.ts +++ b/test/rules/flag-summary.test.ts @@ -19,6 +19,7 @@ ruleTester.run('flagSummary', flagSummary, { name: 'flag with a summary', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -34,6 +35,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'not in commands directory', filename: path.normalize('foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({}), @@ -54,6 +56,7 @@ export default class EnvCreateScratch extends SfCommand { }, ], output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -63,6 +66,7 @@ export default class EnvCreateScratch extends SfCommand { } `, code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -82,6 +86,7 @@ export default class EnvCreateScratch extends SfCommand { }, ], output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -92,6 +97,7 @@ export default class EnvCreateScratch extends SfCommand { } `, code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -115,6 +121,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { Alias: Flags.string({}), diff --git a/test/rules/get-connections-with-version.test.ts b/test/rules/get-connections-with-version.test.ts index 528e44a2..181e42c4 100644 --- a/test/rules/get-connections-with-version.test.ts +++ b/test/rules/get-connections-with-version.test.ts @@ -19,6 +19,7 @@ ruleTester.run('call getConnection with version', getConnectionWithVersion, { name: 'passes in version', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { const conn = flags['target-org'].getConnection(flags['api-version']); @@ -31,6 +32,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'not in commands dir', filename: path.normalize('src/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { const conn = flags['target-org'].getConnection(flags['api-version']); @@ -49,6 +51,7 @@ export default class EnvCreateScratch extends SfCommand { }, ], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { const conn = flags['target-org'].getConnection(); diff --git a/test/rules/id-flag-suggestions.test.ts b/test/rules/id-flag-suggestions.test.ts index 512af021..e7248705 100644 --- a/test/rules/id-flag-suggestions.test.ts +++ b/test/rules/id-flag-suggestions.test.ts @@ -19,6 +19,7 @@ ruleTester.run('idFlagSuggestions', idFlagSuggestions, { name: 'salesforceId flag with length and startsWith', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { verbose: Flags.salesforceId({ @@ -42,6 +43,7 @@ export default class EnvCreateScratch extends SfCommand { { messageId: 'typeSuggestion', output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { id: Flags.salesforceId({startsWith: '000', @@ -53,6 +55,7 @@ export default class EnvCreateScratch extends SfCommand { { messageId: 'lengthSuggestionBoth', output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { id: Flags.salesforceId({length: 'both', @@ -64,6 +67,7 @@ export default class EnvCreateScratch extends SfCommand { { messageId: 'lengthSuggestion15', output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { id: Flags.salesforceId({length: 15, @@ -75,6 +79,7 @@ export default class EnvCreateScratch extends SfCommand { { messageId: 'lengthSuggestion18', output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { id: Flags.salesforceId({length: 18, @@ -87,6 +92,7 @@ export default class EnvCreateScratch extends SfCommand { }, ], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { id: Flags.salesforceId({ @@ -105,6 +111,7 @@ export default class EnvCreateScratch extends SfCommand { { messageId: 'typeSuggestion', output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { 'some-flag': Flags.salesforceId({startsWith: '000', @@ -118,6 +125,7 @@ export default class EnvCreateScratch extends SfCommand { }, ], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { 'some-flag': Flags.salesforceId({ @@ -137,6 +145,7 @@ export default class EnvCreateScratch extends SfCommand { { messageId: 'lengthSuggestionBoth', output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: Flags.salesforceId({length: 'both', @@ -149,6 +158,7 @@ export default class EnvCreateScratch extends SfCommand { { messageId: 'lengthSuggestion15', output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: Flags.salesforceId({length: 15, @@ -161,6 +171,7 @@ export default class EnvCreateScratch extends SfCommand { { messageId: 'lengthSuggestion18', output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: Flags.salesforceId({length: 18, @@ -174,6 +185,7 @@ export default class EnvCreateScratch extends SfCommand { }, ], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: Flags.salesforceId({ diff --git a/test/rules/migration/encourageAliasDeprecation.test.ts b/test/rules/migration/encourageAliasDeprecation.test.ts index d02f5fcc..c46ab586 100644 --- a/test/rules/migration/encourageAliasDeprecation.test.ts +++ b/test/rules/migration/encourageAliasDeprecation.test.ts @@ -19,6 +19,7 @@ ruleTester.run('encourageAliasDeprecation', encourageAliasDeprecation, { name: 'alias with deprecation', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly aliases = ['foo']; public static readonly deprecateAliases = true; @@ -28,6 +29,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'Not in commands dir', filename: path.normalize('foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly aliases = ['foo']; }`, @@ -36,6 +38,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'flag alias with deprecation', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly flags = { foo: Flags.string({ @@ -58,6 +61,7 @@ export default class EnvCreateScratch extends SfCommand { { messageId: 'command', output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly deprecateAliases = true;public static readonly aliases = ['foo']; }`, @@ -67,6 +71,7 @@ export default class EnvCreateScratch extends SfCommand { ], output: null, code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly aliases = ['foo']; }`, @@ -81,6 +86,7 @@ export default class EnvCreateScratch extends SfCommand { { messageId: 'flag', output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly flags = { foo: Flags.string({ @@ -93,6 +99,7 @@ export default class EnvCreateScratch extends SfCommand { }, ], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly flags = { foo: Flags.string({ diff --git a/test/rules/migration/no-builtin-flags.test.ts b/test/rules/migration/no-builtin-flags.test.ts index 28eb584c..9a489b7c 100644 --- a/test/rules/migration/no-builtin-flags.test.ts +++ b/test/rules/migration/no-builtin-flags.test.ts @@ -19,6 +19,7 @@ ruleTester.run('noBuiltinFlags', noBuiltinFlags, { name: 'flags without json', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { verbose: Flags.boolean({ @@ -33,6 +34,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'not in command directory', filename: path.normalize('foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { verbose: Flags.builtin({}), @@ -48,6 +50,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'message' }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { verbose: Flags.builtin({ @@ -57,6 +60,7 @@ export default class EnvCreateScratch extends SfCommand { } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { verbose: Flags.boolean({ @@ -71,6 +75,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'message' }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { verbose: Flags.builtin(), @@ -78,6 +83,7 @@ export default class EnvCreateScratch extends SfCommand { } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { verbose: Flags.boolean(), diff --git a/test/rules/migration/no-deprecated-properties.test.ts b/test/rules/migration/no-deprecated-properties.test.ts index 0fa92747..d3a5af53 100644 --- a/test/rules/migration/no-deprecated-properties.test.ts +++ b/test/rules/migration/no-deprecated-properties.test.ts @@ -19,6 +19,7 @@ ruleTester.run('noDeprecatedProperties', noDeprecatedProperties, { name: 'sf flags', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly flags = { foo: Flags.boolean() @@ -31,6 +32,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'Not in commands dir', filename: path.normalize('foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly args = true; } @@ -45,11 +47,13 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'property', data: { property: 'varargs' } }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly varargs = 'foo'; public static ok = true; }`, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static ok = true; @@ -63,12 +67,14 @@ export default class EnvCreateScratch extends SfCommand { { messageId: 'property', data: { property: 'supportsDevhubUsername' } }, ], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly varargs = true; public static readonly supportsDevhubUsername = true; public static readonly requiresProject = true; }`, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { diff --git a/test/rules/migration/no-filepath-flags.test.ts b/test/rules/migration/no-filepath-flags.test.ts index 8f49ea27..d96385da 100644 --- a/test/rules/migration/no-filepath-flags.test.ts +++ b/test/rules/migration/no-filepath-flags.test.ts @@ -19,6 +19,7 @@ ruleTester.run('noFilepathFlags', noFilepathFlags, { name: 'filepath flag', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { verbose: Flags.file({ @@ -33,6 +34,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'not in command directory', filename: path.normalize('foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { verbose: Flags.filepath({}), @@ -48,6 +50,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'message' }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { verbose: Flags.filepath({ @@ -57,6 +60,7 @@ export default class EnvCreateScratch extends SfCommand { } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { verbose: Flags.file({ diff --git a/test/rules/migration/no-id-flags.test.ts b/test/rules/migration/no-id-flags.test.ts index 63f8b577..bf039f03 100644 --- a/test/rules/migration/no-id-flags.test.ts +++ b/test/rules/migration/no-id-flags.test.ts @@ -19,6 +19,7 @@ ruleTester.run('noIdFlags', noIdFlags, { name: 'salesforceId flag', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { verbose: Flags.salesforceId({ @@ -33,6 +34,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'not in command directory', filename: path.normalize('foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { verbose: Flags.id({}), @@ -48,6 +50,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'message' }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { verbose: Flags.id({ @@ -57,6 +60,7 @@ export default class EnvCreateScratch extends SfCommand { } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { verbose: Flags.salesforceId({ diff --git a/test/rules/migration/no-number-flags.test.ts b/test/rules/migration/no-number-flags.test.ts index d20da528..cf2048f1 100644 --- a/test/rules/migration/no-number-flags.test.ts +++ b/test/rules/migration/no-number-flags.test.ts @@ -19,6 +19,7 @@ ruleTester.run('noNumberFlags', noNumberFlags, { name: 'integer flag', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { verbose: Flags.integer({ @@ -33,6 +34,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'not in command directory', filename: path.normalize('foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { verbose: Flags.integer({}), @@ -48,6 +50,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'message' }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { verbose: Flags.number({ @@ -57,6 +60,7 @@ export default class EnvCreateScratch extends SfCommand { } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { verbose: Flags.integer({ diff --git a/test/rules/migration/no-this-flags.test.ts b/test/rules/migration/no-this-flags.test.ts index 769e863e..b58098a4 100644 --- a/test/rules/migration/no-this-flags.test.ts +++ b/test/rules/migration/no-this-flags.test.ts @@ -19,6 +19,7 @@ ruleTester.run('noThisFlags', noThisFlags, { name: 'Custom Type', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: flags.string({ char: 'f', description: 'foo flag' }), @@ -34,6 +35,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'Not in commands dir', filename: path.normalize('foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: flags.string({ char: 'f', description: 'foo flag' }), @@ -52,6 +54,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'noThisFlags' }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: flags.string({ char: 'f', description: 'foo flag' }), @@ -71,6 +74,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'instanceProp' }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: flags.string({ char: 'f', description: 'foo flag' }), @@ -83,6 +87,7 @@ export default class EnvCreateScratch extends SfCommand { } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: flags.string({ char: 'f', description: 'foo flag' }), @@ -100,6 +105,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'noThisFlags' }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: flags.string({ char: 'f', description: 'foo flag' }), @@ -111,6 +117,7 @@ export default class EnvCreateScratch extends SfCommand { } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: flags.string({ char: 'f', description: 'foo flag' }), diff --git a/test/rules/migration/no-this-org.test.ts b/test/rules/migration/no-this-org.test.ts index d430294a..0cda40a2 100644 --- a/test/rules/migration/no-this-org.test.ts +++ b/test/rules/migration/no-this-org.test.ts @@ -19,6 +19,7 @@ ruleTester.run('noThisOrg', noThisOrg, { name: 'org from flags', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { 'target-org': Flags.requiredOrgFlag(), @@ -34,6 +35,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'top-level org prop', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { private org: Org public static flags = { @@ -54,6 +56,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'setThisOrg' }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { private org: Org; public static flags = { @@ -66,6 +69,7 @@ export default class EnvCreateScratch extends SfCommand { } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { private org: Org; public static flags = { @@ -88,6 +92,7 @@ export default class EnvCreateScratch extends SfCommand { { messageId: 'useFlags', output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { 'target-org': Flags.requiredOrgFlag(), @@ -102,6 +107,7 @@ export default class EnvCreateScratch extends SfCommand { { messageId: 'instanceProp', output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { 'target-org': Flags.requiredOrgFlag(), @@ -118,6 +124,7 @@ public async run(): Promise { }, ], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { 'target-org': Flags.requiredOrgFlag(), diff --git a/test/rules/migration/no-this-ux.test.ts b/test/rules/migration/no-this-ux.test.ts index be171562..d21b6275 100644 --- a/test/rules/migration/no-this-ux.test.ts +++ b/test/rules/migration/no-this-ux.test.ts @@ -19,6 +19,7 @@ ruleTester.run('noThisUx', noThisUx, { name: 'Custom Type', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { this.log('hi') @@ -31,6 +32,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'Not in commands dir', filename: path.normalize('foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { this.ux.log('hi') @@ -46,6 +48,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'message' }, { messageId: 'message' }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { this.ux.log('ui'); @@ -54,6 +57,7 @@ export default class EnvCreateScratch extends SfCommand { } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { this.log('ui'); @@ -67,6 +71,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'spinner' }, { messageId: 'spinner' }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { this.ux.startSpinner('go'); @@ -74,6 +79,7 @@ export default class EnvCreateScratch extends SfCommand { } }`, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { this.spinner.start('go'); @@ -86,12 +92,14 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'message' }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { this.ux.logJson('blah'); } }`, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { this.styledJSON('blah'); diff --git a/test/rules/migration/no-time-flags.test.ts b/test/rules/migration/no-time-flags.test.ts index 13e0453e..4348cea4 100644 --- a/test/rules/migration/no-time-flags.test.ts +++ b/test/rules/migration/no-time-flags.test.ts @@ -19,6 +19,7 @@ ruleTester.run('noTimeFlags', noTimeFlags, { name: 'duration flag', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { wait: Flags.duration({ @@ -37,6 +38,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'not in command directory', filename: path.normalize('foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { wait: Flags.minutes({ @@ -55,6 +57,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'message', data: { time: 'minutes' } }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { wait: Flags.minutes({ @@ -66,6 +69,7 @@ export default class EnvCreateScratch extends SfCommand { } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { wait: Flags.duration({ unit: 'minutes', diff --git a/test/rules/migration/no-username-properties.test.ts b/test/rules/migration/no-username-properties.test.ts index f205048c..15743377 100644 --- a/test/rules/migration/no-username-properties.test.ts +++ b/test/rules/migration/no-username-properties.test.ts @@ -20,6 +20,7 @@ ruleTester.run('noUsernameProperties', noUsernameProperties, { filename: path.normalize('src/commands/foo.ts'), code: ` import { SfCommand, Flags, requiredOrgFlagWithDeprecations } from '@salesforce/sf-plugins-core'; +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly flags = { 'target-org': Flags.requiredOrgFlag(), @@ -32,6 +33,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'Not in commands dir', filename: path.normalize('foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly requiresUsername = true; } @@ -46,6 +48,7 @@ export default class EnvCreateScratch extends SfCommand { errors: [{ messageId: 'requires' }, { messageId: 'requires' }], code: ` import {Flags, SfCommand} from '@salesforce/sf-plugins-core'; +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly requiresUsername = true; public static readonly flags = { @@ -54,6 +57,7 @@ export default class EnvCreateScratch extends SfCommand { }`, output: ` import {Flags, SfCommand, requiredOrgFlagWithDeprecations} from '@salesforce/sf-plugins-core'; +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly requiresUsername = true; public static readonly flags = {'target-org': requiredOrgFlagWithDeprecations, @@ -67,6 +71,7 @@ export default class EnvCreateScratch extends SfCommand { errors: [{ messageId: 'requires' }], output: ` import {Flags, SfCommand, requiredOrgFlagWithDeprecations} from '@salesforce/sf-plugins-core'; +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly flags = {'target-org': requiredOrgFlagWithDeprecations, @@ -75,6 +80,7 @@ export default class EnvCreateScratch extends SfCommand { }`, code: ` import {Flags, SfCommand, requiredOrgFlagWithDeprecations} from '@salesforce/sf-plugins-core'; +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly requiresUsername = true; public static readonly flags = {'target-org': requiredOrgFlagWithDeprecations, @@ -90,6 +96,7 @@ export default class EnvCreateScratch extends SfCommand { code: ` import {foo} from 'bar'; import {Flags, SfCommand} from '@salesforce/sf-plugins-core'; +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly supportsUsername = true; public static readonly flags = { @@ -99,6 +106,7 @@ export default class EnvCreateScratch extends SfCommand { output: ` import {foo} from 'bar'; import {Flags, SfCommand, optionalOrgFlagWithDeprecations} from '@salesforce/sf-plugins-core'; +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly supportsUsername = true; public static readonly flags = {'target-org': optionalOrgFlagWithDeprecations, @@ -112,6 +120,7 @@ export default class EnvCreateScratch extends SfCommand { errors: [{ messageId: 'supports' }], output: ` import {Flags, SfCommand, optionalOrgFlagWithDeprecations} from '@salesforce/sf-plugins-core'; +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly flags = {'target-org': optionalOrgFlagWithDeprecations, @@ -120,6 +129,7 @@ export default class EnvCreateScratch extends SfCommand { }`, code: ` import {Flags, SfCommand, optionalOrgFlagWithDeprecations} from '@salesforce/sf-plugins-core'; +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly supportsUsername = true; public static readonly flags = {'target-org': optionalOrgFlagWithDeprecations, @@ -133,6 +143,7 @@ export default class EnvCreateScratch extends SfCommand { errors: [{ messageId: 'requiresHub' }, { messageId: 'requiresHub' }], code: ` import {Flags, SfCommand} from '@salesforce/sf-plugins-core'; +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly requiresDevhubUsername = true; public static readonly flags = { @@ -141,6 +152,7 @@ export default class EnvCreateScratch extends SfCommand { }`, output: ` import {Flags, SfCommand, requiredHubFlagWithDeprecations} from '@salesforce/sf-plugins-core'; +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly requiresDevhubUsername = true; public static readonly flags = {'target-dev-hub': requiredHubFlagWithDeprecations, @@ -154,6 +166,7 @@ export default class EnvCreateScratch extends SfCommand { errors: [{ messageId: 'requiresHub' }], output: ` import {Flags, SfCommand, requiredHubFlagWithDeprecations} from '@salesforce/sf-plugins-core'; +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly flags = {'target-dev-hub': requiredHubFlagWithDeprecations, @@ -162,6 +175,7 @@ export default class EnvCreateScratch extends SfCommand { }`, code: ` import {Flags, SfCommand, requiredHubFlagWithDeprecations} from '@salesforce/sf-plugins-core'; +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly requiresDevhubUsername = true; public static readonly flags = {'target-dev-hub': requiredHubFlagWithDeprecations, diff --git a/test/rules/migration/sfdx-flags-property.test.ts b/test/rules/migration/sfdx-flags-property.test.ts index 1ffcefa8..add0e557 100644 --- a/test/rules/migration/sfdx-flags-property.test.ts +++ b/test/rules/migration/sfdx-flags-property.test.ts @@ -19,6 +19,7 @@ ruleTester.run('sfdxFlagsProperty', sfdxFlagsProperty, { name: 'sf flags', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly flags = { foo: Flags.boolean() @@ -31,6 +32,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'Not in commands dir', filename: path.normalize('foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flagsConfig: FlagsConfig = { foo: flags.boolean() @@ -47,6 +49,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'flagsConfig' }, { messageId: 'flagsConfigType' }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flagsConfig: FlagsConfig = { foo: flags.boolean() @@ -54,6 +57,7 @@ export default class EnvCreateScratch extends SfCommand { } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags: FlagsConfig = { foo: flags.boolean() @@ -67,6 +71,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'flagsConfigType' }], output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: flags.boolean() @@ -74,6 +79,7 @@ export default class EnvCreateScratch extends SfCommand { } `, code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags: FlagsConfig = { foo: flags.boolean() diff --git a/test/rules/migration/should-parse-flags.test.ts b/test/rules/migration/should-parse-flags.test.ts index b16dc236..c903eeb5 100644 --- a/test/rules/migration/should-parse-flags.test.ts +++ b/test/rules/migration/should-parse-flags.test.ts @@ -18,6 +18,7 @@ ruleTester.run('shouldParseFlags', shouldParseFlags, { name: 'Parses as expected', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: Flags.boolean() @@ -32,6 +33,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'No flags to parse', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise {} } @@ -41,6 +43,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'Not in commands dir', filename: path.normalize('foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: Flags.boolean() @@ -56,6 +59,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'summary' }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: Flags.boolean() @@ -66,6 +70,7 @@ export default class EnvCreateScratch extends SfCommand { } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: Flags.boolean() diff --git a/test/rules/migration/use-sf-command-flags.test.ts b/test/rules/migration/use-sf-command-flags.test.ts index 3abf4053..8ddebff4 100644 --- a/test/rules/migration/use-sf-command-flags.test.ts +++ b/test/rules/migration/use-sf-command-flags.test.ts @@ -19,6 +19,7 @@ ruleTester.run('useSfCommandFlags', useSfCommandFlags, { name: 'sf flags', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly flags = { foo: Flags.boolean() @@ -31,6 +32,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'Not in commands dir', filename: path.normalize('foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flagsConfig: FlagsConfig = { foo: flags.boolean() @@ -46,6 +48,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'message' }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: flags.boolean() @@ -53,6 +56,7 @@ export default class EnvCreateScratch extends SfCommand { } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: Flags.boolean() diff --git a/test/rules/no-args-parse-without-strict-false.test.ts b/test/rules/no-args-parse-without-strict-false.test.ts index 56428975..bad283d9 100644 --- a/test/rules/no-args-parse-without-strict-false.test.ts +++ b/test/rules/no-args-parse-without-strict-false.test.ts @@ -19,6 +19,7 @@ ruleTester.run('noArgsParseWithoutStrictFalse', noArgsParseWithoutStrictFalse, { name: 'Parses as expected', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly strict = false; public async run(): Promise { @@ -31,6 +32,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'No args parsed', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { const {flags} = await this.parse(EnvCreateScratch); @@ -42,6 +44,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'Not in commands dir', filename: path.normalize('foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { const {flags, args, argv} = await this.parse(EnvCreateScratch); @@ -67,6 +70,7 @@ export default class EnvCreateScratch extends SomethingElse { public async run(): Promise { const {flags, args, argv} = await this.parse(EnvCreateScratch); @@ -74,6 +78,7 @@ export default class EnvCreateScratch extends SfCommand { } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly strict = false;public async run(): Promise { const {flags, args, argv} = await this.parse(EnvCreateScratch); @@ -86,6 +91,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'summary' }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly strict = true; public async run(): Promise { @@ -94,6 +100,7 @@ export default class EnvCreateScratch extends SfCommand { } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly strict = false; public async run(): Promise { diff --git a/test/rules/no-classes-in-command-return-type.test.ts b/test/rules/no-classes-in-command-return-type.test.ts index c84773cb..1ad5ea4c 100644 --- a/test/rules/no-classes-in-command-return-type.test.ts +++ b/test/rules/no-classes-in-command-return-type.test.ts @@ -23,6 +23,7 @@ ruleTester.run('noClassesInCommandReturnType', noClassesInCommandReturnType, { name: 'return a type', code: ` export type FooReturn = { foo: string } +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { return {foo: 'bar'} @@ -34,6 +35,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'return an interface', code: ` export interface FooReturn { foo: string } +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { return {foo: 'bar'} @@ -48,6 +50,7 @@ export default class EnvCreateScratch extends SfCommand { errors: [{ messageId: 'summary' }], code: ` export class FooReturn {} +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { return new Foo(); @@ -64,6 +67,7 @@ export class FooClass {} export interface FooReturn { foo: FooClass } +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { return { @@ -82,6 +86,7 @@ export class FooClass {} export type FooReturn = { foo: FooClass } +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { return { @@ -100,6 +105,7 @@ import { Messages } from '@salesforce/core'; export type FooReturn = { foo: Messages } +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { return { diff --git a/test/rules/no-default-depends-on-flags.test.ts b/test/rules/no-default-depends-on-flags.test.ts index 124bf81e..f3acce50 100644 --- a/test/rules/no-default-depends-on-flags.test.ts +++ b/test/rules/no-default-depends-on-flags.test.ts @@ -19,6 +19,8 @@ ruleTester.run('noDefaultDependsOnFlags', noDefaultDependsOnFlags, { name: 'does not use default and dependsOn', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -33,6 +35,8 @@ export default class EnvCreateScratch extends SfCommand { name: 'does not block flag with a default value depending on another flag with a default value', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -58,6 +62,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'message' }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { json: Flags.boolean({ @@ -75,6 +80,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'message' }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ diff --git a/test/rules/no-duplicate-short-chars.test.ts b/test/rules/no-duplicate-short-chars.test.ts index 8e54f8a7..fbcce161 100644 --- a/test/rules/no-duplicate-short-chars.test.ts +++ b/test/rules/no-duplicate-short-chars.test.ts @@ -19,6 +19,7 @@ ruleTester.run('no duplicate short characters', noDuplicateShortCharacters, { name: 'all flags use different chars', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -39,6 +40,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'some flags have no char', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -56,6 +58,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'not in commands dir', filename: path.normalize('src/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -81,6 +84,7 @@ export default class EnvCreateScratch extends SfCommand { ], filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: Flags.string({ @@ -103,6 +107,7 @@ export default class EnvCreateScratch extends SfCommand { ], filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: Flags.string({ @@ -126,6 +131,7 @@ export default class EnvCreateScratch extends SfCommand { ], filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: Flags.string({ @@ -150,6 +156,7 @@ export default class EnvCreateScratch extends SfCommand { ], filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: Flags.string({ @@ -174,6 +181,7 @@ export default class EnvCreateScratch extends SfCommand { ], filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { foo: Flags.string({ diff --git a/test/rules/no-hyphen-aliases.test.ts b/test/rules/no-hyphen-aliases.test.ts index 2faee32a..f9994cc1 100644 --- a/test/rules/no-hyphen-aliases.test.ts +++ b/test/rules/no-hyphen-aliases.test.ts @@ -19,6 +19,7 @@ ruleTester.run('no hyphen aliases', noHyphenAliases, { name: 'aliases without hyphens', filename: path.normalize('src/commands/foo/bar/baz.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -40,6 +41,7 @@ export default class EnvCreateScratch extends SfCommand { ], filename: path.normalize('src/commands/foo/bar/baz.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -50,6 +52,7 @@ export default class EnvCreateScratch extends SfCommand { } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -69,6 +72,7 @@ export default class EnvCreateScratch extends SfCommand { ], filename: path.normalize('src/commands/foo/bar/baz.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -79,6 +83,7 @@ export default class EnvCreateScratch extends SfCommand { } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -102,6 +107,7 @@ export default class EnvCreateScratch extends SfCommand { ], filename: path.normalize('src/commands/foo/bar/baz.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -112,6 +118,7 @@ export default class EnvCreateScratch extends SfCommand { } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ diff --git a/test/rules/no-json-flag.test.ts b/test/rules/no-json-flag.test.ts index c836b342..7615b9e6 100644 --- a/test/rules/no-json-flag.test.ts +++ b/test/rules/no-json-flag.test.ts @@ -19,6 +19,7 @@ ruleTester.run('jsonFlag', jsonFlag, { name: 'flags without json', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -33,6 +34,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'not in command directory', filename: path.normalize('foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { json: Flags.boolean({}), @@ -48,6 +50,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'message' }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { json: Flags.boolean({ diff --git a/test/rules/no-split-examples.test.ts b/test/rules/no-split-examples.test.ts index a47b6d5b..9026b040 100644 --- a/test/rules/no-split-examples.test.ts +++ b/test/rules/no-split-examples.test.ts @@ -18,6 +18,7 @@ ruleTester.run('noSplitExamples', noSplitExamples, { { name: 'correct examples with getMessages', code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly examples = messages.getMessages('examples') } @@ -35,6 +36,7 @@ export default class EnvCreateScratch extends somethingElse { public static readonly examples = message.getMessage('examples').split(EOL) } @@ -51,11 +53,13 @@ export default class EnvCreateScratch extends SfCommand { }, ], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly examples = message.getMessage('examples').split(EOL); } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly examples = message.getMessages('examples'); } diff --git a/test/rules/no-uneccessary-properties.test.ts b/test/rules/no-uneccessary-properties.test.ts index 5cbaed62..a8b926a3 100644 --- a/test/rules/no-uneccessary-properties.test.ts +++ b/test/rules/no-uneccessary-properties.test.ts @@ -18,6 +18,7 @@ ruleTester.run('noUnnecessaryProperties', noUnnecessaryProperties, { { name: 'correct example for a command', code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static requiresProject = true public static notInTargetList = false @@ -27,6 +28,7 @@ export default class EnvCreateScratch extends SfCommand { { name: 'other static properties with no value', code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static org: Org } @@ -35,6 +37,7 @@ export default class EnvCreateScratch extends SfCommand { { name: 'populated aliases for a command', code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static aliases = ['foo'] } @@ -52,6 +55,7 @@ export default class EnvCreateScratch extends somethingElse { public static requiresProject = false } @@ -69,11 +73,13 @@ export default class EnvCreateScratch extends SfCommand { }, ], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly aliases = [] } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { } @@ -94,6 +100,7 @@ export default class EnvCreateScratch extends SfCommand { }, ], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static hidden = false public static requiresProject = false @@ -101,6 +108,7 @@ export default class EnvCreateScratch extends SfCommand { } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { diff --git a/test/rules/no-unnecessary-aliases.test.ts b/test/rules/no-unnecessary-aliases.test.ts index 5bf4a8e7..8aaaaad8 100644 --- a/test/rules/no-unnecessary-aliases.test.ts +++ b/test/rules/no-unnecessary-aliases.test.ts @@ -19,6 +19,7 @@ ruleTester.run('no unnecessary aliases', noUnnecessaryAliases, { name: 'aliases are not a permutation', filename: path.normalize('src/commands/foo/bar/baz.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly aliases = ['bar:baz', 'bar:qux']; } @@ -29,6 +30,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'not in commands dir', filename: path.normalize('src/shared/foo/bar/baz.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly aliases = ['foo:baz:bar']; } @@ -45,11 +47,13 @@ export default class EnvCreateScratch extends SfCommand { ], filename: path.normalize('src/commands/foo/bar/baz.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly aliases = ['bar:baz:foo', 'bar:qux']; } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly aliases = [ 'bar:qux']; } @@ -64,11 +68,13 @@ export default class EnvCreateScratch extends SfCommand { ], filename: path.normalize('src/commands/foo/bar/baz.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly aliases = ['bar:baz:foo']; } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { } @@ -86,11 +92,13 @@ export default class EnvCreateScratch extends SfCommand { ], filename: path.normalize('src/commands/foo/bar/baz.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly aliases = ['bar:baz:foo', 'baz:bar:foo']; } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly aliases = [ ]; } diff --git a/test/rules/only-extend-sfCommand.test.ts b/test/rules/only-extend-sfCommand.test.ts index d16b8cfe..57fdd185 100644 --- a/test/rules/only-extend-sfCommand.test.ts +++ b/test/rules/only-extend-sfCommand.test.ts @@ -19,6 +19,7 @@ ruleTester.run('only-extend-SfCommand', onlyExtendSfCommand, { name: 'extends SfCommand directly', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static flags = { alias: Flags.string({ @@ -28,6 +29,23 @@ export default class EnvCreateScratch extends SfCommand { } } +`, + }, + { + name: 'extends SfCommand directly, import alias', + filename: path.normalize('src/commands/foo.ts'), + code: ` +import {SfCommand as SfCmd} from '@salesforce/sf-plugins-core'; + +export default class EnvCreateScratch extends SfCmd { + public static flags = { + alias: Flags.string({ + summary: 'foo', + char: 'a' + }) + } +} + `, }, { diff --git a/test/rules/read-only-properties.test.ts b/test/rules/read-only-properties.test.ts index 2b8fdcf7..fe4a44e0 100644 --- a/test/rules/read-only-properties.test.ts +++ b/test/rules/read-only-properties.test.ts @@ -18,6 +18,7 @@ ruleTester.run('readOnlyProperties', readOnlyProperties, { { name: 'correct example for a command', code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly summary = 'foo' public static readonly examples = 'baz' @@ -36,6 +37,7 @@ export default class EnvCreateScratch extends somethingElse { public static description = 'bar' public static summary = 'baz' @@ -58,12 +60,14 @@ export default class EnvCreateScratch extends SfCommand { }, ], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static description = 'bar' public static summary = 'baz' } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly description = 'bar' public static readonly summary = 'baz' @@ -85,12 +89,14 @@ export default class EnvCreateScratch extends SfCommand { }, ], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { protected static readonly description = 'bar' protected static readonly summary = 'baz' } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly description = 'bar' public static readonly summary = 'baz' @@ -107,6 +113,7 @@ export default class EnvCreateScratch extends SfCommand { }, ], output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public static readonly aliases = 'bar' public static readonly flags = { @@ -115,6 +122,7 @@ export default class EnvCreateScratch extends SfCommand { } `, code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { protected static readonly aliases = 'bar' public static readonly flags = { @@ -133,6 +141,7 @@ export default class EnvCreateScratch extends SfCommand { }, ], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { protected static aliases = 'bar' public static readonly flags = { @@ -141,6 +150,7 @@ export default class EnvCreateScratch extends SfCommand { } `, output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { protected static readonly aliases = 'bar' public static readonly flags = { diff --git a/test/rules/run-matches-class-type.test.ts b/test/rules/run-matches-class-type.test.ts index f97b0098..79c62cdf 100644 --- a/test/rules/run-matches-class-type.test.ts +++ b/test/rules/run-matches-class-type.test.ts @@ -19,6 +19,7 @@ ruleTester.run('runMatchesClassType', runMatchesClassType, { name: 'Custom Type', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { console.log('hi') @@ -31,6 +32,7 @@ export default class EnvCreateScratch extends SfCommand { name: 'standard type', filename: path.normalize('foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { console.log('hi') @@ -46,6 +48,7 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'summary' }, { messageId: 'summary' }], code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { console.log('hi') @@ -59,12 +62,14 @@ export default class EnvCreateScratch extends SfCommand { filename: path.normalize('src/commands/foo.ts'), errors: [{ messageId: 'summary' }], output: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { console.log('hi') } }`, code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class EnvCreateScratch extends SfCommand { public async run(): Promise { console.log('hi') diff --git a/test/rules/spread-base-flags.test.ts b/test/rules/spread-base-flags.test.ts index 52ba6336..dbcea9f5 100644 --- a/test/rules/spread-base-flags.test.ts +++ b/test/rules/spread-base-flags.test.ts @@ -67,6 +67,7 @@ export default class Top extends Base { name: 'does not apply to SfCommand.flags', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class Top extends SfCommand { public static flags = { alias: Flags.string({ @@ -81,6 +82,7 @@ export default class Top extends SfCommand { name: 'does not apply to SfCommand baseFlags', filename: path.normalize('src/commands/foo.ts'), code: ` +import {SfCommand} from '@salesforce/sf-plugins-core'; export default class Top extends SfCommand { public static baseFlags = { alias: Flags.string({