Files
twenty/packages/twenty-eslint-rules/rules/matching-state-variable.spec.ts
T
Félix MalfaitandGitHub c737028dd6 Move tools/eslint-rules to packages/twenty-eslint-rules (#17203)
## Summary

Moves the custom ESLint rules from `tools/eslint-rules` to
`packages/twenty-eslint-rules` for better organization within the
monorepo packages structure.

## Changes

- Move `eslint-rules` from `tools/` to `packages/twenty-eslint-rules`
- Use `loadWorkspaceRules` from `@nx/eslint-plugin` to load custom rules
- Update all ESLint configs to use the `twenty/` rule prefix instead of
`@nx/workspace-`
- Update `project.json`, `jest.config.mjs` with new paths
- Update `package.json` workspaces and `nx.json` cache inputs
- Update Dockerfile reference

## Technical Details

The custom ESLint rules are now loaded using Nx's `loadWorkspaceRules`
utility which:
- Handles TypeScript transpilation automatically
- Allows loading workspace rules from any directory
- Provides a cleaner approach than the previous `@nx/workspace-`
convention

## Testing

- Verified all 17 custom ESLint rules load correctly from the new
location
- Verified linting works on dependent packages (twenty-front,
twenty-server, etc.)
2026-01-17 07:37:17 +01:00

179 lines
4.6 KiB
TypeScript

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);',
},
],
});