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 sonarjs/no-small-switch and sonarjs/no-duplicated-branches rules #2966

Merged
merged 1 commit into from
Jan 9, 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
7 changes: 7 additions & 0 deletions .changeset/funny-bats-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'graphql-language-service-cli': patch
'graphql-language-service-server': patch
'vscode-graphql-execution': patch
---

enable `sonarjs/no-small-switch` and `sonarjs/no-duplicated-branches` rules
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ module.exports = {
'unicorn/no-lonely-if': 'error',
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': 'error',
'sonarjs/no-small-switch': 'error',
'sonarjs/no-duplicated-branches': 'error',
},

plugins: ['@typescript-eslint', 'promise', 'sonarjs', 'unicorn'],
Expand Down
54 changes: 25 additions & 29 deletions packages/graphql-language-service-cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,37 +107,33 @@ if (!command) {
process.exit(0);
}

switch (command) {
case 'server':
process.on('uncaughtException', error => {
process.stderr.write(
'An error was thrown from GraphQL language service: ' + String(error),
);
// don't exit at all if there is an uncaughtException
// process.exit(0);
});
if (command === 'server') {
process.on('uncaughtException', error => {
process.stderr.write(
'An error was thrown from GraphQL language service: ' + String(error),
);
// don't exit at all if there is an uncaughtException
// process.exit(0);
});

const options: { [key: string]: any } = {};
if (argv?.port) {
options.port = argv.port;
}
if (argv?.method) {
options.method = argv.method;
}
if (argv?.configDir) {
options.configDir = argv.configDir;
}
try {
startServer(options);
} catch (error) {
const logger = new Logger();
logger.error(String(error));
}
break;
default: {
client(command as string, argv as { [key: string]: string });
break;
const options: { [key: string]: any } = {};
if (argv?.port) {
options.port = argv.port;
}
if (argv?.method) {
options.method = argv.method;
}
if (argv?.configDir) {
options.configDir = argv.configDir;
}
try {
startServer(options);
} catch (error) {
const logger = new Logger();
logger.error(String(error));
}
} else {
client(command as string, argv as { [key: string]: string });
}

// Exit the process when stream closes from remote end.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,10 @@ export class MessageProcessor {
}
}
_handleConfigError({ err }: { err: unknown; uri?: string }) {
if (err instanceof ConfigNotFoundError) {
if (err instanceof ConfigNotFoundError || err instanceof ConfigEmptyError) {
// TODO: obviously this needs to become a map by workspace from uri
// for workspaces support
this._isGraphQLConfigMissing = true;

this._logConfigError(err.message);
} else if (err instanceof ProjectNotFoundError) {
// this is the only case where we don't invalidate config;
Expand All @@ -270,9 +269,6 @@ export class MessageProcessor {
} else if (err instanceof ConfigInvalidError) {
this._isGraphQLConfigMissing = true;
this._logConfigError(`Invalid configuration\n${err.message}`);
} else if (err instanceof ConfigEmptyError) {
this._isGraphQLConfigMissing = true;
this._logConfigError(err.message);
} else if (err instanceof LoaderNoResultError) {
this._isGraphQLConfigMissing = true;
this._logConfigError(err.message);
Expand Down
16 changes: 1 addition & 15 deletions packages/vscode-graphql-execution/src/helpers/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,7 @@ export class SourceHelper {
}
break;
case 'String':
if (value.length && !Array.isArray(value)) {
return null;
}
break;
case 'ID':
if (value.length && !Array.isArray(value)) {
return null;
}
break;
case 'Enum':
if (value.length && !Array.isArray(value)) {
return null;
Expand Down Expand Up @@ -140,13 +132,7 @@ export class SourceHelper {
FragmentDefinition(node) {
const existingDef = fragmentDefinitions.get(node.name.value);
const newVal = print(node);
if (existingDef && existingDef.content !== newVal) {
fragmentDefinitions.set(node.name.value, {
definition: node,
content: newVal,
filePath: source.location,
});
} else if (!existingDef) {
if ((existingDef && existingDef.content !== newVal) || !existingDef) {
fragmentDefinitions.set(node.name.value, {
definition: node,
content: newVal,
Expand Down