POC: chore: use Nx workspace lint rules (#3163)
* chore: use Nx workspace lint rules Closes #3162 * Fix lint * Fix lint on BE * Fix tests --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
178
tools/eslint-rules/rules/matching-state-variable.spec.ts
Normal file
178
tools/eslint-rules/rules/matching-state-variable.spec.ts
Normal file
@ -0,0 +1,178 @@
|
||||
import { TSESLint } from '@typescript-eslint/utils';
|
||||
|
||||
import { rule, RULE_NAME } from './matching-state-variable';
|
||||
|
||||
const ruleTester = new TSESLint.RuleTester({
|
||||
parser: require.resolve('@typescript-eslint/parser'),
|
||||
});
|
||||
|
||||
ruleTester.run(RULE_NAME, rule, {
|
||||
valid: [
|
||||
{
|
||||
code: 'const variable = useRecoilValue(variableState);',
|
||||
},
|
||||
{
|
||||
code: 'const variable = useRecoilScopedValue(variableScopedState);',
|
||||
},
|
||||
{
|
||||
code: 'const [variable, setVariable] = useRecoilState(variableScopedState);',
|
||||
},
|
||||
{
|
||||
code: 'const [variable, setVariable] = useRecoilScopedState(variableScopedState);',
|
||||
},
|
||||
{
|
||||
code: 'const [variable, setVariable] = useRecoilFamilyState(variableScopedState);',
|
||||
},
|
||||
{
|
||||
code: 'const [variable, setVariable] = useRecoilScopedFamilyState(variableScopedState);',
|
||||
},
|
||||
],
|
||||
invalid: [
|
||||
{
|
||||
code: 'const myValue = useRecoilValue(variableState);',
|
||||
errors: [
|
||||
{
|
||||
messageId: 'invalidVariableName',
|
||||
},
|
||||
],
|
||||
output: 'const variable = useRecoilValue(variableState);',
|
||||
},
|
||||
{
|
||||
code: 'const myValue = useRecoilScopedValue(variableState);',
|
||||
errors: [
|
||||
{
|
||||
messageId: 'invalidVariableName',
|
||||
},
|
||||
],
|
||||
output: 'const variable = useRecoilScopedValue(variableState);',
|
||||
},
|
||||
|
||||
{
|
||||
code: 'const [myValue, setMyValue] = useRecoilState(variableState);',
|
||||
errors: [
|
||||
{
|
||||
messageId: 'invalidVariableName',
|
||||
},
|
||||
{
|
||||
messageId: 'invalidSetterName',
|
||||
},
|
||||
],
|
||||
output: 'const [variable, setVariable] = useRecoilState(variableState);',
|
||||
},
|
||||
{
|
||||
code: 'const [myValue] = useRecoilState(variableState);',
|
||||
errors: [
|
||||
{
|
||||
messageId: 'invalidVariableName',
|
||||
},
|
||||
],
|
||||
output: 'const [variable] = useRecoilState(variableState);',
|
||||
},
|
||||
{
|
||||
code: 'const [, setMyValue] = useRecoilState(variableState);',
|
||||
errors: [
|
||||
{
|
||||
messageId: 'invalidSetterName',
|
||||
},
|
||||
],
|
||||
output: 'const [, setVariable] = useRecoilState(variableState);',
|
||||
},
|
||||
|
||||
{
|
||||
code: 'const [myValue, setMyValue] = useRecoilScopedState(variableState);',
|
||||
errors: [
|
||||
{
|
||||
messageId: 'invalidVariableName',
|
||||
},
|
||||
{
|
||||
messageId: 'invalidSetterName',
|
||||
},
|
||||
],
|
||||
output:
|
||||
'const [variable, setVariable] = useRecoilScopedState(variableState);',
|
||||
},
|
||||
{
|
||||
code: 'const [myValue] = useRecoilScopedState(variableState);',
|
||||
errors: [
|
||||
{
|
||||
messageId: 'invalidVariableName',
|
||||
},
|
||||
],
|
||||
output: 'const [variable] = useRecoilScopedState(variableState);',
|
||||
},
|
||||
{
|
||||
code: 'const [, setMyValue] = useRecoilScopedState(variableState);',
|
||||
errors: [
|
||||
{
|
||||
messageId: 'invalidSetterName',
|
||||
},
|
||||
],
|
||||
output: 'const [, setVariable] = useRecoilScopedState(variableState);',
|
||||
},
|
||||
|
||||
{
|
||||
code: 'const [myValue, setMyValue] = useRecoilFamilyState(variableState);',
|
||||
errors: [
|
||||
{
|
||||
messageId: 'invalidVariableName',
|
||||
},
|
||||
{
|
||||
messageId: 'invalidSetterName',
|
||||
},
|
||||
],
|
||||
output:
|
||||
'const [variable, setVariable] = useRecoilFamilyState(variableState);',
|
||||
},
|
||||
{
|
||||
code: 'const [myValue] = useRecoilFamilyState(variableState);',
|
||||
errors: [
|
||||
{
|
||||
messageId: 'invalidVariableName',
|
||||
},
|
||||
],
|
||||
output: 'const [variable] = useRecoilFamilyState(variableState);',
|
||||
},
|
||||
{
|
||||
code: 'const [, setMyValue] = useRecoilFamilyState(variableState);',
|
||||
errors: [
|
||||
{
|
||||
messageId: 'invalidSetterName',
|
||||
},
|
||||
],
|
||||
output: 'const [, setVariable] = useRecoilFamilyState(variableState);',
|
||||
},
|
||||
|
||||
{
|
||||
code: 'const [myValue, setMyValue] = useRecoilScopedFamilyState(variableState);',
|
||||
errors: [
|
||||
{
|
||||
messageId: 'invalidVariableName',
|
||||
},
|
||||
{
|
||||
messageId: 'invalidSetterName',
|
||||
},
|
||||
],
|
||||
output:
|
||||
'const [variable, setVariable] = useRecoilScopedFamilyState(variableState);',
|
||||
},
|
||||
{
|
||||
code: 'const [myValue] = useRecoilScopedFamilyState(variableState);',
|
||||
errors: [
|
||||
{
|
||||
messageId: 'invalidVariableName',
|
||||
},
|
||||
],
|
||||
output: 'const [variable] = useRecoilScopedFamilyState(variableState);',
|
||||
},
|
||||
{
|
||||
code: 'const [, setMyValue] = useRecoilScopedFamilyState(variableState);',
|
||||
errors: [
|
||||
{
|
||||
messageId: 'invalidSetterName',
|
||||
},
|
||||
],
|
||||
output:
|
||||
'const [, setVariable] = useRecoilScopedFamilyState(variableState);',
|
||||
},
|
||||
],
|
||||
});
|
||||
Reference in New Issue
Block a user