2024-01-04 01:07:25 +03:00
|
|
|
import { TSESLint } from '@typescript-eslint/utils';
|
2023-09-15 03:04:45 +03:00
|
|
|
|
2024-01-04 01:07:25 +03:00
|
|
|
import { rule, RULE_NAME } from '../rules/effect-components';
|
2023-09-15 03:04:45 +03:00
|
|
|
|
2024-01-04 01:07:25 +03:00
|
|
|
const ruleTester = new TSESLint.RuleTester({
|
|
|
|
parser: require.resolve('@typescript-eslint/parser'),
|
2023-09-15 03:04:45 +03:00
|
|
|
parserOptions: {
|
|
|
|
ecmaFeatures: {
|
|
|
|
jsx: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-01-04 01:07:25 +03:00
|
|
|
ruleTester.run(RULE_NAME, rule, {
|
2023-09-15 03:04:45 +03:00
|
|
|
valid: [
|
|
|
|
{
|
2023-09-16 04:41:10 +03:00
|
|
|
code: `const TestComponentEffect = () => <></>;`,
|
2023-09-15 03:04:45 +03:00
|
|
|
},
|
|
|
|
{
|
2023-09-16 04:41:10 +03:00
|
|
|
code: `const TestComponent = () => <div></div>;`,
|
2023-09-15 03:04:45 +03:00
|
|
|
},
|
|
|
|
{
|
2023-09-16 04:41:10 +03:00
|
|
|
code: `export const useUpdateEffect = () => null;`,
|
2023-09-15 03:04:45 +03:00
|
|
|
},
|
|
|
|
{
|
2023-09-16 04:41:10 +03:00
|
|
|
code: `export const useUpdateEffect = () => <></>;`,
|
2023-09-15 03:04:45 +03:00
|
|
|
},
|
|
|
|
{
|
2023-09-16 04:41:10 +03:00
|
|
|
code: `const TestComponent = () => <><div></div></>;`,
|
2023-09-15 03:04:45 +03:00
|
|
|
},
|
|
|
|
{
|
2023-09-16 04:41:10 +03:00
|
|
|
code: `const TestComponentEffect = () => null;`,
|
2023-09-15 03:04:45 +03:00
|
|
|
},
|
|
|
|
{
|
2023-09-16 04:41:10 +03:00
|
|
|
code: `const TestComponentEffect = () => {
|
2023-09-15 03:04:45 +03:00
|
|
|
useEffect(() => {}, []);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
2023-09-16 04:41:10 +03:00
|
|
|
code: `const TestComponentEffect = () => {
|
2023-09-15 03:04:45 +03:00
|
|
|
useEffect(() => {}, []);
|
|
|
|
|
|
|
|
return <></>;
|
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
code: `const TestComponentEffect = () => {
|
|
|
|
useEffect(() => {}, []);
|
|
|
|
|
|
|
|
return <></>;
|
|
|
|
}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
code: `const TestComponentEffect = () => {
|
|
|
|
useEffect(() => {}, []);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}`,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
invalid: [
|
|
|
|
{
|
2024-01-04 01:07:25 +03:00
|
|
|
code: 'const TestComponent = () => <></>;',
|
|
|
|
output: 'const TestComponentEffect = () => <></>;',
|
2023-09-15 03:04:45 +03:00
|
|
|
errors: [
|
|
|
|
{
|
2024-01-04 01:07:25 +03:00
|
|
|
messageId: 'addEffectSuffix',
|
2023-09-15 03:04:45 +03:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
2024-01-04 01:07:25 +03:00
|
|
|
code: 'const TestComponentEffect = () => <><div></div></>;',
|
|
|
|
output: 'const TestComponent = () => <><div></div></>;',
|
2023-09-15 03:04:45 +03:00
|
|
|
errors: [
|
|
|
|
{
|
2024-01-04 01:07:25 +03:00
|
|
|
messageId: 'removeEffectSuffix',
|
2023-09-15 03:04:45 +03:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|