File index.js
has 657 lines of code (exceeds 250 allowed). Consider refactoring. Open
'use strict';
var schedule = require('node-schedule');
var EventEmitter = require('events').EventEmitter;
var logger = require('./../../common').logger.prefix('triggers');
Function activate
has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring. Open
exports.activate = (trigger) => {
try {
var index = trigger.automation_events.findIndex(
(obj) => obj.type === 'exact_time' || obj.type === 'repeat_time'
),
- Read upRead up
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 sync
has 120 lines of code (exceeds 25 allowed). Consider refactoring. Open
exports.sync = (id, err, triggers, stored, cb) => {
var watching = [];
if (err) {
logger.error('error starting async: ' + err);
Function activate
has 101 lines of code (exceeds 25 allowed). Consider refactoring. Open
exports.activate = (trigger) => {
try {
var index = trigger.automation_events.findIndex(
(obj) => obj.type === 'exact_time' || obj.type === 'repeat_time'
),
Function set_up_hooks
has 74 lines of code (exceeds 25 allowed). Consider refactoring. Open
function set_up_hooks() {
if (Object.keys(event_triggers).length == 0) return;
Object.keys(event_triggers).forEach((event) => {
hooks.on(event.split('-')[0], (info) => {
Function activate_event
has 68 lines of code (exceeds 25 allowed). Consider refactoring. Open
exports.activate_event = (trigger) => {
try {
var event_index = trigger.automation_events.findIndex(
(obj) => events_list.indexOf(obj.type) > -1
);
Function to_unix
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
function to_unix(date) {
var new_date;
try {
if (/^\d+$/.test(date)) {
var year = parseInt(date.slice(0, 4)),
- Read upRead up
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 delete_obsolete_triggers
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
function delete_obsolete_triggers(stored, triggers) {
logger.debug('deleting outdated triggers');
logger.debug(
'iterates over: ' +
triggers.map(function (item) {
Function check_rules
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
function check_rules(rule) {
if (rule.second && (rule.second < 0 || rule.second > 60)) return false;
if (rule.minute && (rule.minute < 0 || rule.minute > 60)) return false;
if (rule.hour && (rule.hour < 0 || rule.hour > 24)) return false;
if (rule.dayOfWeek.some((elem) => elem > 6 || elem < 0)) return false;
- Read upRead up
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 to_unix
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
function to_unix(date) {
var new_date;
try {
if (/^\d+$/.test(date)) {
var year = parseInt(date.slice(0, 4)),
Consider simplifying this complex logical expression. Open
} else if (info.days_of_week && info.hour) {
// At least the days and hour
try {
let rule = new schedule.RecurrenceRule();
Avoid too many return
statements within this function. Open
return 2;
Avoid too many return
statements within this function. Open
if (!check_range_format(date_from, date_until)) return 4;
Avoid too many return
statements within this function. Open
if (current_date > end_date) return 3;
Avoid too many return
statements within this function. Open
if (!check_repeat_format(days, hour_from, hour_until, until)) return 4;
Avoid too many return
statements within this function. Open
return true;
Avoid too many return
statements within this function. Open
if (current_triggers[trigger_index].last_exec) return;
Avoid too many return
statements within this function. Open
return 1;
Avoid too many return
statements within this function. Open
if (!check_rules(rule)) return 2;
Avoid too many return
statements within this function. Open
return 2;
Avoid too many return
statements within this function. Open
return;
Avoid too many return
statements within this function. Open
} else return 2;
Avoid too many return
statements within this function. Open
return 0;
Similar blocks of code found in 2 locations. Consider refactoring. Open
const intersected_triggers = triggers.filter((new_trigger) => {
return !stored.some((old_trigger) => {
return old_trigger.id.toString() === new_trigger.id.toString();
});
});
- Read upRead up
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 69.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
const intersected_triggers = stored.filter((old_trigger) => {
return !triggers.some((new_trigger) => {
return old_trigger.id.toString() === new_trigger.id.toString();
});
});
- Read upRead up
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 69.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (
Object.keys(dates).length == 0 ||
date.getTime() < dates.from ||
date.getTime() > dates.until
)
- Read upRead up
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 59.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (
Object.keys(dates).length == 0 ||
date.getTime() < dates.from ||
date.getTime() > dates.until
)
- Read upRead up
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 59.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (isNaN(date_from) || isNaN(date_until) || date.getTime() < date_from || date.getTime() > date_until)
return;
- Read upRead up
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 47.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (
isNaN(date_from) ||
isNaN(date_until) ||
date.getTime() < date_from ||
date.getTime() > date_until
- Read upRead up
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 47.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76