romain-gilliotte/timeslot-dag

View on GitHub

Showing 41 of 41 total issues

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

module.exports = {
  humanizeValue(periodicity, value) {
    const year = value.substring(0, 4);

    switch (periodicity) {
Severity: Major
Found in src/locale/es.js and 1 other location - About 1 day to fix
src/locale/fr.js on lines 35..78

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

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

module.exports = {
  humanizeValue(periodicity, value) {
    const year = value.substring(0, 4);

    switch (periodicity) {
Severity: Major
Found in src/locale/fr.js and 1 other location - About 1 day to fix
src/locale/es.js on lines 35..78

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

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 3 locations. Consider refactoring.
Open

    } else if (periodicity === 'week_sat') {
      if (firstDay === SATURDAY)
        // Lucky us, first day of year is Saturday
        epoch = Date.UTC(year, 0, 1, 0, 0, 0, 0);
      else if (firstDay === SUNDAY)
Severity: Major
Found in src/timeslot.js and 2 other locations - About 1 day to fix
src/timeslot.js on lines 120..186
src/timeslot.js on lines 164..186

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

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 3 locations. Consider refactoring.
Open

    if (periodicity === 'week_sun') {
      if (firstDay === SUNDAY)
        // Lucky us, first day of year is Sunday
        epoch = Date.UTC(year, 0, 1, 0, 0, 0, 0);
      else if (firstDay === MONDAY)
Severity: Major
Found in src/timeslot.js and 2 other locations - About 1 day to fix
src/timeslot.js on lines 142..186
src/timeslot.js on lines 164..186

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

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 3 locations. Consider refactoring.
Open

    } else if (periodicity === 'week_mon') {
      if (firstDay === MONDAY)
        // Lucky us, first day of year is Sunday
        epoch = Date.UTC(year, 0, 1, 0, 0, 0, 0);
      else if (firstDay === TUESDAY)
Severity: Major
Found in src/timeslot.js and 2 other locations - About 1 day to fix
src/timeslot.js on lines 120..186
src/timeslot.js on lines 142..186

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

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

File timeslot.js has 393 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const HashLru = require('hashlru');

const instances = HashLru(1e3);

/**
Severity: Minor
Found in src/timeslot.js - About 5 hrs to fix

    Function _getEpidemiologicWeekEpoch has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

      static _getEpidemiologicWeekEpoch(year, periodicity) {
        var SUNDAY = 0,
          MONDAY = 1,
          TUESDAY = 2,
          WEDNESDAY = 3,
    Severity: Minor
    Found in src/timeslot.js - About 3 hrs 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

      previous() {
        if (!this._previous) {
          if (this._periodicity === 'all') throw new Error('There is no previous slot');
    
          var date = new Date(this.firstDate.valueOf());
    Severity: Major
    Found in src/timeslot.js and 1 other location - About 3 hrs to fix
    src/timeslot.js on lines 511..521

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

    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

      next() {
        if (!this._next) {
          if (this._periodicity === 'all') throw new Error('There is no next slot');
    
          var date = new Date(this.lastDate.valueOf());
    Severity: Major
    Found in src/timeslot.js and 1 other location - About 3 hrs to fix
    src/timeslot.js on lines 488..498

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

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

      get firstDate() {
        if (!this._firstDate) {
          if (this._periodicity === 'day') this._firstDate = new Date(this._value + 'T00:00:00Z');
          else if (
            this._periodicity === 'month_week_sat' ||
    Severity: Minor
    Found in src/timeslot.js - About 3 hrs 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 lastDate has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

      get lastDate() {
        if (!this._lastDate) {
          if (this._periodicity === 'day')
            // last day is current day
            this._lastDate = this.firstDate;
    Severity: Minor
    Found in src/timeslot.js - About 3 hrs 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 fromDate has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

      static fromDate(utcDate, periodicity) {
        if (typeof utcDate === 'string') utcDate = new Date(utcDate);
    
        if (periodicity === 'day') return TimeSlot.fromValue(utcDate.toISOString().substring(0, 10));
        else if (
    Severity: Minor
    Found in src/timeslot.js - About 2 hrs 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

          } else if (this._periodicity === 'semester') {
            var month2 = (this._value.substring(6, 7) - 1) * 6 + 1;
            if (month2 < 10) month2 = '0' + month2;
    
            this._firstDate = new Date(this._value.substring(0, 5) + month2 + '-01T00:00:00Z');
    Severity: Major
    Found in src/timeslot.js and 1 other location - About 2 hrs to fix
    src/timeslot.js on lines 317..329

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

    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._periodicity === 'quarter') {
            var month = (this._value.substring(6, 7) - 1) * 3 + 1;
            if (month < 10) month = '0' + month;
    
            this._firstDate = new Date(this._value.substring(0, 5) + month + '-01T00:00:00Z');
    Severity: Major
    Found in src/timeslot.js and 1 other location - About 2 hrs to fix
    src/timeslot.js on lines 322..329

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

    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 (this._periodicity === 'month_week_sat')
              firstWeekLength = 7 - ((firstDayOfMonth + 1) % 7);
            else if (this._periodicity === 'month_week_sun') firstWeekLength = 7 - firstDayOfMonth;
            // 1 if month start on saturday, 2 if friday, 7 if sunday
            else firstWeekLength = 7 - ((firstDayOfMonth - 1 + 7) % 7);
    Severity: Major
    Found in src/timeslot.js and 1 other location - About 2 hrs to fix
    src/timeslot.js on lines 289..293

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

    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 (this._periodicity === 'month_week_sat')
                firstWeekLength = 7 - ((firstDayOfMonth + 1) % 7);
              else if (this._periodicity === 'month_week_sun') firstWeekLength = 7 - firstDayOfMonth;
              // 1 if month start on saturday, 2 if friday, 7 if sunday
              else firstWeekLength = 7 - ((firstDayOfMonth - 1 + 7) % 7);
    Severity: Major
    Found in src/timeslot.js and 1 other location - About 2 hrs to fix
    src/timeslot.js on lines 357..361

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

    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 lastDate has 56 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      get lastDate() {
        if (!this._lastDate) {
          if (this._periodicity === 'day')
            // last day is current day
            this._lastDate = this.firstDate;
    Severity: Major
    Found in src/timeslot.js - About 2 hrs to fix

      Function _getEpidemiologicWeekEpoch has 56 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        static _getEpidemiologicWeekEpoch(year, periodicity) {
          var SUNDAY = 0,
            MONDAY = 1,
            TUESDAY = 2,
            WEDNESDAY = 3,
      Severity: Major
      Found in src/timeslot.js - About 2 hrs to fix

        Function firstDate has 54 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          get firstDate() {
            if (!this._firstDate) {
              if (this._periodicity === 'day') this._firstDate = new Date(this._value + 'T00:00:00Z');
              else if (
                this._periodicity === 'month_week_sat' ||
        Severity: Major
        Found in src/timeslot.js - About 2 hrs to fix

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

                } else if (this._periodicity === 'quarter') {
                  var quarterDate = new Date(this.firstDate.valueOf());
                  quarterDate.setUTCMonth(quarterDate.getUTCMonth() + 3); // add three month.
                  quarterDate.setUTCDate(0); // go to last day of previous month.
                  this._lastDate = quarterDate;
          Severity: Major
          Found in src/timeslot.js and 2 other locations - About 2 hrs to fix
          src/timeslot.js on lines 387..404
          src/timeslot.js on lines 397..404

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

          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

          Severity
          Category
          Status
          Source
          Language