Passed
Push — develop ( be29f2...b2a598 )
by Dylan
05:09 queued 02:15
created

js/default_tests.js   F

Complexity

Total Complexity 98
Complexity/F 4.26

Size

Lines of Code 375
Function Count 23

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 98
dl 0
loc 375
rs 3.12
c 5
b 1
f 0
cc 0
nc 1
mnd 4
bc 41
fnc 23
bpm 1.7826
cpm 4.2608
noi 84

2 Functions

Rating   Name   Duplication   Size   Complexity  
A crawler.CRAWL_LOAD_FAILED 0 4 1
A default_tests.callback 0 13 3

How to fix   Complexity   

Complexity

Complex classes like js/default_tests.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
/**
2
 * Example callback:
3
 * callback: function(cont, url, html, headers, field_data, phrases){
4
            return crawler.add_row('h1count', html.find( 'h1' ).length);
5
        }
6
 *
7
 */
8
const default_tests = [
1 ignored issue
show
Unused Code introduced by
The constant default_tests seems to be never used. Consider removing it.
Loading history...
9
    {
10
        name: 'error_pages',
11
        title: 'ERROR PAGES',
12
        headers: ['URL'],
13
        type: 'success'
14
    },
15
16
    {
17
        name : 'h1_info',
18
        title: 'H1 INFO',
19
        headers: ['URL', 'Count', 'Text', 'Status'],
20
        callback: function(cont, url, html){
21
            var h1      = html.find( 'h1' ),
22
                link    = crawler_painter.create_link(url, url),
1 ignored issue
show
Bug introduced by
The variable crawler_painter seems to be never declared. If this is a global, consider adding a /** global: crawler_painter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
23
                joined  = [], status  = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as status is implicitly marked as undefined by the declaration.
Loading history...
24
25
            h1.each(function(){ joined.push(this.innerHTML); });
26
27
            if(h1.length != 1)
28
                status = crawler_painter.create_status('error', (h1.length < 1) ? 'Missing H1' : 'Multiple H1 tags');
2 ignored issues
show
Bug introduced by
The variable crawler_painter seems to be never declared. If this is a global, consider adding a /** global: crawler_painter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
29
            else status = crawler_painter.create_status('success', 'OK!');
30
31
            crawler_painter.add_row(this.name, [link, h1.length, joined.join(', '), status]);
32
        }
33
    },
34
35
    {
36
        name : 'h2_info',
37
        title: 'H2 INFO',
38
        headers: ['URL', 'Count', 'Text', 'Status'],
39
        callback: function(cont, url, html){
40
            var h2      = html.find( 'h2' ),
41
                link    = crawler_painter.create_link(url, url),
1 ignored issue
show
Bug introduced by
The variable crawler_painter seems to be never declared. If this is a global, consider adding a /** global: crawler_painter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
42
                joined  = [], status = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as status is implicitly marked as undefined by the declaration.
Loading history...
43
44
            h2.each(function(){ joined.push(this.innerHTML); });
45
46
            if(h2.length < 1) status = crawler_painter.create_status('warning', 'Missing H2');
2 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Bug introduced by
The variable crawler_painter seems to be never declared. If this is a global, consider adding a /** global: crawler_painter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
47
            else status = crawler_painter.create_status('success', 'OK!');
48
49
            crawler_painter.add_row(this.name, [link, h2.length, joined.join(', '), status]);
50
        }
51
    },
52
53
    {
54
        name : 'word_count',
55
        title: 'WORD COUNT',
56
        headers: ['URL', 'Word Count', 'Article Word Count'],
57
        callback: function(cont, url, html, headers, field_data, phrases){
58
            var link        = crawler_painter.create_link(url, url),
1 ignored issue
show
Bug introduced by
The variable crawler_painter seems to be never declared. If this is a global, consider adding a /** global: crawler_painter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
59
                word_count  = crawler.get_word_count(phrases),
1 ignored issue
show
Bug introduced by
The variable crawler seems to be never declared. If this is a global, consider adding a /** global: crawler */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
60
                art_count   = crawler.get_word_count(field_data[3]);
61
62
            crawler_painter.add_row(this.name, [link, word_count, art_count]);
63
        }
64
    },
65
66
    {
67
        name : 'int_link_info',
68
        title: 'INTERNAL LINK INFO',
69
        headers: ['URL', 'Article Links', 'Article Link Count', 'Article Density',
70
                    'Total Link Count', 'Total Density', 'Status'],
71
        type: 'info',
72
        callback: function(cont, url, html, headers, field_data, phrases){
73
            var link = crawler_painter.create_link(url, url),
1 ignored issue
show
Bug introduced by
The variable crawler_painter seems to be never declared. If this is a global, consider adding a /** global: crawler_painter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
74
                art_links = [], links = [];
75
76
            // Article links
77
            for( var field in field_data[2] ) {
1 ignored issue
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
78
                $.each($(field_data[2][field]).find('a'), function () {
79
                    var href = $(this).attr('href');
80
                    if(href && !crawler.is_external(href) && !crawler.is_anchor(href, url)) art_links.push(href);
2 ignored issues
show
Bug introduced by
The variable crawler seems to be never declared. If this is a global, consider adding a /** global: crawler */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
81
                });
82
            }
