8000 fix most issues from the linter · debug-js/debug@8fa6444 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8fa6444

Browse files
author
chagris
committed
fix most issues from the linter
1 parent 69b5a48 commit 8fa6444

File tree

2 files changed

+41
-37
lines changed

2 files changed

+41
-37
lines changed

src/common.js

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ function setup(env) {
4343
createDebug.outputFormatters = {};
4444

4545
/**
46-
* Map %m to outputting diff
46+
* Map %m to applying formatters to arguments
4747
*/
4848

49-
createDebug.outputFormatters.m = function(format, args) {
49+
createDebug.outputFormatters.m = function (_, args) {
5050
args[0] = createDebug.coerce(args[0]);
5151

5252
if (typeof args[0] !== 'string') {
@@ -80,41 +80,40 @@ function setup(env) {
8080
});
8181

8282
return args;
83-
}
83+
};
8484

8585
/**
8686
* Map %+ to humanize()'s defaults (1000ms diff => "1s")
8787
*/
8888

89-
createDebug.outputFormatters['+'] = function(format, args) {
89+
createDebug.outputFormatters['+'] = function () {
9090
return '+' + createDebug.humanize(this.diff);
91-
}
91+
};
9292

9393
/**
9494
* Map %d to returning milliseconds
9595
8000 */
9696

97-
createDebug.outputFormatters.d = function(format, args) {
98-
return '+' + this.diff + "ms";
99-
}
97+
createDebug.outputFormatters.d = function () {
98+
return '+' + this.diff + 'ms';
99+
};
100100

101101
/**
102102
* Map %n to outputting namespace prefix
103103
*/
104104

105-
createDebug.outputFormatters.n = function(format, args) {
105+
createDebug.outputFormatters.n = function () {
106106
return this.namespace;
107-
}
107+
};
108108

109109
/**
110110
* Map %_time to handling time...?
111111
*/
112112

113-
createDebug.outputFormatters._time = function(format, args) {
114-
//browser doesn't have date
113+
createDebug.outputFormatters._time = function (format) {
114+
// Browser doesn't have date
115115
return new Date().toISOString();
116-
}
117-
116+
};
118117

119118
/**
120119
* Map of meta-formatters which are applied to outputFormatters
@@ -125,33 +124,33 @@ function setup(env) {
125124
* Map %J* to `JSON.stringify()`
126125
*/
127126

128-
createDebug.outputFormatters.J = function(v) {
127+
createDebug.outputFormatters.J = function (v) {
129128
return JSON.stringify(v);
130-
}
129+
};
131130

132131
/**
133132
* Map %c* to to `applyColor()`
134133
*/
135134

136-
createDebug.outputFormatters.c = function(v) {
135+
createDebug.outputFormatters.c = function (v) {
137136
if (this.useColors) {
138137
return this.applyColor(v);
139138
} else {
140139
return v;
141140
}
142-
}
141+
};
143142

144143
/**
145144
* Map %C* to to `applyColor(arg, bold = true)` (node)
146145
*/
147146

148-
createDebug.outputFormatters.C = function(v) {
147+
createDebug.outputFormatters.C = function (v) {
149148
if (this.useColors) {
150149
return this.applyColor(v, true);
151150
} else {
152151
return v;
153152
}
154-
}
153+
};
155154

156155
/**
157156
* Selects a color for a debug namespace
@@ -198,28 +197,33 @@ function setup(env) {
198197
prevTime = curr;
199198

200199
// Apply relevant `outputFormatters` to `format`
201-
let reg = /%([a-zA-Z+]+|[a-zA-Z]*?\{.+\})/, formattedArgs = [], res;
202-
let outputFormat = self.format; //make a copy of the format
200+
const reg = /%([a-zA-Z+]+|[a-zA-Z]*?\{.+\})/;
201+
let formattedArgs = [];
202+
let res;
203+
let outputFormat = self.format; // Make a copy of the format
203204
while (res = outputFormat.match(reg)) {
204-
let [matched, formatToken] = res, formatter, formatted;
205-
//split out the part before the matched format token
206-
let split = outputFormat.slice(0, res.index);
205+
let [matched, formatToken] = res;
206+
let formatter;
207+
let formatted;
208+
209+
// Split out the part before the matched format token
210+
const split = outputFormat.slice(0, res.index);
207211
outputFormat = outputFormat.slice(res.index + matched.length);
208212

209-
//and add it to the arguments
213+
// And add it to the arguments
210214
if (split.length > 0) {
211215
formattedArgs.push(split);
212216
}
213217

214-
let metaFormatters = [];
218+
const metaFormatters = [];
215219
// Extract metaformatters
216220
while (formatToken.length > 1 && !formatToken.startsWith('{')) {
217221
const metaFormatterToken = formatToken.slice(0, 1);
218222
formatToken = formatToken.slice(1);
219223
metaFormatters.push(createDebug.outputFormatters[metaFormatterToken]);
220224
}
221225

222-
//not really sure how to handle time at this point
226+
// Not really sure how to handle time at this point
223227
if (formatToken.startsWith('{')) {
224228
formatter = createDebug.outputFormatters._time;
225229
} else {
@@ -230,12 +234,12 @@ function setup(env) {
230234

231235
// Apply metaFormatters
232236
metaFormatters.forEach(metaFormatter => {
233-
if (typeof metaFormatter === "function") {
237+
if (typeof metaFormatter === 'function') {
234238
formatted = metaFormatter.call(self, formatted);
235239
}
236240
});
237241

238-
if (Array.isArray(formatted)) { //intended to concatenate %m's args in the middle of the format
242+
if (Array.isArray(formatted)) { // Intended to concatenate %m's args in the middle of the format
239243
formattedArgs = formattedArgs.concat(formatted);
240244
} else {
241245
formattedArgs.push(formatted);
@@ -250,7 +254,7 @@ function setup(env) {
250254
debug.namespace = namespace;
251255
debug.enabled = createDebug.enabled(namespace);
252256
debug.useColors = createDebug.useColors();
253-
debug.format = createDebug.getFormat() || '%{H:M-Z}%n%m%+'; //' %n%m%+'
257+
debug.format = createDebug.getFormat() || '%{H:M-Z}%n%m%+'; // ' %n%m%+'
254258
debug.color = selectColor(namespace);
255259
debug.applyColor = createDebug.applyColor.bind(debug);
256260
debug.destroy = destroy;

src/node.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ exports.inspectOpts = Object.keys(process.env).filter(key => {
138138
} else if (val === 'null') {
139139
val = null;
140140
} else {
141-
let asNumber = Number(val);
141+
const asNumber = Number(val);
142142
if (!isNaN(asNumber)) {
143143
val = asNumber;
144144
}
@@ -172,11 +172,11 @@ function getFormat() {
172172
return exports.inspectOpts.format;
173173
} else {
174174
if (useColors) {
175-
return ' %Cn%m%c+'; //' %n %m %+'
175+
return ' %Cn%m%c+'; // ' %n %m %+'
176176
} else if (exports.inspectOpts.hideDate) {
177-
return '%n%m'; //'%n %m'
177+
return '%n%m'; // '%n %m'
178178
} else {
179-
return '%{%FT%T.%LZ%M-Z}%n%m'; //'%{%FT%T.%LZ%M-Z} %n %m'
179+
return '%{%FT%T.%LZ%M-Z}%n%m'; // '%{%FT%T.%LZ%M-Z} %n %m'
180180
}
181181
}
182182
}
@@ -188,7 +188,7 @@ function getFormat() {
188188
*/
189189

190190
function applyColor(str, bold = false) {
191-
//I think doing this each time is a waste, colorCode could be stored in some variable?
191+
// I think doing this each time is a waste, colorCode could be stored in some variable?
192192
const c = this.color;
193193
const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
194194

@@ -267,4 +267,4 @@ formatters.o = function (v) {
267267
formatters.O = function (v) {
268268
this.inspectOpts.colors = this.useColors;
269269
return util.inspect(v, this.inspectOpts);
270-
};
270+
};

0 commit comments

Comments
 (0)
0