fix: add prefer-dom-node-remove rule (#5112)

This commit is contained in:
LongYinan 2023-11-29 04:43:50 +00:00
parent 45690c2756
commit 4dddbbdaee
No known key found for this signature in database
GPG Key ID: 30B1140CE1C07C99
6 changed files with 8 additions and 7 deletions

View File

@ -209,6 +209,7 @@ const config = {
'unicorn/no-useless-fallback-in-spread': 'error', 'unicorn/no-useless-fallback-in-spread': 'error',
'unicorn/prefer-dom-node-dataset': 'error', 'unicorn/prefer-dom-node-dataset': 'error',
'unicorn/prefer-dom-node-append': 'error', 'unicorn/prefer-dom-node-append': 'error',
'unicorn/prefer-dom-node-remove': 'error',
'unicorn/prefer-array-some': 'error', 'unicorn/prefer-array-some': 'error',
'unicorn/no-useless-promise-resolve-reject': 'error', 'unicorn/no-useless-promise-resolve-reject': 'error',
'sonarjs/no-all-duplicated-branches': 'error', 'sonarjs/no-all-duplicated-branches': 'error',

View File

@ -10,7 +10,7 @@ export const RootBlockHub = () => {
const div = ref.current; const div = ref.current;
if (blockHub) { if (blockHub) {
if (div.hasChildNodes()) { if (div.hasChildNodes()) {
div.removeChild(div.firstChild as ChildNode); (div.firstChild as ChildNode).remove();
} }
div.append(blockHub); div.append(blockHub);
} }

View File

@ -136,7 +136,7 @@ const BlockSuiteEditorImpl = ({
} }
container.append(editor); container.append(editor);
return () => { return () => {
container.removeChild(editor); editor.remove();
}; };
}, [editor]); }, [editor]);

View File

@ -177,7 +177,7 @@ const EditorWrapper = memo(function EditorWrapper({
document.body.append(div); document.body.append(div);
return () => { return () => {
cleanup(); cleanup();
document.body.removeChild(div); div.remove();
}; };
}); });
}); });
@ -238,11 +238,11 @@ const PluginContentAdapter = memo<PluginContentAdapterProps>(
root.append(div); root.append(div);
if (abortController.signal.aborted) { if (abortController.signal.aborted) {
cleanup(); cleanup();
root.removeChild(div); div.remove();
} else { } else {
const cl = () => { const cl = () => {
cleanup(); cleanup();
root.removeChild(div); div.remove();
}; };
const dispose = addCleanup(pluginName, cl); const dispose = addCleanup(pluginName, cl);
abortController.signal.addEventListener('abort', () => { abortController.signal.addEventListener('abort', () => {

View File

@ -30,7 +30,7 @@ export const PluginHeader = () => {
pluginsRef.current = pluginsRef.current.filter( pluginsRef.current = pluginsRef.current.filter(
name => name !== pluginName name => name !== pluginName
); );
root.removeChild(div); div.remove();
cleanup(); cleanup();
}); });
}); });

View File

@ -233,7 +233,7 @@ const ImagePreviewModalImpl = (
a.download = block.id ?? 'image'; a.download = block.id ?? 'image';
document.body.append(a); document.body.append(a);
a.click(); a.click();
document.body.removeChild(a); a.remove();
} }
}, },
[props.pageId, props.workspace] [props.pageId, props.workspace]