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

setup @shopify/prefer-early-return and sonarjs/no-inverted-boolean-check #3276

Merged
merged 2 commits into from
Jun 24, 2023
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
20 changes: 10 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ module.exports = {
'plugin:react/jsx-runtime',
'prettier',
],

plugins: [
'promise',
'sonarjs',
'unicorn',
'@arthurgeron/react-usememo',
'sonar',
'@shopify',
],
globals: {
atom: false,
document: false,
Expand All @@ -52,8 +59,9 @@ module.exports = {
Map: true,
Set: true,
},

rules: {
'@shopify/prefer-early-return': ['error', { maximumStatements: 2 }],
'sonarjs/no-inverted-boolean-check': 'error',
'@arthurgeron/react-usememo/require-usememo': [
'error',
{ checkHookCalls: false },
Expand Down Expand Up @@ -314,14 +322,6 @@ module.exports = {
// TODO: Fix all errors for the following rules included in recommended config
'@typescript-eslint/no-var-requires': 'off',
},

plugins: [
'promise',
'sonarjs',
'unicorn',
'@arthurgeron/react-usememo',
'sonar',
],
},
{
// Rules that requires type information
Expand Down
71 changes: 37 additions & 34 deletions examples/monaco-graphql-nextjs/src/components/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Uri, editor, KeyMod, KeyCode, languages } from 'monaco-editor';
import { initializeMode } from 'monaco-graphql/esm/initializeMode';
import { createGraphiQLFetcher } from '@graphiql/toolkit';
import * as JSONC from 'jsonc-parser';

/**
* Copied from graphql/graphiql/examples/monaco-graphql-vite
*/
Expand Down Expand Up @@ -154,42 +155,44 @@ export default function Editor() {
* Handle the initial schema load
*/
useEffect(() => {
if (!schema && !loading) {
setLoading(true);
void getSchema()
.then(data => {
if (!('data' in data)) {
throw new Error(
'this demo does not support subscriptions or http multipart yet',
);
}
initializeMode({
diagnosticSettings: {
validateVariablesJSON: {
[Uri.file('operation.graphql').toString()]: [
Uri.file('variables.json').toString(),
],
},
jsonDiagnosticSettings: {
validate: true,
schemaValidation: 'error',
// set these again, because we are entirely re-setting them here
allowComments: true,
trailingCommas: 'ignore',
},
if (schema || loading) {
return;
}

setLoading(true);
void getSchema()
.then(data => {
if (!('data' in data)) {
throw new Error(
'this demo does not support subscriptions or http multipart yet',
);
}
initializeMode({
diagnosticSettings: {
validateVariablesJSON: {
[Uri.file('operation.graphql').toString()]: [
Uri.file('variables.json').toString(),
],
},
schemas: [
{
introspectionJSON: data.data as unknown as IntrospectionQuery,
uri: 'myschema.graphql',
},
],
});
jsonDiagnosticSettings: {
validate: true,
schemaValidation: 'error',
// set these again, because we are entirely re-setting them here
allowComments: true,
trailingCommas: 'ignore',
},
},
schemas: [
{
introspectionJSON: data.data as unknown as IntrospectionQuery,
uri: 'myschema.graphql',
},
],
});

setSchema(data.data);
})
.then(() => setLoading(false));
}
setSchema(data.data);
})
.then(() => setLoading(false));
}, [schema, loading]);
return (
<div id="wrapper">
Expand Down
69 changes: 35 additions & 34 deletions examples/monaco-graphql-react-vite/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,42 +156,43 @@ export default function App() {
* Handle the initial schema load
*/
useEffect(() => {
if (!schema && !loading) {
setLoading(true);
void getSchema()
.then(data => {
if (!('data' in data)) {
throw new Error(
'this demo does not support subscriptions or http multipart yet',
);
}
initializeMode({
diagnosticSettings: {
validateVariablesJSON: {
[Uri.file('operation.graphql').toString()]: [
Uri.file('variables.json').toString(),
],
},
jsonDiagnosticSettings: {
validate: true,
schemaValidation: 'error',
// set these again, because we are entirely re-setting them here
allowComments: true,
trailingCommas: 'ignore',
},
if (schema || loading) {
return;
}
setLoading(true);
void getSchema()
.then(data => {
if (!('data' in data)) {
throw new Error(
'this demo does not support subscriptions or http multipart yet',
);
}
initializeMode({
diagnosticSettings: {
validateVariablesJSON: {
[Uri.file('operation.graphql').toString()]: [
Uri.file('variables.json').toString(),
],
},
jsonDiagnosticSettings: {
validate: true,
schemaValidation: 'error',
// set these again, because we are entirely re-setting them here
allowComments: true,
trailingCommas: 'ignore',
},
schemas: [
{
introspectionJSON: data.data as unknown as IntrospectionQuery,
uri: 'myschema.graphql',
},
],
});
},
schemas: [
{
introspectionJSON: data.data as unknown as IntrospectionQuery,
uri: 'myschema.graphql',
},
],
});

setSchema(data.data);
})
.then(() => setLoading(false));
}
setSchema(data.data);
})
.then(() => setLoading(false));
}, [schema, loading]);
return (
<div id="wrapper">
Expand Down
26 changes: 13 additions & 13 deletions examples/monaco-graphql-webpack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,19 @@ async function render() {
schemaPicker.addEventListener(
'input',
async function SchemaSelectionHandler(_ev: Event) {
if (schemaPicker.value !== schemaFetcher.currentSchema.value) {
const schemaResult = await schemaFetcher.changeSchema(
schemaPicker.value,
);
if (schemaResult && monacoGraphQLAPI) {
monacoGraphQLAPI.setSchemaConfig([
{
...schemaResult,
fileMatch: [operationModel.uri.toString()],
},
]);
schemaEditor.setValue(schemaResult.documentString || '');
}
if (schemaPicker.value === schemaFetcher.currentSchema.value) {
return;
}

const schemaResult = await schemaFetcher.changeSchema(schemaPicker.value);
if (schemaResult && monacoGraphQLAPI) {
monacoGraphQLAPI.setSchemaConfig([
{
...schemaResult,
fileMatch: [operationModel.uri.toString()],
},
]);
schemaEditor.setValue(schemaResult.documentString || '');
}
},
);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"@changesets/changelog-github": "^0.4.7",
"@changesets/cli": "^2.25.2",
"@manypkg/get-packages": "^1.1.3",
"@shopify/eslint-plugin": "^42.1.0",
"@strictsoftware/typedoc-plugin-monorepo": "^0.3.1",
"@testing-library/jest-dom": "5.16.5",
"@types/aws-serverless-express": "^3.3.3",
Expand Down
39 changes: 20 additions & 19 deletions packages/graphiql-react/src/editor/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,26 +161,27 @@ export function onHasCompletion(
hintsUl.addEventListener(
'DOMNodeRemoved',
(onRemoveFn = (event: Event) => {
if (event.target === hintsUl) {
hintsUl.removeEventListener('scroll', handleScroll);
hintsUl.removeEventListener('DOMNodeRemoved', onRemoveFn);
if (information) {
information.removeEventListener(
'click',
onClickHintInformation,
);
}
information = null;
fieldName = null;
typeNamePill = null;
typeNamePrefix = null;
typeName = null;
typeNameSuffix = null;
description = null;
deprecation = null;
deprecationReason = null;
onRemoveFn = null;
if (event.target !== hintsUl) {
return;
}
hintsUl.removeEventListener('scroll', handleScroll);
hintsUl.removeEventListener('DOMNodeRemoved', onRemoveFn);
if (information) {
information.removeEventListener(
'click',
onClickHintInformation,
);
}
information = null;
fieldName = null;
typeNamePill = null;
typeNamePrefix = null;
typeName = null;
typeNameSuffix = null;
description = null;
deprecation = null;
deprecationReason = null;
onRemoveFn = null;
}),
);
}
Expand Down
21 changes: 11 additions & 10 deletions packages/graphiql-toolkit/src/storage/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,24 @@ export class HistoryStore {
operationName?: string,
) => {
if (
this.shouldSaveQuery(
!this.shouldSaveQuery(
query,
variables,
headers,
this.history.fetchRecent(),
)
) {
this.history.push({
query,
variables,
headers,
operationName,
});
const historyQueries = this.history.items;
const favoriteQueries = this.favorite.items;
this.queries = historyQueries.concat(favoriteQueries);
return;
}
this.history.push({
query,
variables,
headers,
operationName,
});
const historyQueries = this.history.items;
const favoriteQueries = this.favorite.items;
this.queries = historyQueries.concat(favoriteQueries);
};

toggleFavorite(
Expand Down
15 changes: 8 additions & 7 deletions packages/graphiql/__mocks__/codemirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ function CodeMirror(node: HTMLElement, { value, ...options }) {
},

off(event) {
if (Object.prototype.hasOwnProperty.call(_eventListeners, event)) {
const updatedEventListeners = {};
for (const e in _eventListeners) {
if (e !== event) {
updatedEventListeners[e] = _eventListeners[e];
}
if (!Object.prototype.hasOwnProperty.call(_eventListeners, event)) {
return;
}
const updatedEventListeners = {};
for (const e in _eventListeners) {
if (e !== event) {
updatedEventListeners[e] = _eventListeners[e];
}
_eventListeners = updatedEventListeners;
}
_eventListeners = updatedEventListeners;
},

getValue() {
Expand Down
Loading