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

enable @typescript-eslint/no-unused-expressions rule #2933

Merged
merged 1 commit into from
Dec 8, 2022
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/polite-crabs-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@graphiql/react': patch
'graphql-language-service-server': patch
---

enable @typescript-eslint/no-unused-expressions
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ module.exports = {
'error',
{ argsIgnorePattern: '^_', ignoreRestSiblings: true },
],
'@typescript-eslint/no-unused-expressions': 'error',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this config change would validate a few false negatives and perhaps reveal a few more issues:

Suggested change
'@typescript-eslint/no-unused-expressions': 'error',
'@typescript-eslint/no-unused-expressions': ['error', {
allowShortCircuit: true,
allowTaggedTemplates: true,
enforceForJSX: true
}],

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still like to have allowShortCircuit: false since it will forbid code style in favour of if statements, but if you dislike just click on the Commit suggestion 😜


'no-use-before-define': 0,

Expand Down
10 changes: 6 additions & 4 deletions examples/monaco-graphql-react-vite/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,24 @@ export default function App() {
const variablesModel = getOrCreateModel('variables.json', defaultVariables);
const resultsModel = getOrCreateModel('results.json', '{}');

queryEditor ??
Copy link
Member

@acao acao Dec 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems the eslint rule doesn't recognize these valid expressions though? Though this style isn't very clear, but this code works as intended? (addressed by this suggestion: https://github.com/graphql/graphiql/pull/2933/files#r1038468647)

Copy link
Collaborator Author

@dimaMachina dimaMachina Dec 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it’s a valid, code works as intended, but refactoring to use if statement is more readable

if (!queryEditor) {
setQueryEditor(
createEditor(opsRef, {
theme: 'vs-dark',
model: queryModel,
language: 'graphql',
}),
);
variablesEditor ??
}
if (!variablesEditor) {
setVariablesEditor(
createEditor(varsRef, {
theme: 'vs-dark',
model: variablesModel,
}),
);
resultsViewer ??
}
if (!resultsViewer) {
setResultsViewer(
createEditor(resultsRef, {
theme: 'vs-dark',
Expand All @@ -132,7 +134,7 @@ export default function App() {
smoothScrolling: true,
}),
);

}
queryModel.onDidChangeContent(
debounce(300, () => {
localStorage.setItem('operations', queryModel.getValue());
Expand Down
1 change: 0 additions & 1 deletion packages/graphiql-react/src/utility/resize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ export function useDragResize({
if (!Number.isFinite(flex) || flex < 1) {
firstRef.current.style.flex = '1';
}
firstRef.current.style.flex;
}
}, []);

Expand Down
4 changes: 3 additions & 1 deletion packages/graphql-language-service-server/src/GraphQLCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,9 @@ export class GraphQLCache implements GraphQLCacheInterface {
const schemaKey = this._getSchemaCacheKeyForProject(
projectConfig,
) as string;
schemaKey && this._schemaMap.delete(schemaKey);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a valid expression as well? confused

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s valid but with if statement it’s more readable and clear

if (schemaKey) {
this._schemaMap.delete(schemaKey);
}
}

_getSchemaCacheKeyForProject(
Expand Down