Ikagaka/routable-component.js

View on GitHub

Showing 22 of 22 total issues

Function _attachRouteEvent has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  _attachRouteEvent(route: RoutableComponentRoute) {
    const listener = (...args: any[]) => {
      if (!this.controllers[route.controller]) {
        if (!(route.controller in this.controllerClasses)) {
          throw new Error(`controller [${route.controller}] not found`);
Severity: Minor
Found in src/lib/routable-component.ts - About 1 hr 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 event has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  event(...args: string[]) {
    if (this._currentFrom && this._currentController) {
      if (args.length > 2) throw new Error("arguments too long");
      this.eventOnFromController(args[0], args[1]);
    } else if (this._currentFrom) {
Severity: Minor
Found in src/lib/routable-component.ts - About 1 hr 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

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

  eventOnFrom(event: string, controller: string, action: string = event) {
    const from = this._currentFrom;
    this.addRoute(from, event, controller, action);
  }
Severity: Major
Found in src/lib/routable-component.ts and 1 other location - About 1 hr to fix
src/lib/routable-component.ts on lines 263..266

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 56.

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

  eventOnController(from: string, event: string, action: string = event) {
    const controller = this._currentController;
    this.addRoute(from, event, controller, action);
  }
Severity: Major
Found in src/lib/routable-component.ts and 1 other location - About 1 hr to fix
src/lib/routable-component.ts on lines 252..255

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 56.

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

  controller(controller: string, block: RoutesDifiner) {
    this._currentController = controller;
    block(this);
    delete this._currentController;
  }
Severity: Minor
Found in src/lib/routable-component.ts and 1 other location - About 50 mins to fix
src/lib/routable-component.ts on lines 284..288

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 51.

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

  from(from: string, block: RoutesDifiner) {
    this._currentFrom = from;
    block(this);
    delete this._currentFrom;
  }
Severity: Minor
Found in src/lib/routable-component.ts and 1 other location - About 50 mins to fix
src/lib/routable-component.ts on lines 295..299

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 51.

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

    } else if (this._currentController) {
      if (args.length > 3) throw new Error("arguments too long");
      this.eventOnController(args[0], args[1], args[2]);
    } else {
      this.eventOnNone(args[0], args[1], args[2], args[3]);
Severity: Minor
Found in src/lib/routable-component.ts and 1 other location - About 40 mins to fix
src/lib/routable-component.ts on lines 224..232

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 48.

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

    } else if (this._currentFrom) {
      if (args.length > 3) throw new Error("arguments too long");
      this.eventOnFrom(args[0], args[1], args[2]);
    } else if (this._currentController) {
      if (args.length > 3) throw new Error("arguments too long");
Severity: Minor
Found in src/lib/routable-component.ts and 1 other location - About 40 mins to fix
src/lib/routable-component.ts on lines 227..232

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 48.

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 unregisterComponent has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  unregisterComponent(name: string) {
    if (this.components[name] && this._listeners[name]) {
      const listeners = this._listeners[name];
      for (const event of Object.keys(listeners)) {
        for (const listener of listeners[event]) {
Severity: Minor
Found in src/lib/routable-component.ts - About 35 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 _checkConstructorArguments has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  _checkConstructorArguments(from: string, event: string, controller: string, action: string) {
    const isString = (obj: any) => typeof obj === "string" || obj instanceof String;
    if (from == null) throw new Error("register routing error: from is empty!");
    if (event == null) throw new Error("register routing error: event is empty!");
    if (controller == null) throw new Error("register routing error: controller is empty!");
Severity: Minor
Found in src/lib/routable-component.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

This overload and the one on line 182 can be combined into one signature with an optional parameter.
Open

  event(from: string, event: string, controller: string, action?: string): void;
Severity: Minor
Found in src/lib/routable-component.ts by tslint

Rule: unified-signatures

Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter.

Notes
  • TypeScript Only

Config

Not configurable.

Examples
"unified-signatures": true

For more information see this page.

Type assertion using the '<>' syntax is forbidden. Use the 'as' syntax instead.
Open

    (<EventEmitter> this.components[route.from]).on(route.event, listener);
Severity: Minor
Found in src/lib/routable-component.ts by tslint

Rule: no-angle-bracket-type-assertion

Requires the use of as Type for type assertions instead of <Type>.

Rationale

Both formats of type assertions have the same effect, but only as type assertions work in .tsx files. This rule ensures that you have a consistent type assertion style across your codebase.

Notes
  • TypeScript Only
  • Has Fix

Config

Not configurable.

Examples
"no-angle-bracket-type-assertion": true

For more information see this page.

This overload and the one on line 182 can be combined into one signature with an optional parameter.
Open

  event(from: string, event: string, action?: string): void;
Severity: Minor
Found in src/lib/routable-component.ts by tslint

Rule: unified-signatures

Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter.

Notes
  • TypeScript Only

Config

Not configurable.

Examples
"unified-signatures": true

For more information see this page.

Type assertion using the '<>' syntax is forbidden. Use the 'as' syntax instead.
Open

        (<any> this.controllers[route.controller])[route.action](...args); // this維持のため
Severity: Minor
Found in src/lib/routable-component.ts by tslint

Rule: no-angle-bracket-type-assertion

Requires the use of as Type for type assertions instead of <Type>.

Rationale

Both formats of type assertions have the same effect, but only as type assertions work in .tsx files. This rule ensures that you have a consistent type assertion style across your codebase.

Notes
  • TypeScript Only
  • Has Fix

Config

Not configurable.

Examples
"no-angle-bracket-type-assertion": true

For more information see this page.

An empty interface is equivalent to {}.
Open

export interface RoutableComponentController {
Severity: Minor
Found in src/lib/routable-component.ts by tslint

Rule: no-empty-interface

Forbids empty interfaces.

Rationale

An empty interface is equivalent to its supertype (or {}).

Notes
  • TypeScript Only

Config

Not configurable.

For more information see this page.

This overload and the one on line 196 can be combined into one signature with an optional parameter.
Open

  event(from: string, event: string, controller: string, action?: string): void;
Severity: Minor
Found in src/lib/routable-component.ts by tslint

Rule: unified-signatures

Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter.

Notes
  • TypeScript Only

Config

Not configurable.

Examples
"unified-signatures": true

For more information see this page.

A maximum of 1 class per file is allowed.
Open

export class RoutableComponentRoute {
  private readonly _from: string;
  private readonly _event: string;
  private readonly _controller: string;
  private readonly _action: string;
Severity: Minor
Found in src/lib/routable-component.ts by tslint

Rule: max-classes-per-file

A file may not contain more than the specified number of classes

Rationale

Ensures that files have a single responsibility so that that classes each exist in their own files

Config

The one required argument is an integer indicating the maximum number of classes that can appear in a file. An optional argument "exclude-class-expressions" can be provided to exclude class expressions from the overall class count.

Examples
"max-classes-per-file": true,1
"max-classes-per-file": true,5,exclude-class-expressions
Schema
{
  "type": "array",
  "items": [
    {
      "type": "number",
      "minimum": 1
    },
    {
      "type": "string",
      "enum": [
        "exclude-class-expressions"
      ]
    }
  ],
  "additionalItems": false,
  "minLength": 1,
  "maxLength": 2
}

For more information see this page.

This overload and the one on line 182 can be combined into one signature with an optional parameter.
Open

  event(event: string, controller: string, action?: string): void;
Severity: Minor
Found in src/lib/routable-component.ts by tslint

Rule: unified-signatures

Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter.

Notes
  • TypeScript Only

Config

Not configurable.

Examples
"unified-signatures": true

For more information see this page.

Type assertion using the '<>' syntax is forbidden. Use the 'as' syntax instead.
Open

          (<EventEmitter> this.components[name]).removeListener(event, listener);
Severity: Minor
Found in src/lib/routable-component.ts by tslint

Rule: no-angle-bracket-type-assertion

Requires the use of as Type for type assertions instead of <Type>.

Rationale

Both formats of type assertions have the same effect, but only as type assertions work in .tsx files. This rule ensures that you have a consistent type assertion style across your codebase.

Notes
  • TypeScript Only
  • Has Fix

Config

Not configurable.

Examples
"no-angle-bracket-type-assertion": true

For more information see this page.

Type assertion using the '<>' syntax is forbidden. Use the 'as' syntax instead.
Open

      const action = (<any> this.controllers[route.controller])[route.action];
Severity: Minor
Found in src/lib/routable-component.ts by tslint

Rule: no-angle-bracket-type-assertion

Requires the use of as Type for type assertions instead of <Type>.

Rationale

Both formats of type assertions have the same effect, but only as type assertions work in .tsx files. This rule ensures that you have a consistent type assertion style across your codebase.

Notes
  • TypeScript Only
  • Has Fix

Config

Not configurable.

Examples
"no-angle-bracket-type-assertion": true

For more information see this page.

Severity
Category
Status
Source
Language