Skip to content

Commit

Permalink
[ESLint] enable @typescript-eslint/no-floating-promises, update typ…
Browse files Browse the repository at this point in the history
…escript-eslint to v6 (#3109)
  • Loading branch information
dimaMachina committed Apr 14, 2023
1 parent 2e477eb commit 5100700
Show file tree
Hide file tree
Showing 20 changed files with 119 additions and 86 deletions.
10 changes: 10 additions & 0 deletions .changeset/shaggy-monkeys-bathe.md
@@ -0,0 +1,10 @@
---
'graphql-language-service-server': patch
'graphql-language-service-cli': patch
'codemirror-graphql': patch
'@graphiql/toolkit': patch
'@graphiql/react': patch
'monaco-graphql': patch
---

enable `no-floating-promises` eslint rule
3 changes: 2 additions & 1 deletion .eslintrc.js
Expand Up @@ -105,7 +105,6 @@ module.exports = {
'no-useless-call': 1,
'no-useless-concat': 1,
'no-useless-return': 0,
'no-void': 1,
'@typescript-eslint/prefer-optional-chain': 'error',
'no-warning-comments': 0,
radix: 'error',
Expand Down Expand Up @@ -298,8 +297,10 @@ module.exports = {
overrides: [
{
files: ['**/*.{ts,tsx}'],
// extends: ['plugin:@typescript-eslint/recommended-type-checked'],
rules: {
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-floating-promises': 'error',
},
parserOptions: {
project: [
Expand Down
2 changes: 1 addition & 1 deletion examples/monaco-graphql-nextjs/src/components/editor.tsx
Expand Up @@ -156,7 +156,7 @@ export default function Editor() {
useEffect(() => {
if (!schema && !loading) {
setLoading(true);
getSchema()
void getSchema()
.then(data => {
if (!('data' in data)) {
throw new Error(
Expand Down
2 changes: 1 addition & 1 deletion examples/monaco-graphql-react-vite/src/App.tsx
Expand Up @@ -158,7 +158,7 @@ export default function App() {
useEffect(() => {
if (!schema && !loading) {
setLoading(true);
getSchema()
void getSchema()
.then(data => {
if (!('data' in data)) {
throw new Error(
Expand Down
6 changes: 2 additions & 4 deletions examples/monaco-graphql-webpack/src/index.ts
Expand Up @@ -13,9 +13,7 @@ const SITE_ID = '46a6b3c8-992f-4623-9a76-f1bd5d40505c';

let monacoGraphQLAPI: MonacoGraphQLAPI | null = null;

(async () => {
await render();
})();
void render();

async function render() {
if (!schemaFetcher.token) {
Expand Down Expand Up @@ -314,7 +312,7 @@ export function renderGithubLoginButton() {
if (err) {
console.error('Error authenticating with GitHub:', err);
} else {
schemaFetcher.setApiToken(data.token);
await schemaFetcher.setApiToken(data.token);
await render();
}
},
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -105,8 +105,8 @@
"@types/react": "^17.0.37",
"@types/react-dom": "^17.0.17",
"@types/ws": "^7.4.0",
"@typescript-eslint/eslint-plugin": "^5.54.1",
"@typescript-eslint/parser": "^5.54.1",
"@typescript-eslint/eslint-plugin": "rc-v6",
"@typescript-eslint/parser": "rc-v6",
"aws-serverless-express": "^3.4.0",
"babel-jest": "^29.4.3",
"concurrently": "^7.0.0",
Expand Down
1 change: 0 additions & 1 deletion packages/codemirror-graphql/src/index.d.ts
Expand Up @@ -13,7 +13,6 @@ declare module 'codemirror' {
hint?: ShowHintOptions['hint'];
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface CodeMirrorHintMap {}

const hint: CodeMirrorHintMap;
Expand Down
4 changes: 2 additions & 2 deletions packages/graphiql-react/src/editor/completion.ts
Expand Up @@ -24,8 +24,8 @@ export function onHasCompletion(
explorer: ExplorerContextType | null,
plugin: PluginContextType | null,
callback?: (type: GraphQLNamedType) => void,
) {
importCodeMirror([], { useCommonAddons: false }).then(CodeMirror => {
): void {
void importCodeMirror([], { useCommonAddons: false }).then(CodeMirror => {
let information: HTMLDivElement | null;
let fieldName: HTMLSpanElement | null;
let typeNamePill: HTMLSpanElement | null;
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql-react/src/editor/header-editor.ts
Expand Up @@ -51,7 +51,7 @@ export function useHeaderEditor(
useEffect(() => {
let isActive = true;

importCodeMirror([
void importCodeMirror([
// @ts-expect-error
import('codemirror/mode/javascript/javascript'),
]).then(CodeMirror => {
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql-react/src/editor/query-editor.ts
Expand Up @@ -140,7 +140,7 @@ export function useQueryEditor(
useEffect(() => {
let isActive = true;

importCodeMirror([
void importCodeMirror([
import('codemirror/addon/comment/comment'),
import('codemirror/addon/search/search'),
import('codemirror-graphql/esm/hint'),
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql-react/src/editor/response-editor.tsx
Expand Up @@ -62,7 +62,7 @@ export function useResponseEditor(

useEffect(() => {
let isActive = true;
importCodeMirror(
void importCodeMirror(
[
import('codemirror/addon/fold/foldgutter'),
import('codemirror/addon/fold/brace-fold'),
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql-react/src/editor/variable-editor.ts
Expand Up @@ -57,7 +57,7 @@ export function useVariableEditor(
useEffect(() => {
let isActive = true;

importCodeMirror([
void importCodeMirror([
import('codemirror-graphql/esm/variables/hint'),
import('codemirror-graphql/esm/variables/lint'),
import('codemirror-graphql/esm/variables/mode'),
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql-toolkit/src/async-helpers/index.ts
Expand Up @@ -70,7 +70,7 @@ function asyncIterableToPromise<T>(
.then(result => {
resolve(result.value);
// ensure cleanup
iteratorReturn?.();
void iteratorReturn?.();
})
.catch(err => {
reject(err);
Expand Down
6 changes: 2 additions & 4 deletions packages/graphql-language-service-cli/src/cli.ts
Expand Up @@ -126,12 +126,10 @@ if (command === 'server') {
if (argv?.configDir) {
options.configDir = argv.configDir;
}
try {
startServer(options);
} catch (error) {
startServer(options).catch(error => {
const logger = new Logger();
logger.error(String(error));
}
});
} else {
client(command as string, argv as { [key: string]: string });
}
Expand Down
8 changes: 6 additions & 2 deletions packages/graphql-language-service-server/src/GraphQLCache.ts
Expand Up @@ -452,7 +452,11 @@ export class GraphQLCache implements GraphQLCacheInterface {
cache.delete(filePath);
}
} else if (fileAndContent?.queries) {
this.updateFragmentDefinition(rootDir, filePath, fileAndContent.queries);
await this.updateFragmentDefinition(
rootDir,
filePath,
fileAndContent.queries,
);
}
}

Expand Down Expand Up @@ -518,7 +522,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
cache.delete(filePath);
}
} else if (fileAndContent?.queries) {
this.updateObjectTypeDefinition(
await this.updateObjectTypeDefinition(
rootDir,
filePath,
fileAndContent.queries,
Expand Down
14 changes: 7 additions & 7 deletions packages/graphql-language-service-server/src/MessageProcessor.ts
Expand Up @@ -143,7 +143,7 @@ export class MessageProcessor {
}

if (!existsSync(this._tmpDirBase)) {
mkdirp(this._tmpDirBase);
void mkdirp(this._tmpDirBase);
}
}
get connection(): Connection {
Expand Down Expand Up @@ -350,7 +350,7 @@ export class MessageProcessor {
uri.match('package.json')?.length && require(uri)?.graphql;
if (hasGraphQLConfigFile || hasPackageGraphQLConfig) {
this._logger.info('updating graphql config');
this._updateGraphQLConfig();
await this._updateGraphQLConfig();
return { uri, diagnostics: [] };
}
// update graphql config only when graphql config is saved!
Expand Down Expand Up @@ -703,12 +703,12 @@ export class MessageProcessor {
return { uri, diagnostics };
}
if (change.type === FileChangeTypeKind.Deleted) {
this._graphQLCache.updateFragmentDefinitionCache(
await this._graphQLCache.updateFragmentDefinitionCache(
this._graphQLCache.getGraphQLConfig().dirpath,
change.uri,
false,
);
this._graphQLCache.updateObjectTypeDefinitionCache(
await this._graphQLCache.updateObjectTypeDefinitionCache(
this._graphQLCache.getGraphQLConfig().dirpath,
change.uri,
false,
Expand Down Expand Up @@ -924,7 +924,7 @@ export class MessageProcessor {
version = schemaDocument.version++;
}
const schemaText = readFileSync(uri, 'utf8');
this._cacheSchemaText(schemaUri, schemaText, version);
await this._cacheSchemaText(schemaUri, schemaText, version);
}
}
_getTmpProjectPath(
Expand All @@ -937,7 +937,7 @@ export class MessageProcessor {
const basePath = path.join(this._tmpDirBase, workspaceName);
let projectTmpPath = path.join(basePath, 'projects', project.name);
if (!existsSync(projectTmpPath)) {
mkdirp(projectTmpPath);
void mkdirp(projectTmpPath);
}
if (appendPath) {
projectTmpPath = path.join(projectTmpPath, appendPath);
Expand All @@ -963,7 +963,7 @@ export class MessageProcessor {
);
} else {
try {
this._cacheSchemaFile(uri, project);
await this._cacheSchemaFile(uri, project);
} catch {
// this string may be an SDL string even, how do we even evaluate this?
}
Expand Down
Expand Up @@ -244,7 +244,7 @@ function reportDiagnostics(
connection: Connection,
) {
if (diagnostics) {
connection.sendNotification(
void connection.sendNotification(
PublishDiagnosticsNotification.type,
diagnostics,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/monaco-graphql/src/initializeMode.ts
Expand Up @@ -28,7 +28,7 @@ export function initializeMode(
api = createMonacoGraphQLAPI(LANGUAGE_ID, config);
(<any>languages).graphql = { api };
// export to the global monaco API
getMode().then(mode => mode.setupMode(api));
void getMode().then(mode => mode.setupMode(api));
}

return api;
Expand Down
2 changes: 1 addition & 1 deletion packages/monaco-graphql/src/languageFeatures.ts
Expand Up @@ -56,7 +56,7 @@ export class DiagnosticsAdapter {
this._listener[modelUri] = model.onDidChangeContent(() => {
clearTimeout(onChangeTimeout);
onChangeTimeout = setTimeout(() => {
this._doValidate(model.uri, modeId, jsonValidationForModel);
void this._doValidate(model.uri, modeId, jsonValidationForModel);
}, 200);
});
};
Expand Down

0 comments on commit 5100700

Please sign in to comment.