Skip to content

Commit

Permalink
enable unicorn/prefer-optional-catch-binding rule (#2965)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina committed Jan 9, 2023
1 parent cec3fb2 commit 0669767
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 26 deletions.
10 changes: 10 additions & 0 deletions .changeset/poor-mirrors-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@graphiql/react': patch
'@graphiql/toolkit': patch
'graphql-language-service': patch
'graphql-language-service-server': patch
'monaco-graphql': patch
'vscode-graphql-execution': patch
---

enable `unicorn/prefer-optional-catch-binding` rule
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ module.exports = {
'unicorn/prefer-includes': 'error',
'no-lonely-if': 'error',
'unicorn/no-lonely-if': 'error',
'unicorn/prefer-optional-catch-binding': 'error',
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': 'error',
'sonarjs/no-small-switch': 'error',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function tokenToURL(token: Token) {
try {
const location = window.location;
return new URL(value, location.protocol + '//' + location.host);
} catch (err) {
} catch {
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql-react/src/editor/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function getDefaultTabState({
return parsed;
}
throw new Error('Storage for tabs is invalid');
} catch (err) {
} catch {
return {
activeTabIndex: 0,
tabs: (
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql-react/src/explorer/components/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ function isMatch(sourceText: string, searchValue: string) {
try {
const escaped = searchValue.replace(/[^_0-9A-Za-z]/g, ch => '\\' + ch);
return sourceText.search(new RegExp(escaped, 'i')) !== -1;
} catch (e) {
} catch {
return sourceText.toLowerCase().includes(searchValue.toLowerCase());
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql-react/src/schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ function parseHeaderString(headersString: string | undefined) {
if (headersString) {
headers = JSON.parse(headersString);
}
} catch (err) {
} catch {
isValidJSON = false;
}
return { headers, isValidJSON };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function fillLeafs(
let ast: DocumentNode;
try {
ast = parse(docString);
} catch (error) {
} catch {
return { insertions, result: docString };
}

Expand Down
2 changes: 1 addition & 1 deletion packages/graphiql-toolkit/src/storage/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class HistoryStore {

try {
parse(query);
} catch (e) {
} catch {
return false;
}

Expand Down
10 changes: 5 additions & 5 deletions packages/graphql-language-service-server/src/GraphQLCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
let parsedQuery;
try {
parsedQuery = parse(query);
} catch (error) {
} catch {
return [];
}
return this.getFragmentDependenciesForAST(parsedQuery, fragmentDefinitions);
Expand Down Expand Up @@ -234,7 +234,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
let parsedQuery;
try {
parsedQuery = parse(query);
} catch (error) {
} catch {
return [];
}
return this.getObjectTypeDependenciesForAST(
Expand Down Expand Up @@ -426,7 +426,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
ast: parse(query),
query,
};
} catch (error) {
} catch {
return { ast: null, query };
}
});
Expand Down Expand Up @@ -488,7 +488,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
ast: parse(query),
query,
};
} catch (error) {
} catch {
return { ast: null, query };
}
});
Expand Down Expand Up @@ -827,7 +827,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
mtime: 0,
size: 0,
});
} catch (_) {
} catch {
// If query has syntax errors, go ahead and still resolve
// the filePath and the content, but leave ast empty.
resolve({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class GraphQLLanguageService {
let validationAst = null;
try {
validationAst = parse(source);
} catch (error) {
} catch {
// the query string is already checked to be parsed properly - errors
// from this parse must be from corrupted fragment dependencies.
// For IDEs we don't care for errors outside of the currently edited
Expand Down Expand Up @@ -306,7 +306,7 @@ export class GraphQLLanguageService {
let ast;
try {
ast = parse(query);
} catch (error) {
} catch {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-language-service-server/src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class Logger implements VSCodeLogger {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
} catch (_) {
} catch {
// intentionally no-op. Don't block the language server even if
// the necessary setup cannot be completed for logger.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ export class MessageProcessor {
toPosition(position),
textDocument.uri,
);
} catch (err) {
} catch {
// these thrown errors end up getting fired before the service is initialized, so lets cool down on that
}

Expand Down Expand Up @@ -983,11 +983,11 @@ export class MessageProcessor {
} else {
try {
this._cacheSchemaFile(uri, project);
} catch (err) {
} catch {
// this string may be an SDL string even, how do we even evaluate this?
}
}
} catch (err) {}
} catch {}
}
async _cacheObjectSchema(
pointer: { [key: string]: any },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function getOutline(documentText: string): Outline | null {
let ast;
try {
ast = parse(documentText);
} catch (error) {
} catch {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const getFragmentDependencies = (
let parsedOperation;
try {
parsedOperation = parse(operationString);
} catch (error) {
} catch {
return [];
}
return getFragmentDependenciesForAST(parsedOperation, fragmentDefinitions);
Expand Down
4 changes: 2 additions & 2 deletions packages/monaco-graphql/src/LanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class LanguageService {
definitionNodes.push(node);
},
});
} catch (err) {
} catch {
throw new Error(
`Failed parsing externalFragmentDefinitions string:\n${this._externalFragmentDefinitionsString}`,
);
Expand Down Expand Up @@ -278,7 +278,7 @@ export class LanguageService {
if (operationFacts?.variableToType) {
return getVariablesJSONSchema(operationFacts.variableToType, options);
}
} catch (err) {}
} catch {}
}
return null;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/monaco-graphql/src/graphqlMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function setupMode(defaults: MonacoGraphQLAPI): IDisposable {
): Promise<GraphQLWorker> => {
try {
return client!.getLanguageServiceWorker(...uris);
} catch (err) {
} catch {
throw new Error('Error fetching graphql language service worker');
}
};
Expand Down
8 changes: 4 additions & 4 deletions packages/vscode-graphql-execution/src/helpers/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class SourceHelper {
// Object type
try {
return JSON.parse(value);
} catch (e) {
} catch {
this.outputChannel.appendLine(
`Failed to parse user input as JSON, please use double quotes.`,
);
Expand Down Expand Up @@ -157,7 +157,7 @@ export class SourceHelper {
const documentText = document.getText();
processGraphQLString(documentText, 0);
return documents;
} catch (err) {}
} catch {}
}

tags.forEach(tag => {
Expand All @@ -177,7 +177,7 @@ export class SourceHelper {
processGraphQLString(contents, result.index + tag.length + 1);
// no-op on exception, so that non-parse-able source files
// don't break the extension while editing
} catch (e) {}
} catch {}
}
});
return documents;
Expand Down Expand Up @@ -236,7 +236,7 @@ export const getFragmentDependencies = async (
let parsedQuery;
try {
parsedQuery = parse(query);
} catch (error) {
} catch {
return [];
}
return getFragmentDependenciesForAST(parsedQuery, fragmentDefinitions);
Expand Down

0 comments on commit 0669767

Please sign in to comment.