-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: only apply in /commands folder
- Loading branch information
Showing
12 changed files
with
311 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2020, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
import { ESLintUtils } from '@typescript-eslint/utils'; | ||
import { ancestorsContainsSfCommand, isInCommandDirectory } from '../shared/commands'; | ||
import { flagPropertyIsNamed, isFlag } from '../shared/flags'; | ||
|
||
export const flagSummary = ESLintUtils.RuleCreator.withoutDocs({ | ||
meta: { | ||
docs: { | ||
description: 'Enforce that flags have a summary property', | ||
recommended: 'error', | ||
}, | ||
messages: { | ||
message: 'Flags should have a summary property', | ||
}, | ||
type: 'problem', | ||
schema: [], | ||
}, | ||
defaultOptions: [], | ||
create(context) { | ||
return { | ||
Property(node): void { | ||
if (isInCommandDirectory(context) && isFlag(node) && ancestorsContainsSfCommand(context.getAncestors())) { | ||
if ( | ||
node.value?.type === 'CallExpression' && | ||
node.value.arguments?.[0]?.type === 'ObjectExpression' && | ||
!node.value.arguments[0].properties.some( | ||
(property) => property.type === 'Property' && flagPropertyIsNamed(property, 'summary') | ||
) | ||
) { | ||
context.report({ | ||
node, | ||
messageId: 'message', | ||
}); | ||
} | ||
} | ||
}, | ||
}; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (c) 2020, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import { sep } from 'path'; | ||
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils'; | ||
import { RuleContext } from '@typescript-eslint/utils/dist/ts-eslint'; | ||
|
||
export const isClassDeclaration = (node: TSESTree.Node): node is TSESTree.ClassDeclaration => | ||
node.type === AST_NODE_TYPES.ClassDeclaration; | ||
|
||
export const ancestorsContainsSfCommand = (ancestors: TSESTree.Node[]): boolean => | ||
ancestors.some((a) => isClassDeclaration(a) && extendsSfCommand(a)); | ||
|
||
export const extendsSfCommand = (node: TSESTree.ClassDeclaration): boolean => | ||
node.superClass?.type === AST_NODE_TYPES.Identifier && node.superClass.name === 'SfCommand'; | ||
|
||
export const getClassPropertyIdentifierName = (node: TSESTree.ClassElement): string => | ||
node.type === 'PropertyDefinition' && node.key.type === AST_NODE_TYPES.Identifier ? node.key.name : undefined; | ||
|
||
// we don't care what the types are, really any context will do | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export const isInCommandDirectory = (context: RuleContext<any, any>): boolean => { | ||
return context.getPhysicalFilename().includes(`${sep}commands${sep}`); // not an sfCommand | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.