83
84
            // Full page links
85
            $.each(html.find('a'), function () {
86
                var href = $(this).attr('href');
87
                if(href && !crawler.is_external(href) && !crawler.is_anchor(href, url)) links.push(href);
2 ignored issues
show
Bug introduced by
The variable crawler seems to be never declared. If this is a global, consider adding a /** global: crawler */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
88
            });
89
90
            var art_word_count  = crawler.get_word_count(field_data[3]),
91
                art_density     = (art_links.length > 0) ? art_word_count / art_links.length : false,
92
                art_dens_text   = (art_density != false) ? art_density.toFixed(2) +' words/link' : 'No internal links',
93
                word_count      = crawler.get_word_count(phrases),
94
                density         = (links.length > 0) ? word_count / links.length : false,
95
                dens_text       = (density != false) ? density.toFixed(2) +' words/link' : 'No internal links',
96
                status          = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as status is implicitly marked as undefined by the declaration.
Loading history...
97
98
            if( ( art_density !== false && art_density < 100 ) )
99
                status = crawler_painter.create_status('warning', 'This page might be considered spammy');
2 ignored issues
show
Bug introduced by
The variable crawler_painter seems to be never declared. If this is a global, consider adding a /** global: crawler_painter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
100
101
            if(links.length > 0)
102
                crawler_painter.add_row( this.name, [
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
103
                    link, art_links.join('<br />'), art_links.length, art_dens_text, links.length, dens_text, status
104
                ]);
105
        }
106
    },
107
108
    {
109
        name : 'ext_link_info',
110
        title: 'EXTERNAL LINK INFO',
111
        headers: ['URL', 'External Link Count', 'External Links'],
112
        type: 'success',
113
        callback: function(cont, url, html, headers, field_data){
114
            var link = crawler_painter.create_link(url, url),
1 ignored issue
show
Bug introduced by
The variable crawler_painter seems to be never declared. If this is a global, consider adding a /** global: crawler_painter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
115
                links = [];
116
117
            for( var field in field_data[2] ) {
1 ignored issue
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
118
                $.each($(field_data[2][field]).find('a'), function () {
119
                    var $this = $(this),
120
                        href = $this.attr('href');
121
                    if(href && crawler.is_external(href)){
1 ignored issue
show
Bug introduced by
The variable crawler seems to be never declared. If this is a global, consider adding a /** global: crawler */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
122
                        var type = ( !$this.attr('rel') || $this.attr('rel').toLowerCase().indexOf('nofollow') < 0 )
123
                            ? 'warning' : 'info';
