Skip to content

Commit

Permalink
[ESLint] Prefer .textContent over .innerText (#3118)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina committed May 27, 2023
1 parent c645932 commit 431b7fe
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
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

0 comments on commit 431b7fe

Please sign in to comment.