-
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
5 changed files
with
248 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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 { extendsSfCommand, getClassPropertyIdentifierName, isInCommandDirectory } from '../shared/commands'; | ||
export const commandExamples = ESLintUtils.RuleCreator.withoutDocs({ | ||
meta: { | ||
docs: { | ||
description: 'Ensure commands have a summary, description, and examples', | ||
recommended: 'error', | ||
}, | ||
messages: { | ||
example: 'Commands should have an examples property', | ||
}, | ||
type: 'problem', | ||
schema: [], | ||
}, | ||
defaultOptions: [], | ||
create(context) { | ||
return { | ||
ClassDeclaration(node): void { | ||
// verify it extends SfCommand | ||
if (isInCommandDirectory(context) && extendsSfCommand(node)) { | ||
if (!node.body.body.some((member) => getClassPropertyIdentifierName(member) === 'examples')) { | ||
context.report({ | ||
node, | ||
messageId: 'example', | ||
}); | ||
} | ||
} | ||
}, | ||
}; | ||
}, | ||
}); |
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,37 @@ | ||
/* | ||
* 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 { extendsSfCommand, getClassPropertyIdentifierName, isInCommandDirectory } from '../shared/commands'; | ||
export const commandSummary = ESLintUtils.RuleCreator.withoutDocs({ | ||
meta: { | ||
docs: { | ||
description: 'Ensure commands have a summary', | ||
recommended: 'error', | ||
}, | ||
messages: { | ||
summary: 'Commands should have a summary property', | ||
}, | ||
type: 'problem', | ||
schema: [], | ||
}, | ||
defaultOptions: [], | ||
create(context) { | ||
return { | ||
ClassDeclaration(node): void { | ||
// verify it extends SfCommand | ||
if (isInCommandDirectory(context) && extendsSfCommand(node)) { | ||
if (!node.body.body.some((member) => getClassPropertyIdentifierName(member) === 'summary')) { | ||
context.report({ | ||
node, | ||
messageId: 'summary', | ||
}); | ||
} | ||
} | ||
}, | ||
}; | ||
}, | ||
}); |
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,61 @@ | ||
/* | ||
* 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 { commandExamples } from '../../src/rules/commandExamples'; | ||
|
||
const ruleTester = new ESLintUtils.RuleTester({ | ||
parser: '@typescript-eslint/parser', | ||
}); | ||
|
||
ruleTester.run('commandExamples', commandExamples, { | ||
valid: [ | ||
// example with different chars | ||
{ | ||
code: ` | ||
export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> { | ||
public static readonly summary = 'foo' | ||
public static readonly examples = 'baz' | ||
} | ||
`, | ||
}, | ||
// not an sfCommand | ||
{ | ||
code: ` | ||
export default class EnvCreateScratch extends somethingElse<ScratchCreateResponse> { | ||
// stuff | ||
} | ||
`, | ||
}, | ||
// violation but in wrong folder | ||
{ | ||
filename: 'foo.ts', | ||
code: ` | ||
export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> { | ||
public static readonly description = 'bar' | ||
public static readonly summary = 'baz' | ||
} | ||
`, | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
filename: 'src/commands/foo.ts', | ||
errors: [ | ||
{ | ||
messageId: 'example', | ||
}, | ||
], | ||
code: ` | ||
export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> { | ||
public static readonly description = 'bar' | ||
public static readonly summary = 'baz' | ||
} | ||
`, | ||
}, | ||
], | ||
}); |
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,74 @@ | ||
/* | ||
* 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 { commandSummary } from '../../src/rules/commandSummary'; | ||
|
||
const ruleTester = new ESLintUtils.RuleTester({ | ||
parser: '@typescript-eslint/parser', | ||
}); | ||
|
||
ruleTester.run('commandSummary', commandSummary, { | ||
valid: [ | ||
{ | ||
filename: 'src/commands/foo.ts', | ||
code: | ||
// example with different chars | ||
` | ||
export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> { | ||
public static readonly summary = 'foo' | ||
public static readonly examples = 'baz' | ||
} | ||
`, | ||
}, | ||
// not an sfCommand | ||
{ | ||
filename: 'src/commands/foo.ts', | ||
code: ` | ||
export default class EnvCreateScratch extends somethingElse<ScratchCreateResponse> { | ||
// stuff | ||
} | ||
`, | ||
}, | ||
// not an command class | ||
{ | ||
filename: 'src/commands/foo.ts', | ||
code: ` | ||
export abstract class StagedProgress<T> { | ||
private dataForTheStatus: T; | ||
private theStages: Stage; | ||
} | ||
`, | ||
}, | ||
// not an command directory | ||
{ | ||
filename: 'src/shared/.ts', | ||
code: ` | ||
export abstract class StagedProgress<T> { | ||
private dataForTheStatus: T; | ||
private theStages: Stage; | ||
} | ||
`, | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
errors: [ | ||
{ | ||
messageId: 'summary', | ||
}, | ||
], | ||
filename: 'src/commands/foo.ts', | ||
code: ` | ||
export default class EnvCreateScratch extends SfCommand<ScratchCreateResponse> { | ||
public static readonly description = 'bar' | ||
public static readonly examples = 'baz' | ||
} | ||
`, | ||
}, | ||
], | ||
}); |