124
                        links.push(
125
                            $('<div class="clearfix"></div>').append([
126
                                crawler_painter.create_status(type, href),
1 ignored issue
show
Bug introduced by
The variable crawler_painter seems to be never declared. If this is a global, consider adding a /** global: crawler_painter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
127
                                '<p>&nbsp;</p>'
128
                            ])
129
                        );
130
                    }
131
                });
132
            }
133
134
            if(links.length > 0) crawler_painter.add_row(this.name, [link, links.length, links]);
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
135
        }
136
    },
137
138
    {
139
        name : 'img_info',
140
        title: 'IMAGE INFO',
141
        headers: ['URL', 'Count', 'Missing Alt Tag', 'Missing Title Tag', 'Fields Missing Images', 'Status'],
142
        type: 'success',
143
        callback: function(cont, url, html, headers, field_data) {
144
            var link = crawler_painter.create_link(url, url),
1 ignored issue
show
Bug introduced by
The variable crawler_painter seems to be never declared. If this is a global, consider adding a /** global: crawler_painter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
145
                imgs = html.find('img'),
146
                alt = 0, title = 0, fields = [], status = '';
147
148
            // Check alt and title tags
149
            $.each(imgs, function () {
150
                var $this = $(this);
151
                if (!$this.attr('alt') || $this.attr('alt').length < 1) alt += 1;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
152
                if (!$this.attr('title') || $this.attr('title').length < 1) title += 1;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
153
            });
154
155
            // Check the fields
156
            for (var f in field_data[2]) if ($(field_data[2][f]).find('img').length < 1) fields.push(field_data[1][f]);
2 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
157
158
            // Construct Result
159
            if (alt > 0)
160
                status = crawler_painter.create_status('error',
2 ignored issues
show
Bug introduced by
The variable crawler_painter seems to be never declared. If this is a global, consider adding a /** global: crawler_painter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
161
                    (alt > 1) ? alt + ' images missing alt tag' : '1 image missing alt tag');
162
            else if(fields.length > 0)
163
                status = crawler_painter.create_status('warning',
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
164
                    (fields.length > 1) ? fields.join(' and ') + ' are missing images' : fields[0] + ' is missing images');
165
            else if(title > 0)
166
                status = crawler_painter.create_status('info',
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
167
                    (title > 1) ? title + ' images missing title tag' : '1 image is missing title tag');
168
            else
169
                status = crawler_painter.create_status('success', 'OK!');
170
171
            crawler_painter.add_row(this.name, [link, imgs.length, alt, title, fields.join(', '), status]);
172
        }
173
    },
174
175
    {
176
        name: 'title_info',
177
        title: 'META TITLE',
178
        headers: ['URL', 'Meta Title', 'Length', 'Status'],
179
        callback: function(cont, url, html){
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
180
            var title = html.filter( 'title' ),
181
                link  = crawler_painter.create_link(url, url),
1 ignored issue
show
Bug introduced by
The variable crawler_painter seems to be never declared. If this is a global, consider adding a /** global: crawler_painter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
182
                text  = '', len = 0, status = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as status is implicitly marked as undefined by the declaration.
Loading history...
183
184
            if( title.length > 1 ){
185
                text = 'Multiple Titles';
186
                len  = 'N/A';
187
                status = crawler_painter.create_status('error', 'Multiple title tags');
188
            }else if( title.length < 1 ){
189
                status = crawler_painter.create_status('error', 'Missing title tag');
190
            }else{
191
                text = title.html();
192
                len = text.length;
193
                if(len < 40) status = crawler_painter.create_status('warning', 'Meta title is too short');
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
194
                else if(len > 56) status = crawler_painter.create_status('warning', 'Meta title is too long');
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
195
                else status = crawler_painter.create_status('success', 'OK!');
196
            }
197
198
            crawler_painter.add_row(this.name, [link, text, len, status]);
199
            if(!crawler.hasOwnProperty('meta_titles')) crawler.meta_titles = {};
2 ignored issues
show
Bug introduced by
The variable crawler seems to be never declared. If this is a global, consider adding a /** global: crawler */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
200
            if(!crawler.meta_titles.hasOwnProperty(text)) crawler.meta_titles[text] = [url];
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
201
            else crawler.meta_titles[text].push(url);
202
        }
203
    },
204
205
    {
206
        name: 'description_info',
207
        title: 'META DESCRIPTION',
208
        headers: ['URL', 'Meta Description', 'Length', 'Status'],
209
        callback: function(cont, url, html){
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
210
            var desc = html.filter( 'meta[name=description]' ),
211
                link  = crawler_painter.create_link(url, url),
1 ignored issue
show
Bug introduced by
The variable crawler_painter seems to be never declared. If this is a global, consider adding a /** global: crawler_painter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
212
                text  = '', len = 0, status = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as status is implicitly marked as undefined by the declaration.
Loading history...
213
214
            if( desc.length > 1 ){
215
                text = 'Multiple Meta Descriptions';
216
                len  = 'N/A';
217
                status = crawler_painter.create_status('error', 'Multiple meta description tags');
218
            }else if( desc.length < 1 ){
219
                status = crawler_painter.create_status('error', 'Missing meta description tag');
220
            }else{
221
                text = desc.attr('content');
222
                len = text.length;
223
                if(len < 70) status = crawler_painter.create_status('warning', 'Meta description is too short');
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
224
                else if(len > 156) status = crawler_painter.create_status('warning', 'Meta description is too long');
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
225
                else status = crawler_painter.create_status('success', 'OK!');
226
227
                if(!crawler.hasOwnProperty('descriptions')) crawler.descriptions = {};
2 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Bug introduced by
The variable crawler seems to be never declared. If this is a global, consider adding a /** global: crawler */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
228
                if(!crawler.descriptions.hasOwnProperty(text)) crawler.descriptions[text] = [url];
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
229
                else crawler.descriptions[text].push(url);
230
            }
231
232
            crawler_painter.add_row(this.name, [link, text, len, status]);
233
        }
234
    },
