1 | 1 | var chalk = require('chalk'); |
|
2 | 1 | var format = require('util').format; |
|
3 | |||
4 | /** |
||
5 | * some logging methods... |
||
6 | * info, warn, debug, process |
||
7 | * |
||
8 | */ |
||
9 | |||
10 | /** |
||
11 | * Outputs warn message to console |
||
12 | * |
||
13 | * @return Patternlibrary |
||
14 | */ |
||
15 | function warn ( msg, err ) { |
||
16 | 3 | var strings = { |
|
17 | time : chalk.yellow( (new Date()).toLocaleTimeString() ), |
||
18 | message : chalk.yellow( msg ) |
||
19 | }; |
||
20 | 3 | console.log( |
|
0 ignored issues
–
show
Debugging Code
introduced
by
Loading history...
|
|||
21 | '['+(strings.time)+'] Patternlibrary: ' + (strings.message) // + "\n" |
||
22 | ); |
||
23 | 3 | if (err) this.debug(err); |
|
0 ignored issues
–
show
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 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...
|
|||
24 | 3 | return (this); |
|
25 | } |
||
26 | |||
27 | /** |
||
28 | * Outputs log message to console if verbose option is set to `true` |
||
29 | * |
||
30 | * @return Patternlibrary |
||
31 | */ |
||
32 | function info ( msg ) { |
||
33 | 1029 | if (this.options.verbose === true) { |
|
34 | 2 | var strings = { |
|
35 | time : chalk.grey( (new Date()).toLocaleTimeString() ), |
||
36 | message : chalk.cyan( msg ) |
||
37 | }; |
||
38 | 2 | console.log( |
|
0 ignored issues
–
show
|
|||
39 | '['+(strings.time)+'] Patternlibrary: ' + (strings.message) // + "\n" |
||
40 | ); |
||
41 | } |
||
42 | 1029 | return (this); |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * Outputs debug info to console if verbose option is set to `true` |
||
47 | * |
||
48 | * @return Patternlibrary |
||
49 | */ |
||
50 | function debug ( ) { |
||
51 | 14 | if (this.options.verbose === true) { |
|
52 | 2 | var strings = { |
|
53 | time : chalk.grey( (new Date()).toLocaleTimeString() ), |
||
54 | title : chalk.yellow( 'Patternlibrary Debug:' ) |
||
55 | }; |
||
56 | 2 | console.log( |
|
0 ignored issues
–
show
|
|||
57 | '['+(strings.time)+'] '+(strings.title)+' '+"\n", |
||
58 | chalk.yellow(' >>> =================================================== <<< ') // +"\n" |
||
59 | ); |
||
60 | 2 | for (var arg of arguments) { |
|
61 | 2 | if (arg) console.log(arg); |
|
0 ignored issues
–
show
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 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...
|
|||
62 | } |
||
63 | 2 | console.log( |
|
64 | chalk.yellow(' >>> =================================================== <<< ') // +"\n" |
||
65 | ); |
||
66 | } |
||
67 | 2 | return (this); |
|
68 | } |
||
69 | |||
70 | /** |
||
71 | * Outputs the completion of a page being processed to the console. |
||
72 | * |
||
73 | * @param {string} file - Name of the file. |
||
74 | * @param {object} data - Data object associated with the file. The list of adapters is pulled from this. |
||
75 | * @param {integer} time - Time it took to process the file. |
||
76 | */ |
||
77 | function processlog(file, data, time) { |
||
78 | 88 | if (this.options.verbose === true) { |
|
79 | 3 | var msg = ''; |
|
80 | 3 | var diff = (process.hrtime(time)[1] / 1000000000).toFixed(2); |
|
81 | 3 | var adapters = data; |
|
82 | 4 | if (data && data._adapterData) { |
|
83 | 1 | var adapters = Object.keys(data._adapterData).join(', '); |
|
0 ignored issues
–
show
Comprehensibility
Naming
Best Practice
introduced
by
The variable
adapters already seems to be declared on line 81 . Consider using another variable name or omitting the var keyword.
This check looks for variables that are declared in multiple lines. There may be several reasons for this. In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs. If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.
Loading history...
|
|||
84 | } |
||
85 | 3 | var strings = { |
|
86 | time : chalk.grey( (new Date()).toLocaleTimeString() ), |
||
87 | title : chalk.yellow( 'Patternlibrary process log:' ) |
||
88 | }; |
||
89 | |||
90 | 3 | msg += format('[%s] Patternlibrary: processed %s in %s', (strings.time), chalk.cyan(file), chalk.magenta(diff + ' s')); |
|
91 | |||
92 | 4 | if (adapters && adapters.length) { |
|
93 | 2 | msg += format(' with %s', chalk.yellow(adapters)); |
|
94 | } |
||
95 | |||
96 | 3 | console.log(msg); |
|
0 ignored issues
–
show
|
|||
97 | } |
||
98 | } |
||
99 | |||
100 | |||
101 | /*module.exports = { |
||
102 | log : info, |
||
103 | info : info, |
||
104 | process: process, |
||
105 | debug : debug, |
||
106 | warn : warn |
||
107 | };*/ |
||
108 | //module.exports = function () {}; |
||
109 | 1 | module.exports.log = info, |
|
0 ignored issues
–
show
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.
The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression. This operator is most often used in Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator. This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements. var a,b,c;
a = 1, b = 1, c= 3;
could just as well be written as: var a,b,c;
a = 1;
b = 1;
c = 3;
To learn more about the sequence operator, please refer to the MDN.
Loading history...
|
|||
110 | module.exports.info = info, |
||
111 | module.exports.process= processlog, |
||
112 | module.exports.debug = debug, |
||
113 | module.exports.warn = warn |
||
114 | |||
115 |