Skip to content

Commit 930157c

Browse files
authored
Merge pull request #348 from mistic/integrate-prettier
Integrate pretty on the project.
2 parents 9bcfec1 + 951e18f commit 930157c

12 files changed

+727
-613
lines changed

.eslintrc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
"env": {
44
"node": true
55
},
6+
"plugins": [
7+
"prettier"
8+
],
69
"rules": {
7-
"no-console": "off"
10+
"no-console": "off",
11+
"prettier/prettier": [
12+
"error"
13+
]
814
}
915
}

client-overlay.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var styles = {
1818
bottom: 0,
1919
overflow: 'auto',
2020
dir: 'ltr',
21-
textAlign: 'left'
21+
textAlign: 'left',
2222
};
2323

2424
var ansiHTML = require('ansi-html');
@@ -32,7 +32,7 @@ var colors = {
3232
magenta: '7FACCA',
3333
cyan: 'C3C2EF',
3434
lightgrey: 'EBE7E3',
35-
darkgrey: '6D7891'
35+
darkgrey: '6D7891',
3636
};
3737

3838
var Entities = require('html-entities').AllHtmlEntities;
@@ -58,15 +58,17 @@ function clear() {
5858
}
5959
}
6060

61-
function problemType (type) {
61+
function problemType(type) {
6262
var problemColors = {
6363
errors: colors.red,
64-
warnings: colors.yellow
64+
warnings: colors.yellow,
6565
};
6666
var color = problemColors[type] || colors.red;
6767
return (
68-
'<span style="background-color:#' + color + '; color:#fff; padding:2px 4px; border-radius: 2px">' +
69-
type.slice(0, -1).toUpperCase() +
68+
'<span style="background-color:#' +
69+
color +
70+
'; color:#fff; padding:2px 4px; border-radius: 2px">' +
71+
type.slice(0, -1).toUpperCase() +
7072
'</span>'
7173
);
7274
}
@@ -89,8 +91,8 @@ module.exports = function(options) {
8991

9092
return {
9193
showProblems: showProblems,
92-
clear: clear
93-
}
94+
clear: clear,
95+
};
9496
};
9597

9698
module.exports.clear = clear;

client.js

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*global __resourceQuery __webpack_public_path__*/
33

