tkqubo/conditional-decorator

View on GitHub
test/conditional-as-property-decorator.spec.ts

Summary

Maintainability
C
1 day
Test Coverage

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

    describe('(test: boolean, decorator: PropertyDecorator): PropertyDecorator', () => {
      it('decorates if test is truthy', () => {
        assert(spy1.callCount === 1);
        assert(spy1.getCall(0).args[0] === TargetClass1.prototype);
        assert(spy1.getCall(0).args[1] === 'name');
Severity: Major
Found in test/conditional-as-property-decorator.spec.ts and 1 other location - About 4 hrs to fix
test/conditional-as-property-decorator.spec.ts on lines 53..62

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

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

    describe('(test: (target?: Object, key?: string|symbol) => boolean, decorator: PropertyDecorator): PropertyDecorator', () => {
      it('decorates if test function returns true', () => {
        assert(spy3.callCount === 1);
        assert(spy3.getCall(0).args[0] === TargetClass2.prototype);
        assert(spy3.getCall(0).args[1] === 'name');
Severity: Major
Found in test/conditional-as-property-decorator.spec.ts and 1 other location - About 4 hrs to fix
test/conditional-as-property-decorator.spec.ts on lines 42..51

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

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

expected variable-declaration: 'spy3' to have a typedef
Open

const spy3 = sinon.spy();

Rule: typedef

Requires type definitions to exist.

Notes
  • TypeScript Only

Config

Several arguments may be optionally provided:

  • "call-signature" checks return type of functions.
  • "arrow-call-signature" checks return type of arrow functions.
  • "parameter" checks type specifier of function parameters for non-arrow functions.
  • "arrow-parameter" checks type specifier of function parameters for arrow functions.
  • "property-declaration" checks return types of interface properties.
  • "variable-declaration" checks non-binding variable declarations.
  • "variable-declaration-ignore-function" ignore variable declarations for non-arrow and arrow functions.
  • "member-variable-declaration" checks member variable declarations.
  • "object-destructuring" checks object destructuring declarations.
  • "array-destructuring" checks array destructuring declarations.
Examples
"typedef": true,call-signature,parameter,member-variable-declaration
Schema
{
  "type": "array",
  "items": {
    "type": "string",
    "enum": [
      "call-signature",
      "arrow-call-signature",
      "parameter",
      "arrow-parameter",
      "property-declaration",
      "variable-declaration",
      "variable-declaration-ignore-function",
      "member-variable-declaration",
      "object-destructuring",
      "array-destructuring"
    ]
  },
  "minLength": 0,
  "maxLength": 10
}

For more information see this page.

expected variable-declaration: 'decor4' to have a typedef
Open

const decor4 = createPropertyDecorator(spy4);

Rule: typedef

Requires type definitions to exist.

Notes
  • TypeScript Only

Config

Several arguments may be optionally provided:

  • "call-signature" checks return type of functions.
  • "arrow-call-signature" checks return type of arrow functions.
  • "parameter" checks type specifier of function parameters for non-arrow functions.
  • "arrow-parameter" checks type specifier of function parameters for arrow functions.
  • "property-declaration" checks return types of interface properties.
  • "variable-declaration" checks non-binding variable declarations.
  • "variable-declaration-ignore-function" ignore variable declarations for non-arrow and arrow functions.
  • "member-variable-declaration" checks member variable declarations.
  • "object-destructuring" checks object destructuring declarations.
  • "array-destructuring" checks array destructuring declarations.
Examples
"typedef": true,call-signature,parameter,member-variable-declaration
Schema
{
  "type": "array",
  "items": {
    "type": "string",
    "enum": [
      "call-signature",
      "arrow-call-signature",
      "parameter",
      "arrow-parameter",
      "property-declaration",
      "variable-declaration",
      "variable-declaration-ignore-function",
      "member-variable-declaration",
      "object-destructuring",
      "array-destructuring"
    ]
  },
  "minLength": 0,
  "maxLength": 10
}

For more information see this page.

expected variable-declaration: 'spy2' to have a typedef
Open

const spy2 = sinon.spy();

Rule: typedef

Requires type definitions to exist.

Notes
  • TypeScript Only

Config

Several arguments may be optionally provided:

  • "call-signature" checks return type of functions.
  • "arrow-call-signature" checks return type of arrow functions.
  • "parameter" checks type specifier of function parameters for non-arrow functions.
  • "arrow-parameter" checks type specifier of function parameters for arrow functions.
  • "property-declaration" checks return types of interface properties.
  • "variable-declaration" checks non-binding variable declarations.
  • "variable-declaration-ignore-function" ignore variable declarations for non-arrow and arrow functions.
  • "member-variable-declaration" checks member variable declarations.
  • "object-destructuring" checks object destructuring declarations.
  • "array-destructuring" checks array destructuring declarations.
Examples
"typedef": true,call-signature,parameter,member-variable-declaration
Schema
{
  "type": "array",
  "items": {
    "type": "string",
    "enum": [
      "call-signature",
      "arrow-call-signature",
      "parameter",
      "arrow-parameter",
      "property-declaration",
      "variable-declaration",
      "variable-declaration-ignore-function",
      "member-variable-declaration",
      "object-destructuring",
      "array-destructuring"
    ]
  },
  "minLength": 0,
  "maxLength": 10
}

For more information see this page.

The class property 'name' must be marked either 'private', 'public', or 'protected'
Open

  @conditional(testProperty, decor3) name: string;

Rule: member-access

Requires explicit visibility declarations for class members.

Rationale

Explicit visibility declarations can make code more readable and accessible for those new to TS.

Other languages such as C# default to private, unlike TypeScript's default of public. Members lacking a visibility declaration may be an indication of an accidental leak of class internals.

Notes
  • TypeScript Only
  • Has Fix

Config

These arguments may be optionally provided:

  • "no-public" forbids public accessibility to be specified, because this is the default.
  • "check-accessor" enforces explicit visibility on get/set accessors
  • "check-constructor" enforces explicit visibility on constructors
  • "check-parameter-property" enforces explicit visibility on parameter properties
Examples
"member-access": true
"member-access": true,no-public
"member-access": true,check-accessor
Schema
{
  "type": "array",
  "items": {
    "type": "string",
    "enum": [
      "no-public",
      "check-accessor",
      "check-constructor",
      "check-parameter-property"
    ]
  },
  "minLength": 0,
  "maxLength": 4
}

For more information see this page.

expected variable-declaration: 'spy1' to have a typedef
Open

const spy1 = sinon.spy();

Rule: typedef

Requires type definitions to exist.

Notes
  • TypeScript Only

Config

Several arguments may be optionally provided:

  • "call-signature" checks return type of functions.
  • "arrow-call-signature" checks return type of arrow functions.
  • "parameter" checks type specifier of function parameters for non-arrow functions.
  • "arrow-parameter" checks type specifier of function parameters for arrow functions.
  • "property-declaration" checks return types of interface properties.
  • "variable-declaration" checks non-binding variable declarations.
  • "variable-declaration-ignore-function" ignore variable declarations for non-arrow and arrow functions.
  • "member-variable-declaration" checks member variable declarations.
  • "object-destructuring" checks object destructuring declarations.
  • "array-destructuring" checks array destructuring declarations.
Examples
"typedef": true,call-signature,parameter,member-variable-declaration
Schema
{
  "type": "array",
  "items": {
    "type": "string",
    "enum": [
      "call-signature",
      "arrow-call-signature",
      "parameter",
      "arrow-parameter",
      "property-declaration",
      "variable-declaration",
      "variable-declaration-ignore-function",
      "member-variable-declaration",
      "object-destructuring",
      "array-destructuring"
    ]
  },
  "minLength": 0,
  "maxLength": 10
}

For more information see this page.

The class property 'age' must be marked either 'private', 'public', or 'protected'
Open

  age: number;

Rule: member-access

Requires explicit visibility declarations for class members.

Rationale

Explicit visibility declarations can make code more readable and accessible for those new to TS.

Other languages such as C# default to private, unlike TypeScript's default of public. Members lacking a visibility declaration may be an indication of an accidental leak of class internals.

Notes
  • TypeScript Only
  • Has Fix

Config

These arguments may be optionally provided:

  • "no-public" forbids public accessibility to be specified, because this is the default.
  • "check-accessor" enforces explicit visibility on get/set accessors
  • "check-constructor" enforces explicit visibility on constructors
  • "check-parameter-property" enforces explicit visibility on parameter properties
Examples
"member-access": true
"member-access": true,no-public
"member-access": true,check-accessor
Schema
{
  "type": "array",
  "items": {
    "type": "string",
    "enum": [
      "no-public",
      "check-accessor",
      "check-constructor",
      "check-parameter-property"
    ]
  },
  "minLength": 0,
  "maxLength": 4
}

For more information see this page.

expected variable-declaration: 'decor2' to have a typedef
Open

const decor2 = createPropertyDecorator(spy2);

Rule: typedef

Requires type definitions to exist.

Notes
  • TypeScript Only

Config

Several arguments may be optionally provided:

  • "call-signature" checks return type of functions.
  • "arrow-call-signature" checks return type of arrow functions.
  • "parameter" checks type specifier of function parameters for non-arrow functions.
  • "arrow-parameter" checks type specifier of function parameters for arrow functions.
  • "property-declaration" checks return types of interface properties.
  • "variable-declaration" checks non-binding variable declarations.
  • "variable-declaration-ignore-function" ignore variable declarations for non-arrow and arrow functions.
  • "member-variable-declaration" checks member variable declarations.
  • "object-destructuring" checks object destructuring declarations.
  • "array-destructuring" checks array destructuring declarations.
Examples
"typedef": true,call-signature,parameter,member-variable-declaration
Schema
{
  "type": "array",
  "items": {
    "type": "string",
    "enum": [
      "call-signature",
      "arrow-call-signature",
      "parameter",
      "arrow-parameter",
      "property-declaration",
      "variable-declaration",
      "variable-declaration-ignore-function",
      "member-variable-declaration",
      "object-destructuring",
      "array-destructuring"
    ]
  },
  "minLength": 0,
  "maxLength": 10
}

For more information see this page.

expected variable-declaration: 'decor3' to have a typedef
Open

const decor3 = createPropertyDecorator(spy3);

Rule: typedef

Requires type definitions to exist.

Notes
  • TypeScript Only

Config

Several arguments may be optionally provided:

  • "call-signature" checks return type of functions.
  • "arrow-call-signature" checks return type of arrow functions.
  • "parameter" checks type specifier of function parameters for non-arrow functions.
  • "arrow-parameter" checks type specifier of function parameters for arrow functions.
  • "property-declaration" checks return types of interface properties.
  • "variable-declaration" checks non-binding variable declarations.
  • "variable-declaration-ignore-function" ignore variable declarations for non-arrow and arrow functions.
  • "member-variable-declaration" checks member variable declarations.
  • "object-destructuring" checks object destructuring declarations.
  • "array-destructuring" checks array destructuring declarations.
Examples
"typedef": true,call-signature,parameter,member-variable-declaration
Schema
{
  "type": "array",
  "items": {
    "type": "string",
    "enum": [
      "call-signature",
      "arrow-call-signature",
      "parameter",
      "arrow-parameter",
      "property-declaration",
      "variable-declaration",
      "variable-declaration-ignore-function",
      "member-variable-declaration",
      "object-destructuring",
      "array-destructuring"
    ]
  },
  "minLength": 0,
  "maxLength": 10
}

For more information see this page.

The class property 'age' must be marked either 'private', 'public', or 'protected'
Open

  @conditional(testProperty, decor4) age: number;

Rule: member-access

Requires explicit visibility declarations for class members.

Rationale

Explicit visibility declarations can make code more readable and accessible for those new to TS.

Other languages such as C# default to private, unlike TypeScript's default of public. Members lacking a visibility declaration may be an indication of an accidental leak of class internals.

Notes
  • TypeScript Only
  • Has Fix

Config

These arguments may be optionally provided:

  • "no-public" forbids public accessibility to be specified, because this is the default.
  • "check-accessor" enforces explicit visibility on get/set accessors
  • "check-constructor" enforces explicit visibility on constructors
  • "check-parameter-property" enforces explicit visibility on parameter properties
Examples
"member-access": true
"member-access": true,no-public
"member-access": true,check-accessor
Schema
{
  "type": "array",
  "items": {
    "type": "string",
    "enum": [
      "no-public",
      "check-accessor",
      "check-constructor",
      "check-parameter-property"
    ]
  },
  "minLength": 0,
  "maxLength": 4
}

For more information see this page.

The class property 'name' must be marked either 'private', 'public', or 'protected'
Open

  name: string;

Rule: member-access

Requires explicit visibility declarations for class members.

Rationale

Explicit visibility declarations can make code more readable and accessible for those new to TS.

Other languages such as C# default to private, unlike TypeScript's default of public. Members lacking a visibility declaration may be an indication of an accidental leak of class internals.

Notes
  • TypeScript Only
  • Has Fix

Config

These arguments may be optionally provided:

  • "no-public" forbids public accessibility to be specified, because this is the default.
  • "check-accessor" enforces explicit visibility on get/set accessors
  • "check-constructor" enforces explicit visibility on constructors
  • "check-parameter-property" enforces explicit visibility on parameter properties
Examples
"member-access": true
"member-access": true,no-public
"member-access": true,check-accessor
Schema
{
  "type": "array",
  "items": {
    "type": "string",
    "enum": [
      "no-public",
      "check-accessor",
      "check-constructor",
      "check-parameter-property"
    ]
  },
  "minLength": 0,
  "maxLength": 4
}

For more information see this page.

expected variable-declaration: 'spy4' to have a typedef
Open

const spy4 = sinon.spy();

Rule: typedef

Requires type definitions to exist.

Notes
  • TypeScript Only

Config

Several arguments may be optionally provided:

  • "call-signature" checks return type of functions.
  • "arrow-call-signature" checks return type of arrow functions.
  • "parameter" checks type specifier of function parameters for non-arrow functions.
  • "arrow-parameter" checks type specifier of function parameters for arrow functions.
  • "property-declaration" checks return types of interface properties.
  • "variable-declaration" checks non-binding variable declarations.
  • "variable-declaration-ignore-function" ignore variable declarations for non-arrow and arrow functions.
  • "member-variable-declaration" checks member variable declarations.
  • "object-destructuring" checks object destructuring declarations.
  • "array-destructuring" checks array destructuring declarations.
Examples
"typedef": true,call-signature,parameter,member-variable-declaration
Schema
{
  "type": "array",
  "items": {
    "type": "string",
    "enum": [
      "call-signature",
      "arrow-call-signature",
      "parameter",
      "arrow-parameter",
      "property-declaration",
      "variable-declaration",
      "variable-declaration-ignore-function",
      "member-variable-declaration",
      "object-destructuring",
      "array-destructuring"
    ]
  },
  "minLength": 0,
  "maxLength": 10
}

For more information see this page.

There are no issues that match your filters.

Category
Status