MichaReiser/speedy.js

View on GitHub

Showing 322 of 322 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    it("takes the else if branch if the if condition is false but the else if condition is true", async (cb) => {
        expect(await ifElseIfElse(false, 10, true, 20, 30)).toBe(20);
        cb();
    });
Severity: Minor
Found in packages/compiler/__integrationtests__/if-statement.spec.ts and 1 other location - About 30 mins to fix
packages/compiler/__integrationtests__/if-statement.spec.ts on lines 58..61

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 45.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    it("takes the else branch if neither the if nor the else if condition is true", async (cb) => {
        expect(await ifElseIfElse(false, 10, false, 20, 30)).toBe(30);
        cb();
    });
Severity: Minor
Found in packages/compiler/__integrationtests__/if-statement.spec.ts and 1 other location - About 30 mins to fix
packages/compiler/__integrationtests__/if-statement.spec.ts on lines 53..56

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 45.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        if (!whenTrue) {
            const whenTrueTypeName = context.typeChecker.typeToString(whenTrueType);
            throw CodeGenerationDiagnostics.unsupportedImplicitCastOfConditionalResult(node.whenTrue, conditionalTypeName, whenTrueTypeName);
        }
packages/compiler/src/code-generation/code-generators/conditional-expression-code-generator.ts on lines 26..29

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 45.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    private castToWasm(parameterDeclaration: ts.ParameterDeclaration,
                       loadWasmFunctionIdentifier: ts.Identifier,
                       typesIdentifier: ts.Identifier,
                       argumentObjects: ts.Identifier): ts.Expression {
        const parameterType = this.context.typeChecker.getTypeAtLocation(parameterDeclaration);
packages/compiler/src/code-generation/per-file/per-file-code-generator-source-file-rewriter.ts on lines 168..183

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 45.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function toNumber has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    static toNumber(value: Value, valueType: ts.Type, numberType: ts.Type, context: CodeGenerationContext) {
        let numberValue: llvm.Value;
        const llvmValue = value.generateIR(context);

        if (valueType.flags & ts.TypeFlags.BooleanLike) {
Severity: Minor
Found in packages/compiler/src/code-generation/value/primitive.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function emit has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    private static emit(program: ts.Program, compilationContext: CompilationContext) {
        const codeGenerationContextFactory = new DefaultCodeGenerationContextFactory(new NotYetImplementedCodeGenerator());
        const codeGenerator = new PerFileCodeGenerator(compilationContext.llvmContext, codeGenerationContextFactory);

        const logUnknownVisitor = new LogUnknownTransformVisitor();
Severity: Minor
Found in packages/compiler/src/compiler.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function invokeResolvedFunction has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    private invokeResolvedFunction(resolvedFunction: ResolvedFunction, args: llvm.Value[], callerContext: CodeGenerationContext) {
        const llvmFunction = this.getLLVMFunction(resolvedFunction, callerContext, args);
        assert(llvmFunction.type.isPointerTy() && (llvmFunction.type as llvm.PointerType).elementType.isFunctionTy(), "Expected pointer to a function type");

        const callArguments = this.getCallArguments(resolvedFunction, args, callerContext);

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function getTypeAtLocation has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    getTypeAtLocation(node: ts.Node): ts.Type {
        let type = this.toSupportedType(this.tsTypeChecker.getTypeAtLocation(node));

        // e.g. when const x: int[] = [] then the type of [] is never[] that is quite unfortunate. Take the contextual
        // type information into consideration in this case (but do not otherwise. Otherwise let x: number = 3 returns unexpected results.
Severity: Minor
Found in packages/compiler/src/typescript-type-checker.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function create has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    static create(type: ts.ObjectType, context: CodeGenerationContext) {
        const baseTypes = type.getBaseTypes();

        const declaration = type.getSymbol().valueDeclaration as ts.ClassDeclaration;
        if (baseTypes && type.getBaseTypes().length > 0) {
Severity: Minor
Found in packages/compiler/src/code-generation/value/speedy-js-class-reference.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function isFunctionType has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

export function isFunctionType(type: ts.Type) {
    if (type.flags & ts.TypeFlags.Union) {
        const unionType = type as ts.UnionType;

        if (unionType.types.length === 2 && unionType.types.some(t => !!(t.flags & ts.TypeFlags.Undefined))) {
Severity: Minor
Found in packages/compiler/src/code-generation/util/types.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function toLlvmArgumentTypes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    private toLlvmArgumentTypes(resolvedFunction: ResolvedFunction,
                                numberOfArguments: number,
                                context: CodeGenerationContext,
                                objectReference?: ObjectReference) {
        const argumentTypes = objectReference ? [this.typeConverter.convert(objectReference.type, TypePlace.THIS)] : [];
Severity: Minor
Found in packages/compiler/src/code-generation/value/function-factory.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function createTransformer has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

export function createTransformer(transformVisitor: TransformVisitor, transformationContext: ts.TransformationContext): ts.Transformer<ts.SourceFile> {
    const context: TransformVisitorContext = {
        requestEmitHelper(emitHelper: ts.EmitHelper): void {
            transformationContext.requestEmitHelper(emitHelper);
        },
Severity: Minor
Found in packages/compiler/src/transform/transform-visitor.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function castImplicit has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    castImplicit(type: ts.Type, context: CodeGenerationContext): Value | undefined {
        if (this.type === type) {
            return this;
        }

Severity: Minor
Found in packages/compiler/src/code-generation/value/primitive.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function toInt32 has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    static toInt32(value: Value, valueType: ts.Type, int32Type: ts.Type, context: CodeGenerationContext) {
        let intValue: llvm.Value;

        if (valueType.flags & ts.TypeFlags.IntLike) {
            intValue = value.generateIR(context);
Severity: Minor
Found in packages/compiler/src/code-generation/value/primitive.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function invoke has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

export function invoke(callee: FunctionPointer, args: llvm.Value[], returnType: llvm.Type, callerContext: CodeGenerationContext, options?: InvokeOptions) {
    const functionType = callee.type.elementType;
    const initializedOptions = options || {};

    assert(args.length === functionType.numParams, `Calling function with less arguments than declared parameters`);
Severity: Minor
Found in packages/compiler/src/code-generation/util/functions.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function verifyIsSupportedSpeedyJSFunction has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

export function verifyIsSupportedSpeedyJSFunction(declaration: ts.Declaration, context: CodeGenerationContext) {
    // tslint:disable-next-line: max-line-length
    if (!(declaration.kind === ts.SyntaxKind.FunctionDeclaration || declaration.kind === ts.SyntaxKind.MethodDeclaration || declaration.kind === ts.SyntaxKind.Constructor)) {
        throw CodeGenerationDiagnostics.unsupportedFunctionDeclaration(declaration);
    }
Severity: Minor
Found in packages/compiler/src/code-generation/value/speedyjs-function-factory.ts - About 25 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Interface has only a call signature — use type CodeGenerationContextConstructor = new (...args: any[]) => CodeGenerationContext; instead.
Open

    new (...args: any[]): CodeGenerationContext;

Rule: callable-types

An interface or literal type with just a call signature can be written as a function type.

Rationale

style

Notes
  • TypeScript Only
  • Has Fix

Config

Not configurable.

For more information see this page.

Interface has only a call signature — use type WebAssemblyMemoryConstructor = new (memoryDescriptor: { initial: number, maximum?: number }) => WebAssemblyMemory; instead.
Open

    new (memoryDescriptor: { initial: number, maximum?: number }): WebAssemblyMemory;

Rule: callable-types

An interface or literal type with just a call signature can be written as a function type.

Rationale

style

Notes
  • TypeScript Only
  • Has Fix

Config

Not configurable.

For more information see this page.

TODO found
Open

                // TODO Objekt erstellen und dann methode

TODO found
Open

                // TODO this can be removed when a reference to the type descriptor is added to each object
Severity
Category
Status
Source
Language