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] Prefer .textContent over .innerText #3118

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
6 changes: 6 additions & 0 deletions .changeset/two-chicken-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'cm6-graphql': patch
'@graphiql/react': patch
---

Prefer `.textContent` over `.innerText`
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ module.exports = {
'unicorn/prefer-keyboard-event-key': 'off',

'unicorn/prefer-switch': 'error',
'unicorn/prefer-dom-node-text-content': 'error',
// TODO: Fix all errors for the following rules included in recommended config
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-var-requires': 'off',
Expand Down Expand Up @@ -343,6 +344,10 @@ module.exports = {
{
files: ['**/cypress/**'],
extends: 'plugin:cypress/recommended',
rules: {
// Because innerText doesn't return hidden elements and returns new line (\n) characters
'unicorn/prefer-dom-node-text-content': 'off',
},
},
{
// Rules for unit tests
Expand Down
2 changes: 1 addition & 1 deletion examples/monaco-graphql-webpack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ function renderToolbar(toolbar: HTMLElement) {
executionTray.classList.add('align-right');

executeOpButton.id = 'execute-op';
executeOpButton.innerText = 'Run Operation ➤';
executeOpButton.textContent = 'Run Operation ➤';
executeOpButton.title = 'Execute the active GraphQL Operation';

schemaReloadButton.classList.add('reload-button');
Expand Down
3 changes: 2 additions & 1 deletion packages/cm6-graphql/src/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export const completion = graphqlLanguage.data.of({
(item.isDeprecated && item.deprecationReason)
) {
const el = document.createElement('div');
el.innerText = item.documentation || item.deprecationReason || '';
el.textContent =
item.documentation || item.deprecationReason || '';
return el;
}
},
Expand Down
24 changes: 12 additions & 12 deletions packages/graphiql-react/src/editor/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function onHasCompletion(
const deprecationLabel = document.createElement('span');
deprecationLabel.className =
'CodeMirror-hint-information-deprecation-label';
deprecationLabel.innerText = 'Deprecated';
deprecationLabel.textContent = 'Deprecated';
deprecation.append(deprecationLabel);

deprecationReason = document.createElement('div');
Expand Down Expand Up @@ -186,7 +186,7 @@ export function onHasCompletion(
}

if (fieldName) {
fieldName.innerText = ctx.text;
fieldName.textContent = ctx.text;
}

if (typeNamePill && typeNamePrefix && typeName && typeNameSuffix) {
Expand All @@ -195,24 +195,24 @@ export function onHasCompletion(

const renderType = (type: GraphQLType) => {
if (isNonNullType(type)) {
typeNameSuffix!.innerText = '!' + typeNameSuffix!.innerText;
typeNameSuffix!.textContent = '!' + typeNameSuffix!.textContent;
renderType(type.ofType);
} else if (isListType(type)) {
typeNamePrefix!.innerText += '[';
typeNameSuffix!.innerText = ']' + typeNameSuffix!.innerText;
typeNamePrefix!.textContent += '[';
typeNameSuffix!.textContent = ']' + typeNameSuffix!.textContent;
renderType(type.ofType);
} else {
typeName!.innerText = type.name;
typeName!.textContent = type.name;
}
};

typeNamePrefix.innerText = '';
typeNameSuffix.innerText = '';
typeNamePrefix.textContent = '';
typeNameSuffix.textContent = '';
renderType(ctx.type);
} else {
typeNamePrefix.innerText = '';
typeName.innerText = '';
typeNameSuffix.innerText = '';
typeNamePrefix.textContent = '';
typeName.textContent = '';
typeNameSuffix.textContent = '';
typeNamePill.style.display = 'none';
}
}
Expand Down Expand Up @@ -252,7 +252,7 @@ export function onHasCompletion(
return;
}

const typeName = event.currentTarget.innerText;
const typeName = event.currentTarget.textContent || '';
const type = schema.getType(typeName);
if (type) {
plugin.setVisiblePlugin(DOC_EXPLORER_PLUGIN);
Expand Down