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

chore: fixed sonar issues #526

Merged
merged 3 commits into from
Jun 3, 2024
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
4 changes: 2 additions & 2 deletions packages/create-jitar/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function execute()
const argTargetDir = formatTargetDir(argv._[0]);
const argTemplate = argv.template || argv.t;

let targetDir = argTargetDir || defaultTargetDir;
let targetDir = argTargetDir ?? defaultTargetDir;

const getProjectName = () => targetDir === '.'
? path.basename(path.resolve())
Expand All @@ -54,7 +54,7 @@ async function execute()
initial: defaultTargetDir,
onState: (state) =>
{
targetDir = formatTargetDir(state.value) || defaultTargetDir;
targetDir = formatTargetDir(state.value) ?? defaultTargetDir;
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion packages/create-jitar/templates/lit/src/my-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class MyElement extends LitElement
`
}

static styles = css`
static readonly styles = css`
:host {
max-width: 1280px;
margin: 0 auto;
Expand Down
2 changes: 1 addition & 1 deletion packages/create-jitar/templates/svelte/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import './app.css'
import App from './App.svelte'

const app = new App({
target: document.getElementById('app') as HTMLElement,
target: document.getElementById('app'),
})

export default app
8 changes: 3 additions & 5 deletions packages/reflection/src/models/ReflectionClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,21 @@ export default class ReflectionClass extends ReflectionMember
{
const declaration = this.getDeclaration(name);

return (declaration !== undefined && declaration.isPublic)
|| this.hasGetter(name);
return declaration?.isPublic || this.hasGetter(name);
}

canWrite(name: string): boolean
{
const declaration = this.getDeclaration(name);

return (declaration !== undefined && declaration.isPublic)
|| this.hasSetter(name);
return declaration?.isPublic || this.hasSetter(name);
}

canCall(name: string): boolean
{
const funktion = this.getFunction(name);

return funktion !== undefined && funktion.isPublic;
return funktion?.isPublic ?? false;
}

toString(): string
Expand Down
18 changes: 9 additions & 9 deletions packages/reflection/src/parser/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default class Parser
throw new UnexpectedParseResult('an import definition');
}

return model as ReflectionImport;
return model;
}

parseExport(code: string): ReflectionExport
Expand All @@ -101,7 +101,7 @@ export default class Parser
throw new UnexpectedParseResult('an export definition');
}

return model as ReflectionExport;
return model;
}

parseDeclaration(code: string): ReflectionDeclaration
Expand All @@ -113,7 +113,7 @@ export default class Parser
throw new UnexpectedParseResult('a declaration definition');
}

return model as ReflectionDeclaration;
return model;
}

parseFunction(code: string): ReflectionFunction
Expand All @@ -126,7 +126,7 @@ export default class Parser
throw new UnexpectedParseResult('a function definition');
}

return model as ReflectionFunction;
return model;
}

parseClass(code: string): ReflectionClass
Expand All @@ -139,7 +139,7 @@ export default class Parser
throw new UnexpectedParseResult('a class definition');
}

return model as ReflectionClass;
return model;
}

#parseScope(tokenList: TokenList): ReflectionScope
Expand Down Expand Up @@ -175,7 +175,7 @@ export default class Parser
{
const next = tokenList.next;

if (next !== undefined && next.hasValue(Operator.ARROW))
if (next?.hasValue(Operator.ARROW))
{
return this.#parseArrowFunction(tokenList, isAsync);
}
Expand Down Expand Up @@ -216,7 +216,7 @@ export default class Parser
{
const next = this.#peekAfterBlock(tokenList, Group.OPEN, Group.CLOSE);

if (next !== undefined && next.hasValue(Operator.ARROW))
if (next?.hasValue(Operator.ARROW))
{
return this.#parseArrowFunction(tokenList, isAsync);
}
Expand Down Expand Up @@ -393,7 +393,7 @@ export default class Parser

token = tokenList.step(); // Read away the name

if (token !== undefined && token.hasValue(Keyword.FROM))
if (token?.hasValue(Keyword.FROM))
{
token = tokenList.step(); // Read away the FROM keyword

Expand All @@ -419,7 +419,7 @@ export default class Parser
let from: string | undefined = undefined;
let token = tokenList.current;

if (token !== undefined && token.hasValue(Keyword.FROM))
if (token?.hasValue(Keyword.FROM))
{
token = tokenList.step(); // Read away the FROM keyword
from = token.value;
Expand Down
21 changes: 10 additions & 11 deletions packages/serialization/src/serializers/ClassSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import ClassNotFound from '../errors/ClassNotFound.js';
import InvalidClass from '../errors/InvalidClass.js';
import ClassLoader from '../interfaces/ClassLoader.js';
import Loadable from '../types/Loadable.js';
import FlexObject from '../types/serialized/SerializableObject.js';
import SerializableObject from '../types/serialized/SerializableObject.js';
import SerializedClass from '../types/serialized/SerializedClass.js';

Expand Down Expand Up @@ -50,8 +49,8 @@ export default class ClassSerializer extends ValueSerializer

const name = clazz.name;
const source = (clazz as Loadable).source;
const args: FlexObject = await this.#serializeConstructor(model, parameterNames, object);
const fields: FlexObject = await this.#serializeFields(model, parameterNames, object);
const args: SerializableObject = await this.#serializeConstructor(model, parameterNames, object);
const fields: SerializableObject = await this.#serializeFields(model, parameterNames, object);

return { serialized: true, name: name, source: source, args: args, fields: fields };
}
Expand All @@ -64,16 +63,16 @@ export default class ClassSerializer extends ValueSerializer
return parameters.map(parameter => parameter.name);
}

async #serializeConstructor(model: ReflectionClass, includeNames: string[], object: object): Promise<FlexObject>
async #serializeConstructor(model: ReflectionClass, includeNames: string[], object: object): Promise<SerializableObject>
{
const args: FlexObject = {};
const args: SerializableObject = {};

for (const name of includeNames)
{
// Constructor parameters that can't be read make it impossible to fully reconstruct the object.

const objectValue = model.canRead(name)
? await this.serializeOther((object as FlexObject)[name])
? await this.serializeOther((object as SerializableObject)[name])
: undefined;

args[name] = objectValue;
Expand All @@ -82,9 +81,9 @@ export default class ClassSerializer extends ValueSerializer
return args;
}

async #serializeFields(model: ReflectionClass, excludeNames: string[], object: object): Promise<FlexObject>
async #serializeFields(model: ReflectionClass, excludeNames: string[], object: object): Promise<SerializableObject>
{
const fields: FlexObject = {};
const fields: SerializableObject = {};

for (const property of model.writable)
{
Expand All @@ -97,7 +96,7 @@ export default class ClassSerializer extends ValueSerializer
continue;
}

fields[name] = await this.serializeOther((object as FlexObject)[name]);
fields[name] = await this.serializeOther((object as SerializableObject)[name]);
}

return fields;
Expand Down Expand Up @@ -130,7 +129,7 @@ export default class ClassSerializer extends ValueSerializer
return instance;
}

async #deserializeConstructor(clazz: Function, args: FlexObject): Promise<unknown[]>
async #deserializeConstructor(clazz: Function, args: SerializableObject): Promise<unknown[]>
{
const model = reflector.fromClass(clazz, true);
const constructor = model.getFunction('constructor');
Expand All @@ -150,7 +149,7 @@ export default class ClassSerializer extends ValueSerializer
{
if (loadable.source === undefined)
{
return (globalThis as FlexObject)[loadable.name];
return (globalThis as SerializableObject)[loadable.name];
}

return this.#classLoader.loadClass(loadable);
Expand Down
4 changes: 2 additions & 2 deletions packages/serialization/src/serializers/ErrorSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class ErrorSerializer extends ValueSerializer
return false;
}

const error = value as Object;
const error = value;

return error.constructor === Error
|| error.constructor === EvalError
Expand Down Expand Up @@ -52,7 +52,7 @@ export default class ErrorSerializer extends ValueSerializer
{
const clazz = (globalThis as Record<string, unknown>)[object.type] as (new () => Error);

const error = new clazz() as Error;
const error = new clazz();
error.stack = object.stack;
error.message = object.message;
error.cause = object.cause;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { z } from 'zod';

import ProcedureRuntimeConfiguration from './ProcedureRuntimeConfiguration';
import { override } from 'prompts';

export const standaloneSchema = z
.object({
Expand Down
2 changes: 1 addition & 1 deletion packages/server-nodejs/src/controllers/RPCController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export default class RPCController
return 500;
}

const errorClass = (error as Object).constructor as Function;
const errorClass = error.constructor;

if (this.#isClassType(errorClass, BAD_REQUEST_NAME)) return 400;
if (this.#isClassType(errorClass, UNAUTHORIZED_NAME)) return 401;
Expand Down
5 changes: 1 addition & 4 deletions packages/server-nodejs/src/errors/ConversionError.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@

export default class ConversionError extends Error
{
constructor(message: string)
{
super(message);
}

}
4 changes: 1 addition & 3 deletions packages/server-nodejs/src/utils/RuntimeConfigurator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ export default class RuntimeConfigurator

await this.#buildCache(sourceLocation, cacheLocation);

const segmentNames = configuration.segments === undefined
? await this.#getWorkerSegmentNames(fileManager)
: configuration.segments;
const segmentNames = configuration.segments ?? await this.#getWorkerSegmentNames(fileManager);

const assets = configuration.assets !== undefined
? await fileManager.getAssetFiles(configuration.assets)
Expand Down