Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"conventionalCommits.scopes": [
"binaries"
"binaries",
"rules"
]
}
2 changes: 2 additions & 0 deletions grit/react-effects.grit
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ any {
$body <: contains `if ($condition) { $ifBody }`,
$condition <: not contains `!ignore`,
$condition <: not contains `error`,
$body <: not contains `return $cleanup`,
$body <: not contains `return () =>`,
$body <: not contains `return function`,
register_diagnostic(span=$effect, message="Avoid using state as an event handler. Instead, call the event handler directly.")
Expand All @@ -241,6 +242,7 @@ any {
$body <: contains `if ($condition) { $ifBody }`,
$condition <: not contains `!ignore`,
$condition <: not contains `error`,
$body <: not contains `return $cleanup`,
$body <: not contains `return () =>`,
$body <: not contains `return function`,
register_diagnostic(span=$effect, message="Avoid using state as an event handler. Instead, call the event handler directly.")
Expand Down
8 changes: 8 additions & 0 deletions tests/fixtures/suppression.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useEffect } from 'react';

export function EmptyEffectComponent() {
// biome-ignore lint: This comment should suppress the empty effect warning
useEffect(() => {}, []);

return <div>Empty Effect</div>;
}
26 changes: 26 additions & 0 deletions tests/fixtures/valid-editor-transform-effect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useEffect } from 'react';

declare const ParagraphNode: unknown;

type Editor = {
registerNodeTransform: (
node: unknown,
callback: (node: { getTextContent: () => string; remove: () => void }) => void,
) => () => void;
};

declare function useEditor(): Editor;

export function ValidEditorTransformEffect() {
const editor = useEditor();

useEffect(() => {
return editor.registerNodeTransform(ParagraphNode, (node) => {
if (node.getTextContent().trim() === '') {
node.remove();
}
});
}, [editor]);

return null;
}
10 changes: 10 additions & 0 deletions tests/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,14 @@ describe('unnecessary-effect plugin', () => {
const { exitCode } = runBiome(resolve(FIXTURES_PATH, 'valid-effect.tsx'));
expect(exitCode).toBe(0);
});

test('should not report registering editor transforms', () => {
const { exitCode } = runBiome(resolve(FIXTURES_PATH, 'valid-editor-transform-effect.tsx'));
expect(exitCode).toBe(0);
});

test('should respect suppression comments', () => {
const { exitCode } = runBiome(resolve(FIXTURES_PATH, 'suppression.tsx'));
expect(exitCode).toBe(0);
});
});