44
var options = {
5-
path: "/__webpack_hmr",
5+
path: '/__webpack_hmr',
66
timeout: 20 * 1000,
77
overlay: true,
88
reload: false,
@@ -12,7 +12,7 @@ var options = {
1212
autoConnect: true,
1313
overlayStyles: {},
1414
overlayWarnings: false,
15-
ansiColors: {}
15+
ansiColors: {},
1616
};
1717
if (__resourceQuery) {
1818
var querystring = require('querystring');
@@ -25,8 +25,8 @@ if (typeof window === 'undefined') {
2525
} else if (typeof window.EventSource === 'undefined') {
2626
console.warn(
2727
"webpack-hot-middleware's client requires EventSource to work. " +
28-
"You should include a polyfill if you want to support this browser: " +
29-
"https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events#Tools"
28+
'You should include a polyfill if you want to support this browser: ' +
29+
'https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events#Tools'
3030
);
3131
} else {
3232
if (options.autoConnect) {
@@ -41,7 +41,8 @@ function setOptionsAndConnect(overrides) {
4141
}
4242

4343
function setOverrides(overrides) {
44-
if (overrides.autoConnect) options.autoConnect = overrides.autoConnect == 'true';
44+
if (overrides.autoConnect)
45+
options.autoConnect = overrides.autoConnect == 'true';
4546
if (overrides.path) options.path = overrides.path;
4647
if (overrides.timeout) options.timeout = overrides.timeout;
4748
if (overrides.overlay) options.overlay = overrides.overlay !== 'false';
@@ -61,8 +62,10 @@ function setOverrides(overrides) {
6162
options.path = __webpack_public_path__ + options.path;
6263
}
6364

64-
if (overrides.ansiColors) options.ansiColors = JSON.parse(overrides.ansiColors);
65-
if (overrides.overlayStyles) options.overlayStyles = JSON.parse(overrides.overlayStyles);
65+
if (overrides.ansiColors)
66+
options.ansiColors = JSON.parse(overrides.ansiColors);
67+
if (overrides.overlayStyles)
68+
options.overlayStyles = JSON.parse(overrides.overlayStyles);
6669

6770
if (overrides.overlayWarnings) {
6871
options.overlayWarnings = overrides.overlayWarnings == 'true';
@@ -76,7 +79,7 @@ function EventSourceWrapper() {
7679

7780
init();
7881
var timer = setInterval(function() {
79-
if ((new Date() - lastActivity) > options.timeout) {
82+
if (new Date() - lastActivity > options.timeout) {
8083
handleDisconnect();
8184
}
8285
}, options.timeout / 2);
@@ -89,7 +92,7 @@ function EventSourceWrapper() {
8992
}
9093

9194
function handleOnline() {
92-
if (options.log) console.log("[HMR] connected");
95+
if (options.log) console.log('[HMR] connected');
9396
lastActivity = new Date();
9497
}
9598

@@ -109,7 +112,7 @@ function EventSourceWrapper() {
109112
return {
110113
addMessageListener: function(fn) {
111114
listeners.push(fn);
112-
}
115+
},
113116
};
114117
}
115118

@@ -129,14 +132,14 @@ function connect() {
129132
getEventSourceWrapper().addMessageListener(handleMessage);
130133

131134
function handleMessage(event) {
132-
if (event.data == "\uD83D\uDC93") {
135+
if (event.data == '\uD83D\uDC93') {
133136
return;
134137
}
135138
try {
136139
processMessage(JSON.parse(event.data));
137140
} catch (ex) {
138141
if (options.warn) {
139-
console.warn("Invalid HMR message: " + event.data + "\n" + ex);
142+
console.warn('Invalid HMR message: ' + event.data + '\n' + ex);
140143
}
141144
}
142145
}
@@ -162,43 +165,47 @@ function createReporter() {
162165
if (typeof document !== 'undefined' && options.overlay) {
163166
overlay = require('./client-overlay')({
164167
ansiColors: options.ansiColors,
165-
overlayStyles: options.overlayStyles
168+
overlayStyles: options.overlayStyles,
166169
});
167170
}
168171

169172
var styles = {
170-
errors: "color: #ff0000;",
171-
warnings: "color: #999933;"
173+
errors: 'color: #ff0000;',
174+
warnings: 'color: #999933;',
172175
};
173176
var previousProblems = null;
174177
function log(type, obj) {
175-
var newProblems = obj[type].map(function(msg) { return strip(msg); }).join('\n');
178+
var newProblems = obj[type]
179+
.map(function(msg) {
180+
return strip(msg);
181+
})
182+
.join('\n');
176183
if (previousProblems == newProblems) {
177184
return;
178185
} else {
179186
previousProblems = newProblems;
180187
}
181188

182189
var style = styles[type];
183-
var name = obj.name ? "'" + obj.name + "' " : "";
184-
var title = "[HMR] bundle " + name + "has " + obj[type].length + " " + type;
190+
var name = obj.name ? "'" + obj.name + "' " : '';
191+
var title = '[HMR] bundle ' + name + 'has ' + obj[type].length + ' ' + type;
185192
// NOTE: console.warn or console.error will print the stack trace
186193
// which isn't helpful here, so using console.log to escape it.
187194
if (console.group && console.groupEnd) {
188-
console.group("%c" + title, style);
189-
console.log("%c" + newProblems, style);
195+
console.group('%c' + title, style);
196+
console.log('%c' + newProblems, style);
190197
console.groupEnd();
191198
} else {
192199
console.log(
193-
"%c" + title + "\n\t%c" + newProblems.replace(/\n/g, "\n\t"),
194-
style + "font-weight: bold;",
195-
style + "font-weight: normal;"
200+
'%c' + title + '\n\t%c' + newProblems.replace(/\n/g, '\n\t'),
201+
style + 'font-weight: bold;',
202+
style + 'font-weight: normal;'
196203
);
197204
}
198205
}
199206

200207
return {
201-
cleanProblemsCache: function () {
208+
cleanProblemsCache: function() {
202209
previousProblems = null;
203210
},
204211
problems: function(type, obj) {
@@ -219,7 +226,7 @@ function createReporter() {
219226
},
220227
useCustomOverlay: function(customOverlay) {
221228
overlay = customOverlay;
222-
}
229+
},
223230
};
224231
}
225232

@@ -228,24 +235,28 @@ var processUpdate = require('./process-update');
228235
var customHandler;
229236
var subscribeAllHandler;
230237
function processMessage(obj) {
231-
switch(obj.action) {
232-
case "building":
238+
switch (obj.action) {
239+
case 'building':
233240
if (options.log) {
234241
console.log(
235-
"[HMR] bundle " + (obj.name ? "'" + obj.name + "' " : "") +
236-
"rebuilding"
242+
'[HMR] bundle ' +
243+
(obj.name ? "'" + obj.name + "' " : '') +
244+
'rebuilding'
237245
);
238246
}
239247
break;
240-
case "built":
248+
case 'built':
241249
if (options.log) {
242250
console.log(
243-
"[HMR] bundle " + (obj.name ? "'" + obj.name + "' " : "") +
244-
"rebuilt in " + obj.time + "ms"
251+
'[HMR] bundle ' +
252+
(obj.name ? "'" + obj.name + "' " : '') +
253+
'rebuilt in ' +
254+
obj.time +
255+
'ms'
245256
);
246257
}
247-
// fall through
248-
case "sync":
258+
// fall through
259+
case 'sync':
249260
if (obj.name && options.name && obj.name !== options.name) {
250261
return;
251262
}
@@ -290,6 +301,6 @@ if (module) {
290301
useCustomOverlay: function useCustomOverlay(customOverlay) {
291302
if (reporter) reporter.useCustomOverlay(customOverlay);
292303
},
293-
setOptionsAndConnect: setOptionsAndConnect
304+
setOptionsAndConnect: setOptionsAndConnect,
294305
};
295306
}

helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ exports.pathMatch = function(url, path) {
66
} catch (e) {
77
return false;
88
}
9-
}
9+
};

0 commit comments

Comments
 (0)