TWNTY-2244 - ESLint rule: enforce usage of .getLoadable() + .getValue() to get atoms (#4143)
* ESLint rule: enforce usage of .getLoadable() + .getValue() to get atoms Co-authored-by: Matheus <matheus_benini@hotmail.com> * Merge main Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Matheus <matheus_benini@hotmail.com> * Fix * Refactor according to review Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Matheus <matheus_benini@hotmail.com> * Fix linter issue Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Matheus <matheus_benini@hotmail.com> * Fix linter Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Matheus <matheus_benini@hotmail.com> --------- Co-authored-by: gitstart-twenty <gitstart-twenty@users.noreply.github.com> Co-authored-by: Matheus <matheus_benini@hotmail.com> Co-authored-by: v1b3m <vibenjamin6@gmail.com> Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
committed by
GitHub
parent
706b5d3cf1
commit
b2210bd418
@ -0,0 +1,53 @@
|
||||
import { TSESLint } from '@typescript-eslint/utils';
|
||||
|
||||
import { rule, RULE_NAME } from './use-getLoadable-and-getValue-to-get-atoms';
|
||||
|
||||
const ruleTester = new TSESLint.RuleTester({
|
||||
parser: require.resolve('@typescript-eslint/parser'),
|
||||
parserOptions: {
|
||||
ecmaFeatures: {
|
||||
jsx: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
ruleTester.run(RULE_NAME, rule, {
|
||||
valid: [
|
||||
{
|
||||
code: 'const atoms = snapshot.getLoadable(someState).getValue();',
|
||||
},
|
||||
{
|
||||
code: 'const atoms = snapshot.getLoadable(someState(viewId)).getValue();',
|
||||
},
|
||||
],
|
||||
invalid: [
|
||||
{
|
||||
code: 'const atoms = await snapshot.getPromise(someState);',
|
||||
errors: [
|
||||
{
|
||||
messageId: 'invalidWayToGetAtoms',
|
||||
},
|
||||
],
|
||||
output: 'const atoms = snapshot.getLoadable(someState).getValue();',
|
||||
},
|
||||
{
|
||||
code: 'const atoms = await snapshot.getPromise(someState(viewId));',
|
||||
errors: [
|
||||
{
|
||||
messageId: 'invalidWayToGetAtoms',
|
||||
},
|
||||
],
|
||||
output:
|
||||
'const atoms = snapshot.getLoadable(someState(viewId)).getValue();',
|
||||
},
|
||||
{
|
||||
code: 'const atoms = snapshot.getLoadable(someState).anotherMethod();',
|
||||
errors: [
|
||||
{
|
||||
messageId: 'invalidWayToGetAtoms',
|
||||
},
|
||||
],
|
||||
output: 'const atoms = snapshot.getLoadable(someState).getValue();',
|
||||
},
|
||||
],
|
||||
});
|
||||
Reference in New Issue
Block a user