Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ESLint] enable unicorn/prefer-dom-node-append #3117

Merged
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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ module.exports = {
'unicorn/throw-new-error': 'error',
'unicorn/prefer-includes': 'error',
'unicorn/no-array-for-each': 'error',
'unicorn/prefer-dom-node-append': 'error',
'no-lonely-if': 'error',
'unicorn/no-lonely-if': 'error',
'unicorn/prefer-optional-catch-binding': 'error',
Expand Down
18 changes: 9 additions & 9 deletions examples/monaco-graphql-webpack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ function renderToolbar(toolbar: HTMLElement) {
const executionTray = document.createElement('div');

executionTray.id = 'execution-tray';
executionTray.appendChild(executeOpButton);
executionTray.append(executeOpButton);
executionTray.classList.add('align-right');

executeOpButton.id = 'execute-op';
Expand All @@ -241,12 +241,12 @@ function renderToolbar(toolbar: HTMLElement) {
schemaStatus.id = 'schema-status';
schemaStatus.innerHTML = `Schema Empty`;

toolbar.appendChild(schemaPicker);

toolbar.appendChild(schemaReloadButton);
toolbar.appendChild(schemaStatus);

toolbar?.appendChild(executeOpButton);
toolbar.append(
schemaPicker,
schemaReloadButton,
schemaStatus,
executeOpButton,
);
return { schemaReloadButton, executeOpButton, schemaStatus, schemaPicker };
}

Expand All @@ -261,7 +261,7 @@ function getSchemaPicker(): HTMLSelectElement {
if (option.default) {
optEl.selected = true;
}
schemaPicker.appendChild(optEl);
schemaPicker.append(optEl);
}

return schemaPicker;
Expand Down Expand Up @@ -295,7 +295,7 @@ export function renderGithubLoginButton() {
const toolbar = document.getElementById('toolbar');
toolbar?.appendChild(logoutButton);
} else {
githubLoginWrapper.appendChild(githubButton);
githubLoginWrapper.append(githubButton);
document.getElementById('flex-wrapper')?.prepend(githubLoginWrapper);
}

Expand Down
32 changes: 16 additions & 16 deletions packages/codemirror-graphql/src/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ CodeMirror.registerHelper(
header.className = 'CodeMirror-info-header';
renderField(header, typeInfo, options);
const into = document.createElement('div');
into.appendChild(header);
into.append(header);
renderDescription(into, options, typeInfo.fieldDef as any);
return into;
}
Expand All @@ -84,7 +84,7 @@ CodeMirror.registerHelper(
header.className = 'CodeMirror-info-header';
renderDirective(header, typeInfo, options);
const into = document.createElement('div');
into.appendChild(header);
into.append(header);
renderDescription(into, options, typeInfo.directiveDef);
return into;
}
Expand All @@ -93,7 +93,7 @@ CodeMirror.registerHelper(
header.className = 'CodeMirror-info-header';
renderArg(header, typeInfo, options);
const into = document.createElement('div');
into.appendChild(header);
into.append(header);
renderDescription(into, options, typeInfo.argDef);
return into;
}
Expand All @@ -106,7 +106,7 @@ CodeMirror.registerHelper(
header.className = 'CodeMirror-info-header';
renderEnumValue(header, typeInfo, options);
const into = document.createElement('div');
into.appendChild(header);
into.append(header);
renderDescription(into, options, typeInfo.enumValue);
return into;
}
Expand All @@ -119,7 +119,7 @@ CodeMirror.registerHelper(
header.className = 'CodeMirror-info-header';
renderType(header, typeInfo, options, typeInfo.type);
const into = document.createElement('div');
into.appendChild(header);
into.append(header);
renderDescription(into, options, typeInfo.type);
return into;
}
Expand Down Expand Up @@ -198,7 +198,7 @@ function renderTypeAnnotation(
getTypeReference(typeInfo, t),
);
}
into.appendChild(typeSpan);
into.append(typeSpan);
}

