eoin-obrien/ul-timetable

View on GitHub
src/util/attribute-parsers.ts

Summary

Maintainability
A
3 hrs
Test Coverage

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

export function parseModuleIds(moduleIds: string): string[] | null {
  if (isNull(moduleIds) || moduleIds === '' || moduleIds === nbspEscape) {
    return null;
  }

Severity: Major
Found in src/util/attribute-parsers.ts and 1 other location - About 1 hr to fix
src/util/attribute-parsers.ts on lines 77..83

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

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

export function parseGroups(groups: string): string[] | null {
  if (isNull(groups) || groups === '' || groups === nbspEscape) {
    return null;
  }

Severity: Major
Found in src/util/attribute-parsers.ts and 1 other location - About 1 hr to fix
src/util/attribute-parsers.ts on lines 85..91

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

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

When chaining calls, put method calls on new lines.
Open

  const parts = hyphenatedRoomId.toUpperCase().trim().split('-');
Severity: Minor
Found in src/util/attribute-parsers.ts by tslint

Rule: newline-per-chained-call

Requires that chained method calls be broken apart onto separate lines.

Rationale

This style helps to keep code 'vertical', avoiding the need for side-scrolling in IDEs or text editors.

Config

Not configurable

For more information see this page.

Use 'undefined' instead of 'null'
Open

    return null;
Severity: Minor
Found in src/util/attribute-parsers.ts by tslint

Rule: no-null-keyword

Disallows use of the null keyword literal.

Rationale

Instead of having the dual concepts of null andundefined in a codebase, this rule ensures that only undefined is used.

JavaScript originally intended undefined to refer to a value that doesn't yet exist, while null was meant to refer to a value that does exist but points to nothing. That's confusing. undefined is the default value when object members don't exist, and is the return value for newer native collection APIs such as Map.get when collection values don't exist.

const myObject = {};
myObject.doesNotExist; // undefined
const myMap = new Map<string number>();
myMap.get("doesNotExist"); // undefined</string>

To remove confusion over the two similar values, it's better to stick with just undefined.

Notes
  • Has Fix

Config

Not configurable.

Examples
"no-null-keyword": true

For more information see this page.

Use 'undefined' instead of 'null'
Open

    return null;
Severity: Minor
Found in src/util/attribute-parsers.ts by tslint

Rule: no-null-keyword

Disallows use of the null keyword literal.

Rationale

Instead of having the dual concepts of null andundefined in a codebase, this rule ensures that only undefined is used.

JavaScript originally intended undefined to refer to a value that doesn't yet exist, while null was meant to refer to a value that does exist but points to nothing. That's confusing. undefined is the default value when object members don't exist, and is the return value for newer native collection APIs such as Map.get when collection values don't exist.

const myObject = {};
myObject.doesNotExist; // undefined
const myMap = new Map<string number>();
myMap.get("doesNotExist"); // undefined</string>

To remove confusion over the two similar values, it's better to stick with just undefined.

Notes
  • Has Fix

Config

Not configurable.

Examples
"no-null-keyword": true

For more information see this page.

Use 'undefined' instead of 'null'
Open

    return null;
Severity: Minor
Found in src/util/attribute-parsers.ts by tslint

Rule: no-null-keyword

Disallows use of the null keyword literal.

Rationale

Instead of having the dual concepts of null andundefined in a codebase, this rule ensures that only undefined is used.

JavaScript originally intended undefined to refer to a value that doesn't yet exist, while null was meant to refer to a value that does exist but points to nothing. That's confusing. undefined is the default value when object members don't exist, and is the return value for newer native collection APIs such as Map.get when collection values don't exist.

const myObject = {};
myObject.doesNotExist; // undefined
const myMap = new Map<string number>();
myMap.get("doesNotExist"); // undefined</string>

To remove confusion over the two similar values, it's better to stick with just undefined.

Notes
  • Has Fix

Config

Not configurable.

Examples
"no-null-keyword": true

For more information see this page.

Use 'undefined' instead of 'null'
Open

    return null;
Severity: Minor
Found in src/util/attribute-parsers.ts by tslint

Rule: no-null-keyword

Disallows use of the null keyword literal.

Rationale

Instead of having the dual concepts of null andundefined in a codebase, this rule ensures that only undefined is used.

JavaScript originally intended undefined to refer to a value that doesn't yet exist, while null was meant to refer to a value that does exist but points to nothing. That's confusing. undefined is the default value when object members don't exist, and is the return value for newer native collection APIs such as Map.get when collection values don't exist.

const myObject = {};
myObject.doesNotExist; // undefined
const myMap = new Map<string number>();
myMap.get("doesNotExist"); // undefined</string>

To remove confusion over the two similar values, it's better to stick with just undefined.

Notes
  • Has Fix

Config

Not configurable.

Examples
"no-null-keyword": true

For more information see this page.

Replace Array function with an array literal.
Open

  const range = (start: number, length: number) => [...Array(length).keys()].map((x: number) => String(x + start));
Severity: Minor
Found in src/util/attribute-parsers.ts by tslint

Rule: prefer-array-literal

Use array literal syntax when declaring or instantiating array types.

Notes
  • TypeScript Only

Config

Rule accepts object with next boolean options:

  • "allow-size-argument" - allows calls to Array constructor with a single element (to create empty array of a given length).
  • "allow-type-parameters" - allow Array type parameters.
Schema
{
  "type": "object",
  "properties": {
    "allow-size-argument": {
      "type": "boolean"
    },
    "allow-type-parameters": {
      "type": "boolean"
    }
  },
  "additionalProperties": false
}

For more information see this page.

When chaining calls, put method calls on new lines.
Open

  const weeks = weekIdString.slice(weekIdString.indexOf(':') + 1).trim().split(',');
Severity: Minor
Found in src/util/attribute-parsers.ts by tslint

Rule: newline-per-chained-call

Requires that chained method calls be broken apart onto separate lines.

Rationale

This style helps to keep code 'vertical', avoiding the need for side-scrolling in IDEs or text editors.

Config

Not configurable

For more information see this page.

When chaining calls, put method calls on new lines.
Open

  const parts = hyphenatedRoomId.toUpperCase().trim().split('-');
Severity: Minor
Found in src/util/attribute-parsers.ts by tslint

Rule: newline-per-chained-call

Requires that chained method calls be broken apart onto separate lines.

Rationale

This style helps to keep code 'vertical', avoiding the need for side-scrolling in IDEs or text editors.

Config

Not configurable

For more information see this page.

When chaining calls, put method calls on new lines.
Open

  const range = (start: number, length: number) => [...Array(length).keys()].map((x: number) => String(x + start));
Severity: Minor
Found in src/util/attribute-parsers.ts by tslint

Rule: newline-per-chained-call

Requires that chained method calls be broken apart onto separate lines.

Rationale

This style helps to keep code 'vertical', avoiding the need for side-scrolling in IDEs or text editors.

Config

Not configurable

For more information see this page.

When chaining calls, put method calls on new lines.
Open

  const splitIds = roomIdString.toUpperCase().trim().split(/\s+/g);
Severity: Minor
Found in src/util/attribute-parsers.ts by tslint

Rule: newline-per-chained-call

Requires that chained method calls be broken apart onto separate lines.

Rationale

This style helps to keep code 'vertical', avoiding the need for side-scrolling in IDEs or text editors.

Config

Not configurable

For more information see this page.

When chaining calls, put method calls on new lines.
Open

  const splitIds = roomIdString.toUpperCase().trim().split(/\s+/g);
Severity: Minor
Found in src/util/attribute-parsers.ts by tslint

Rule: newline-per-chained-call

Requires that chained method calls be broken apart onto separate lines.

Rationale

This style helps to keep code 'vertical', avoiding the need for side-scrolling in IDEs or text editors.

Config

Not configurable

For more information see this page.

When chaining calls, put method calls on new lines.
Open

  const weeks = weekIdString.slice(weekIdString.indexOf(':') + 1).trim().split(',');
Severity: Minor
Found in src/util/attribute-parsers.ts by tslint

Rule: newline-per-chained-call

Requires that chained method calls be broken apart onto separate lines.

Rationale

This style helps to keep code 'vertical', avoiding the need for side-scrolling in IDEs or text editors.

Config

Not configurable

For more information see this page.

There are no issues that match your filters.

Category
Status