Skip to content

Commit e6e642c

Browse files
committed
Add linter and fix lint issues
Config copied from webpack-dev-server.
1 parent f941380 commit e6e642c

File tree

4 files changed

+87
-16
lines changed

4 files changed

+87
-16
lines changed

.eslintrc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"env": {
3+
"node": true
4+
},
5+
"rules": {
6+
"strict": 0,
7+
"camelcase": 0,
8+
"curly": 0,
9+
"indent": [2, "tab"],
10+
"eol-last": 2,
11+
"no-shadow": 0,
12+
"no-redeclare": 2,
13+
"no-extra-bind": 2,
14+
"no-empty": 0,
15+
"no-process-exit": 2,
16+
"no-underscore-dangle": 0,
17+
"no-use-before-define": 0,
18+
"no-unused-vars": 0,
19+
"consistent-return": 0,
20+
"no-inner-declarations": 2,
21+
"no-loop-func": 2,
22+
"no-undef": 2,
23+
"space-before-function-paren": [2, "never"]
24+
}
25+
}

.jsbeautifyrc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"js": {
3+
"allowed_file_extensions": ["js", "json", "jshintrc", "jsbeautifyrc"],
4+
"brace_style": "collapse",
5+
"break_chained_methods": false,
6+
"e4x": true,
7+
"eval_code": false,
8+
"end_with_newline": true,
9+
"indent_char": "\t",
10+
"indent_level": 0,
11+
"indent_size": 1,
12+
"indent_with_tabs": true,
13+
"jslint_happy": false,
14+
"jslint_happy_align_switch_case": true,
15+
"space_after_anon_function": false,
16+
"keep_array_indentation": false,
17+
"keep_function_indentation": false,
18+
"max_preserve_newlines": 2,
19+
"preserve_newlines": true,
20+
"space_before_conditional": false,
21+
"space_in_paren": false,
22+
"unescape_strings": false,
23+
"wrap_line_length": 0
24+
}
25+
}

middleware.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var parseRange = require("range-parser");
88

99
var HASH_REGEXP = /[0-9a-f]{10,}/;
1010