function renderType(
Expand Down Expand Up @@ -242,9 +242,9 @@ function renderDescription(
if (options.renderDescription) {
descriptionDiv.innerHTML = options.renderDescription(description);
} else {
descriptionDiv.appendChild(document.createTextNode(description));
descriptionDiv.append(document.createTextNode(description));
}
into.appendChild(descriptionDiv);
into.append(descriptionDiv);
}

renderDeprecation(into, options, def);
Expand All @@ -264,21 +264,21 @@ function renderDeprecation(
if (reason) {
const deprecationDiv = document.createElement('div');
deprecationDiv.className = 'info-deprecation';
into.appendChild(deprecationDiv);
into.append(deprecationDiv);

const label = document.createElement('span');
label.className = 'info-deprecation-label';
label.appendChild(document.createTextNode('Deprecated'));
deprecationDiv.appendChild(label);
label.append(document.createTextNode('Deprecated'));
deprecationDiv.append(label);

const reasonDiv = document.createElement('div');
reasonDiv.className = 'info-deprecation-reason';
if (options.renderDescription) {
reasonDiv.innerHTML = options.renderDescription(reason);
} else {
reasonDiv.appendChild(document.createTextNode(reason));
reasonDiv.append(document.createTextNode(reason));
}
deprecationDiv.appendChild(reasonDiv);
deprecationDiv.append(reasonDiv);
}
}

Expand All @@ -305,9 +305,9 @@ function text(
node = document.createElement('span');
}
node.className = className;
node.appendChild(document.createTextNode(content));
into.appendChild(node);
node.append(document.createTextNode(content));
into.append(node);
} else {
into.appendChild(document.createTextNode(content));
into.append(document.createTextNode(content));
}
}
4 changes: 2 additions & 2 deletions packages/codemirror-graphql/src/utils/info-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ function onMouseHover(cm: CodeMirror.Editor, box: DOMRect) {
function showPopup(cm: CodeMirror.Editor, box: DOMRect, info: HTMLDivElement) {
const popup = document.createElement('div');
popup.className = 'CodeMirror-info';
popup.appendChild(info);
document.body.appendChild(popup);
popup.append(info);
document.body.append(popup);

const popupBox = popup.getBoundingClientRect();
const popupStyle = window.getComputedStyle(popup);
Expand Down
22 changes: 11 additions & 11 deletions packages/graphiql-react/src/editor/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,50 +49,50 @@ export function onHasCompletion(
// highlighted typeahead option.
information = document.createElement('div');
information.className = 'CodeMirror-hint-information';
hintsUl.appendChild(information);
hintsUl.append(information);

const header = document.createElement('header');
header.className = 'CodeMirror-hint-information-header';
information.appendChild(header);
information.append(header);

fieldName = document.createElement('span');
fieldName.className = 'CodeMirror-hint-information-field-name';
header.appendChild(fieldName);
header.append(fieldName);

typeNamePill = document.createElement('span');
typeNamePill.className = 'CodeMirror-hint-information-type-name-pill';
header.appendChild(typeNamePill);
header.append(typeNamePill);

typeNamePrefix = document.createElement('span');
typeNamePill.appendChild(typeNamePrefix);
typeNamePill.append(typeNamePrefix);

typeName = document.createElement('a');
typeName.className = 'CodeMirror-hint-information-type-name';
typeName.href = 'javascript:void 0'; // eslint-disable-line no-script-url
typeName.addEventListener('click', onClickHintInformation);
typeNamePill.appendChild(typeName);
typeNamePill.append(typeName);

typeNameSuffix = document.createElement('span');
typeNamePill.appendChild(typeNameSuffix);
typeNamePill.append(typeNameSuffix);

description = document.createElement('div');
description.className = 'CodeMirror-hint-information-description';
information.appendChild(description);
information.append(description);

deprecation = document.createElement('div');
deprecation.className = 'CodeMirror-hint-information-deprecation';
information.appendChild(deprecation);
information.append(deprecation);

const deprecationLabel = document.createElement('span');
deprecationLabel.className =
'CodeMirror-hint-information-deprecation-label';
deprecationLabel.innerText = 'Deprecated';
deprecation.appendChild(deprecationLabel);
deprecation.append(deprecationLabel);

deprecationReason = document.createElement('div');
deprecationReason.className =
'CodeMirror-hint-information-deprecation-reason';
deprecation.appendChild(deprecationReason);
deprecation.append(deprecationReason);

/**
* This is a bit hacky: By default, codemirror renders all hints
Expand Down
5 changes: 2 additions & 3 deletions packages/graphiql/__mocks__/@graphiql/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,9 @@ function useMockedEditor(name: Name, onEdit?: (newValue: string) => void) {
mockTextArea.className = 'mockCodeMirror';

const mockWrapper = document.createElement('div');
mockWrapper.appendChild(mockGutter);
mockWrapper.appendChild(mockTextArea);
mockWrapper.append(mockGutter, mockTextArea);

ref.current.appendChild(mockWrapper);
ref.current.append(mockWrapper);

setEditor({
getValue() {
Expand Down
5 changes: 2 additions & 3 deletions packages/graphiql/__mocks__/codemirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ function CodeMirror(node: HTMLElement, { value, ...options }) {
_emit('change', e);
});
mockTextArea.value = value;
mockWrapper.appendChild(mockGutter);
mockWrapper.appendChild(mockTextArea);
node.appendChild(mockWrapper);
mockWrapper.append(mockGutter, mockTextArea);
node.append(mockWrapper);

function _emit(event, data) {
if (_eventListeners[event]) {
Expand Down