-
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
6 changed files
with
93 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Mark when an alias starts with a hyphen, like -f or --foo (`sf-plugin/no-hyphens-aliases`) | ||
|
||
💼 This rule is enabled in the following configs: ✈️ `migration`, ✅ `recommended`. | ||
|
||
🔧 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix). | ||
|
||
<!-- end auto-generated rule header --> |
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,47 @@ | ||
/* | ||
* 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 { AST_NODE_TYPES, ESLintUtils } from '@typescript-eslint/utils'; | ||
|
||
export const noMessagesLoad = ESLintUtils.RuleCreator.withoutDocs({ | ||
meta: { | ||
docs: { | ||
description: 'Use Messages.loadMessages() instead of Messages.load()', | ||
recommended: 'error', | ||
}, | ||
messages: { | ||
message: 'Use Messages.loadMessages() instead of Messages.load()', | ||
}, | ||
type: 'problem', | ||
schema: [], | ||
fixable: 'code', | ||
}, | ||
defaultOptions: [], | ||
create(context) { | ||
return { | ||
CallExpression(node): void { | ||
if ( | ||
node.callee.type === AST_NODE_TYPES.MemberExpression && | ||
node.callee.object.type === AST_NODE_TYPES.Identifier && | ||
node.callee.object.name === 'Messages' && | ||
node.callee.property.type === AST_NODE_TYPES.Identifier && | ||
node.callee.property.name === 'load' && | ||
node.arguments[0].type === AST_NODE_TYPES.Literal && | ||
node.arguments[1].type === AST_NODE_TYPES.Literal | ||
) { | ||
const replacementText = `Messages.loadMessages(${node.arguments[0].raw}, ${node.arguments[1].raw})`; | ||
context.report({ | ||
node: node.callee.property, | ||
messageId: 'message', | ||
fix: (fixer) => { | ||
return fixer.replaceText(node, replacementText); | ||
}, | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}); |
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,33 @@ | ||
/* | ||
* 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 { noMessagesLoad } from '../../src/rules/no-messages-load'; | ||
|
||
const ruleTester = new ESLintUtils.RuleTester({ | ||
parser: '@typescript-eslint/parser', | ||
}); | ||
|
||
ruleTester.run('noMessagesLoad', noMessagesLoad, { | ||
valid: [ | ||
{ | ||
name: 'messages.loadMessages', | ||
code: "const messages = Messages.loadMessages('foo', 'bar')", | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
name: 'messages.load', | ||
errors: [ | ||
{ | ||
messageId: 'message', | ||
}, | ||
], | ||
code: "const messages = Messages.load('foo', 'bar', ['a', 'b'])", | ||
output: "const messages = Messages.loadMessages('foo', 'bar')", | ||
}, | ||
], | ||
}); |