235
236
    {
237
        name: 'canonical_info',
238
        title: 'PAGES MISSING CANONICAL',
239
        headers: ['URL'],
240
        type: 'success',
241
        callback: function(cont, url, html){
242
            var tags = html.filter( 'link' ),
243
                canonical = undefined;
0 ignored issues
show
Unused Code Comprehensibility introduced by
The assignment of undefined is not necessary as canonical is implicitly marked as undefined by the declaration.
Loading history...
244
245
            for( var i = 0; i < tags.length; i++ ) {
246
                var rel = $(tags[i]).attr('rel');
247
                if( rel && rel.toLowerCase() === 'canonical' ) {
248
                    canonical = $(tags[i]).attr('rel');
249
                    break;
250
                }
251
            }
252
253
            if(canonical === undefined || canonical.length < 1) {
254
                crawler_painter.add_row(this.name, [crawler_painter.create_link(url, url)]);
1 ignored issue
show
Bug introduced by
The variable crawler_painter seems to be never declared. If this is a global, consider adding a /** global: crawler_painter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
255
                crawler_painter.set_type(this.name, 'error');
256
            }
257
258
            canonical = url; // What Google will do
259
            if(!crawler.hasOwnProperty('canonicals')) crawler.canonicals = {};
2 ignored issues
show
Bug introduced by
The variable crawler seems to be never declared. If this is a global, consider adding a /** global: crawler */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
260
            if(!crawler.canonicals.hasOwnProperty(canonical)) crawler.canonicals[canonical] = [url];
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
261
            else crawler.canonicals[canonical].push(url);
262
        }
263
    },
264
265
    {
266
        name: 'no-index_pages',
267
        title: 'NO-INDEX PAGES',
268
        headers: ['URL'],
269
        type: 'success',
270
        callback: function(cont, url, html){
271
            var tags = html.filter( 'meta' );
272
            for( var i = 0; i < tags.length; i++ )
273
                if( $(tags[i]).attr( 'name' ) && $(tags[i]).attr( 'name' ).toLowerCase() === 'robots' &&
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
274
                        $(tags[i]).attr('content').toLowerCase().indexOf( 'noindex' ) > -1 ) {
275
                    crawler_painter.add_row(this.name, [crawler_painter.create_link(url, url)]);
1 ignored issue
show
Bug introduced by
The variable crawler_painter seems to be never declared. If this is a global, consider adding a /** global: crawler_painter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
276
                    crawler_painter.set_type(this.name, 'warning');
277
                    return;
278
                }
279
        }
280
    },
281
282
    {
283
        name: 'urls_test',
284
        title: 'URL STRUCTURE',
285
        headers: ['URL', 'Status'],
286
        type: 'success',
287
        callback: function(cont, url){
288
            var link = crawler_painter.create_link(url, url),
1 ignored issue
show
Bug introduced by
The variable crawler_painter seems to be never declared. If this is a global, consider adding a /** global: crawler_painter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
289
                type = 'warning',
290
                msg  = 'OK!';
0 ignored issues
show
Unused Code introduced by
The assignment to variable msg seems to be never used. Consider removing it.
Loading history...
291
292
            if( url.length > 115 )                  msg = 'URL is too long';
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
293
            else if( url.toLowerCase() != url )     msg = 'URL is not in lower case';
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
294
            else if( url.replace('_','') !== url )  msg = 'URL contains under scores';
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
295
            else return true;
296
297
            crawler_painter.add_row(this.name, [link, crawler_painter.create_status(type, msg)]);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
298
        }
299
    },
300
301
    {
302
        name: 'duplicate_meta_tags',
303
        title: 'DUPLICATE META TAGS',
304
        headers: ['URL', 'Status'],
305
        type: 'success',
306
        callback: function(){
307
            var canonicals = crawler.canonicals,
1 ignored issue
show
Bug introduced by
The variable crawler seems to be never declared. If this is a global, consider adding a /** global: crawler */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
308
                tests      = {
309
                    'meta_titles'   : 'Urls have same meta title but different canonicals',
310
                    'descriptions'  : 'Urls have same meta description but different canonicals'
311
                };
312
313
            // Reset table
314
            crawler_painter.reset_table(this.name, 'success');
1 ignored issue
show
Bug introduced by
The variable crawler_painter seems to be never declared. If this is a global, consider adding a /** global: crawler_painter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
315
316
            for(var test in tests){
1 ignored issue
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
317
                for(var x in crawler[test]){
1 ignored issue
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
318
                    var urls = crawler[test][x];
319
                    if( urls < 2 ) continue;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
320
                    var canonical = getKeyFromObject(canonicals, urls[0]);
321
                    for( var i in urls )
1 ignored issue
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
322
                        if( canonical != getKeyFromObject(canonicals, urls[i]) ) {
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
323
                            crawler_painter.add_row(
324
                                this.name,
325
                                [urls.join(', '), crawler_painter.create_status('error', tests[test])]
326
                            );
327
                            break;
328
                        }
329
                }
330
            }
331
332
            function getKeyFromObject(object, search){
333
                for( var key in object ) if( object[key].indexOf(search) >= 0 ) return key;
2 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
334
            }
335
        }
336
    },
337
338
    {
339
        name: 'href_langs',
340
        title: 'LANG TAGS',
341
        headers: ['URL', 'Tags'],
342
        type: 'info',
343
        callback: function(cont, url, html){
344
            var link    = crawler_painter.create_link(url, url),
1 ignored issue
show
Bug introduced by
The variable crawler_painter seems to be never declared. If this is a global, consider adding a /** global: crawler_painter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
345
                tags    = [];
346
347
            $.each( html.filter( 'link' ), function(){
348
                if( $(this).attr( 'hreflang' ) )
349
                    tags.push( $('<p>').text( $(this).clone().wrap('<p>').parent().html() ).html() );
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
350
            });
351
352
            if( tags.length > 0 ) crawler_painter.add_row(this.name, [link, tags.join('<br />')] );
2 ignored issues
show
Bug introduced by
The variable crawler_painter seems to be never declared. If this is a global, consider adding a /** global: crawler_painter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
353
        }
354
    },
355
356
    {
357
        name: 'orphan_pages',
358
        title: 'ORPHAN PAGES',
359
        headers: ['URL'],
360
        callback: function(){
361
            if(crawler.que.length > 0) return true;
2 ignored issues
show
Bug introduced by
The variable crawler seems to be never declared. If this is a global, consider adding a /** global: crawler */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
362
            crawler_painter.reset_table(this.name, 'success');
1 ignored issue
show
Bug introduced by
The variable crawler_painter seems to be never declared. If this is a global, consider adding a /** global: crawler_painter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
363
364
            pages_loop:
365
            for( var i in crawler.tested ){
1 ignored issue
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
366
                var url = crawler.tested[i];
367
                if( crawler.linked_from.hasOwnProperty(url) ) {
368
                    for (var x in crawler.linked_from[url])
1 ignored issue
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
369
                        if (crawler.linked_from[url][x] != url) continue pages_loop;
1 ignored issue
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
370
                }
371
372
                crawler.add_row(this.name, [crawler_painter.create_link(crawler.tested[i], crawler.tested[i])]);
373
                crawler_painter.set_type(this.name, 'error');
374
            }
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
375
        }
376
    }
377
];
378
379
crawler.on('CRAWL_LOAD_FAILED', function(url){
380
    crawler_painter.add_row('error_pages', [url]);
1 ignored issue
show
Bug introduced by
The variable crawler_painter seems to be never declared. If this is a global, consider adding a /** global: crawler_painter */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
381
    crawler_painter.set_type('error_pages', 'error');
382
});
383