11-
var defaultReporter = function (reporterOptions) {
11+
var defaultReporter = function(reporterOptions) {
1212
var state = reporterOptions.state;
1313
var stats = reporterOptions.stats;
1414
var options = reporterOptions.options;
@@ -60,12 +60,16 @@ module.exports = function(compiler, options) {
6060
// We are now on valid state
6161
state = true;
6262
// Do the stuff in nextTick, because bundle may be invalidated
63-
// if a change happend while compiling
63+
// if a change happened while compiling
6464
process.nextTick(function() {
6565
// check if still in valid state
6666
if(!state) return;
6767
// print webpack output
68-
options.reporter({ state: true, stats: stats, options: options });
68+
options.reporter({
69+
state: true,
70+
stats: stats,
71+
options: options
72+
});
6973

7074
// execute callback that are delayed
7175
var cbs = callbacks;
@@ -85,10 +89,15 @@ module.exports = function(compiler, options) {
8589
// on compiling
8690
function invalidPlugin() {
8791
if(state && (!options.noInfo && !options.quiet))
88-
options.reporter({ state: false, options: options })
92+
options.reporter({
93+
state: false,
94+
options: options
95+
})
96+
8997
// We are now in invalid state
9098
state = false;
9199
}
100+
92101
function invalidAsyncPlugin(compiler, callback) {
93102
invalidPlugin();
94103
callback();
@@ -135,7 +144,7 @@ module.exports = function(compiler, options) {
135144
}
136145

137146
function pathJoin(a, b) {
138-
return a == "/" ? "/" + b : (a||"") + "/" + b
147+
return a == "/" ? "/" + b : (a || "") + "/" + b
139148
}
140149

141150
function getFilenameFromUrl(url) {
@@ -157,19 +166,19 @@ module.exports = function(compiler, options) {
157166
}
158167

159168
function handleRangeHeaders(content, req, res) {
160-
if (req.headers['Accept-Ranges']) res.setHeader('Accept-Ranges', 'bytes');
161-
if (req.headers.range) {
169+
if(req.headers['Accept-Ranges']) res.setHeader('Accept-Ranges', 'bytes');
170+
if(req.headers.range) {
162171
var ranges = parseRange(content.length, req.headers.range);
163172

164173
// unsatisfiable
165-
if (-1 == ranges) {
174+
if(-1 == ranges) {
166175
res.setHeader('Content-Range', 'bytes */' + content.length);
167176
res.statusCode = 416;
168177
return content;
169178
}
170179

171180
// valid (syntactically invalid/multiple ranges are treated as a regular response)
172-
if (-2 != ranges && ranges.length === 1) {
181+
if(-2 != ranges && ranges.length === 1) {
173182
// Content-Range
174183
res.statusCode = 206;
175184
var length = content.length;
@@ -187,7 +196,7 @@ module.exports = function(compiler, options) {
187196
// The middleware function
188197
function webpackDevMiddleware(req, res, next) {
189198
var filename = getFilenameFromUrl(req.url);
190-
if (filename === false) return next();
199+
if(filename === false) return next();
191200

192201
// in lazy mode, rebuild on bundle request
193202
if(options.lazy && (!options.filename || options.filename.test(filename)))
@@ -203,11 +212,12 @@ module.exports = function(compiler, options) {
203212
}
204213
// delay the request until we have a vaild bundle
205214
ready(processRequest, req);
215+
206216
function processRequest() {
207217
try {
208218
var stat = fs.statSync(filename);
209219
if(!stat.isFile()) {
210-
if (stat.isDirectory()) {
220+
if(stat.isDirectory()) {
211221
filename = pathJoin(filename, "index.html");
212222
stat = fs.statSync(filename);
213223
if(!stat.isFile()) throw "next";
@@ -231,21 +241,21 @@ module.exports = function(compiler, options) {
231241
}
232242
}
233243
res.statusCode = 200;
234-
if (res.send) res.send(content);
244+
if(res.send) res.send(content);
235245
else res.end(content);
236246
}
237247
}
238248

239249
webpackDevMiddleware.getFilenameFromUrl = getFilenameFromUrl;
240250

241251
webpackDevMiddleware.waitUntilValid = function(callback) {
242-
callback = callback || function(){};
243-
if (!watching || !watching.running) callback();
252+
callback = callback || function() {};
253+
if(!watching || !watching.running) callback();
244254
else ready(callback, {});
245255
};
246256

247257
webpackDevMiddleware.invalidate = function(callback) {
248-
callback = callback || function(){};
258+
callback = callback || function() {};
249259
if(watching) {
250260
ready(callback, {});
251261
watching.invalidate();
@@ -255,7 +265,7 @@ module.exports = function(compiler, options) {
255265
};
256266

257267
webpackDevMiddleware.close = function(callback) {
258-
callback = callback || function(){};
268+
callback = callback || function() {};
259269
if(watching) watching.close(callback);
260270
else callback();
261271
};

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
"mime": "^1.3.4",
1212
"range-parser": "^1.0.3"
1313
},
14+
"devDependencies": {
15+
"eslint": "^2.10.1",
16+
"beautify-lint": "^1.0.4",
17+
"js-beautify": "^1.6.3"
18+
},
1419
"licenses": [
1520
{
1621
"type": "MIT",
@@ -25,5 +30,11 @@
2530
"repository": {
2631
"type": "git",
2732
"url": "https://github.com/webpack/webpack-dev-middleware.git"
33+
},
34+
"scripts": {
35+
"lint": "eslint *.js",
36+
"beautify-lint": "beautify-lint *.js",
37+
"beautify": "beautify-rewrite *.js",
38+
"travis": "npm run lint && npm run beautify-lint && node middleware.js"
2839
}
2940
}

0 commit comments

Comments
 (0)