-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
380 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* 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 { AST_NODE_TYPES } from '@typescript-eslint/utils'; | ||
import { ancestorsContainsSfCommand, isInCommandDirectory } from '../../shared/commands'; | ||
|
||
const spinnerMigration = new Map([ | ||
['startSpinner', 'this.spinner.start'], | ||
['stopSpinner', 'this.spinner.stop'], | ||
]); | ||
|
||
export const noThisUx = ESLintUtils.RuleCreator.withoutDocs({ | ||
meta: { | ||
docs: { | ||
description: 'SfCommand does not have a ux property', | ||
recommended: 'error', | ||
}, | ||
messages: { | ||
message: 'SfCommand does not have a ux property. Use methods from this like this.log() or this.table()', | ||
spinner: 'SfCommand does not have a ux.spinner. Use this.spinner.start() or this.spinner.stop()', | ||
}, | ||
type: 'problem', | ||
schema: [], | ||
fixable: 'code', | ||
}, | ||
defaultOptions: [], | ||
create(context) { | ||
return { | ||
MemberExpression(node): void { | ||
if ( | ||
isInCommandDirectory(context) && | ||
node.type === AST_NODE_TYPES.MemberExpression && | ||
node.object?.type === AST_NODE_TYPES.MemberExpression && | ||
node.object?.object?.type === AST_NODE_TYPES.ThisExpression && | ||
node.object?.property?.type === AST_NODE_TYPES.Identifier && | ||
node.object?.property?.name === 'ux' && | ||
ancestorsContainsSfCommand(context.getAncestors()) | ||
) { | ||
// spinner cases | ||
if (node.property.type === 'Identifier' && spinnerMigration.has(node.property.name)) { | ||
// all other this.ux cases | ||
const toRemove = node; | ||
const original = node.property.name; | ||
context.report({ | ||
node, | ||
messageId: 'spinner', | ||
fix: (fixer) => { | ||
return fixer.replaceText(toRemove, spinnerMigration.get(original)); | ||
}, | ||
}); | ||
} else if (node.property.type === 'Identifier' && node.property.name === 'logJson') { | ||
// this.ux.logJson => this.styledJson | ||
const toRemove = node; | ||
context.report({ | ||
node, | ||
messageId: 'spinner', | ||
fix: (fixer) => { | ||
return fixer.replaceText(toRemove, 'this.styledJSON'); | ||
}, | ||
}); | ||
} else { | ||
// all other this.ux cases | ||
const toRemove = node.object; | ||
context.report({ | ||
node, | ||
messageId: 'message', | ||
fix: (fixer) => { | ||
return fixer.replaceText(toRemove, 'this'); | ||
}, | ||
}); | ||
} | ||
} | ||
}, | ||
}; | ||
}, | ||
}); |
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,55 @@ | ||
/* | ||
* 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 { isInCommandDirectory } from '../../shared/commands'; | ||
export const noSfdxCommandImport = ESLintUtils.RuleCreator.withoutDocs({ | ||
meta: { | ||
docs: { | ||
description: 'Change import to sfCommand', | ||
recommended: 'error', | ||
}, | ||
messages: { | ||
import: 'Use SfCommand from sf-plugins-core', | ||
superClass: 'Use SfCommand as the base class', | ||
}, | ||
type: 'problem', | ||
schema: [], | ||
fixable: 'code', | ||
}, | ||
defaultOptions: [], | ||
create(context) { | ||
return { | ||
ClassDeclaration(node): void { | ||
if (isInCommandDirectory(context)) { | ||
if (node.superClass?.type === 'Identifier' && node.superClass.name === 'SfdxCommand') { | ||
context.report({ | ||
node: node.superClass, | ||
messageId: 'superClass', | ||
fix: (fixer) => { | ||
return fixer.replaceTextRange(node.superClass.range, 'SfCommand<unknown>'); | ||
}, | ||
}); | ||
} | ||
} | ||
}, | ||
ImportDeclaration(node): void { | ||
// verify it extends SfCommand | ||
if (isInCommandDirectory(context)) { | ||
if (node.source.value === '@salesforce/command') { | ||
context.report({ | ||
node, | ||
messageId: 'import', | ||
fix: (fixer) => { | ||
return fixer.replaceText(node, "import {Flags, SfCommand} from '@salesforce/sf-plugins-core'"); | ||
}, | ||
}); | ||
} | ||
} | ||
}, | ||
}; | ||
}, | ||
}); |
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,56 @@ | ||
/* | ||
* 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'; | ||
export const sfdxFlagsProperty = ESLintUtils.RuleCreator.withoutDocs({ | ||
meta: { | ||
docs: { | ||
description: 'Change flag definitions to SfCommmand version', | ||
recommended: 'error', | ||
}, | ||
messages: { | ||
flagsConfig: 'Use public readonly static flags = {', | ||
flagsConfigType: 'The FlagsConfig type is not used by SfCommand', | ||
}, | ||
type: 'problem', | ||
schema: [], | ||
fixable: 'code', | ||
}, | ||
defaultOptions: [], | ||
create(context) { | ||
return { | ||
PropertyDefinition(node): void { | ||
if (isInCommandDirectory(context) && ancestorsContainsSfCommand(context.getAncestors())) { | ||
if (node.key.type === 'Identifier' && node.key.name === 'flagsConfig') { | ||
context.report({ | ||
node, | ||
messageId: 'flagsConfig', | ||
fix: (fixer) => { | ||
return fixer.replaceTextRange(node.key.range, 'flags'); | ||
}, | ||
}); | ||
} | ||
if ( | ||
node.key.type === 'Identifier' && | ||
node.typeAnnotation?.type === 'TSTypeAnnotation' && | ||
node.typeAnnotation.typeAnnotation?.type === 'TSTypeReference' && | ||
node.typeAnnotation.typeAnnotation.typeName?.type === 'Identifier' && | ||
node.typeAnnotation.typeAnnotation.typeName.name === 'FlagsConfig' | ||
) { | ||
context.report({ | ||
node, | ||
messageId: 'flagsConfigType', | ||
fix: (fixer) => { | ||
return fixer.remove(node.typeAnnotation); | ||
}, | ||
}); | ||
} | ||
} | ||
}, | ||
}; | ||
}, | ||
}); |
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,52 @@ | ||
/* | ||
* 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 { AST_NODE_TYPES } from '@typescript-eslint/utils'; | ||
import { ancestorsContainsSfCommand, isInCommandDirectory } from '../../shared/commands'; | ||
|
||
export const useSfCommandFlags = ESLintUtils.RuleCreator.withoutDocs({ | ||
meta: { | ||
docs: { | ||
description: 'use Flags export from sf-plugins-core', | ||
recommended: 'error', | ||
}, | ||
messages: { | ||
message: 'for SfCommand, each flag definition should use "Flags", not "flags"', | ||
}, | ||
type: 'problem', | ||
schema: [], | ||
fixable: 'code', | ||
}, | ||
defaultOptions: [], | ||
create(context) { | ||
return { | ||
Property(node): void { | ||
if ( | ||
isInCommandDirectory(context) && | ||
node.type === AST_NODE_TYPES.Property && | ||
node.value?.type === 'CallExpression' && | ||
node.value?.callee?.type === 'MemberExpression' && | ||
node.value?.callee?.object?.type === 'Identifier' && | ||
node.value?.callee?.object?.name === 'flags' && | ||
ancestorsContainsSfCommand(context.getAncestors()) | ||
) { | ||
const range = node.value.callee.object.range; | ||
context.report({ | ||
node, | ||
messageId: 'message', | ||
fix: (fixer) => { | ||
// TS isn't using the type narrowing done above. | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore, eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument | ||
return fixer.replaceTextRange(range, 'Flags'); | ||
}, | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}); |
Oops, something went wrong.