-
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: autofix this.flags inside run method
- Loading branch information
Showing
3 changed files
with
148 additions
and
35 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,95 @@ | ||
/* | ||
* 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 path from 'path'; | ||
import { ESLintUtils } from '@typescript-eslint/utils'; | ||
import { noThisFlags } from '../../../src/rules/migration/noThisFlags'; | ||
|
||
const ruleTester = new ESLintUtils.RuleTester({ | ||
parser: '@typescript-eslint/parser', | ||
}); | ||
|
||
ruleTester.run('noThisFlags', noThisFlags, { | ||
valid: [ | ||
{ | ||
name: 'Custom Type', | ||
filename: path.normalize('src/commands/foo.ts'), | ||
code: ` | ||
export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> { | ||
public static flags = { | ||
foo: flags.string({ char: 'f', description: 'foo flag' }), | ||
} | ||
public async run(): Promise<ScratchCreateResponse> { | ||
const {flags} = await this.parse(EnvCreateScratch) | ||
console.log(flags.foo) | ||
} | ||
} | ||
`, | ||
}, | ||
{ | ||
name: 'Not in commands dir', | ||
filename: path.normalize('foo.ts'), | ||
code: ` | ||
export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> { | ||
public static flags = { | ||
foo: flags.string({ char: 'f', description: 'foo flag' }), | ||
} | ||
public async run(): Promise<ScratchCreateResponse> { | ||
const {flags} = await this.parse(EnvCreateScratch) | ||
console.log(flags.foo) | ||
} | ||
} | ||
`, | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
name: 'uses this.flags', | ||
filename: path.normalize('src/commands/foo.ts'), | ||
errors: [{ messageId: 'noThisFlags' }], | ||
code: ` | ||
export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> { | ||
public static flags = { | ||
foo: flags.string({ char: 'f', description: 'foo flag' }), | ||
} | ||
public async run(): Promise<ScratchCreateResponse> { | ||
const {flags} = await this.parse(EnvCreateScratch) | ||
} | ||
public otherMethod() { | ||
console.log(this.flags.foo) | ||
} | ||
} | ||
`, | ||
}, | ||
{ | ||
name: 'uses this.flags in run (autofix)', | ||
filename: path.normalize('src/commands/foo.ts'), | ||
errors: [{ messageId: 'noThisFlags' }], | ||
code: ` | ||
export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> { | ||
public static flags = { | ||
foo: flags.string({ char: 'f', description: 'foo flag' }), | ||
} | ||
public async run(): Promise<ScratchCreateResponse> { | ||
const {flags} = await this.parse(EnvCreateScratch) | ||
console.log(this.flags.foo) | ||
} | ||
} | ||
`, | ||
output: ` | ||
export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> { | ||
public static flags = { | ||
foo: flags.string({ char: 'f', description: 'foo flag' }), | ||
} | ||
public async run(): Promise<ScratchCreateResponse> { | ||
const {flags} = await this.parse(EnvCreateScratch) | ||
console.log(flags.foo) | ||
} | ||
} | ||
`, | ||
}, | ||
], | ||
}); |