Skip to content

Commit 46af9d0

Browse files
committed
apply minimal eslint rule overrides
apply a few small eslint fixes
1 parent e692640 commit 46af9d0

File tree

4 files changed

+28
-22
lines changed

4 files changed

+28
-22
lines changed

.eslintrc.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
{
2-
"extends": "eslint-config-populist"
2+
"extends": "eslint-config-populist",
3+
"rules": {
4+
"strict": "warn",
5+
"indent": ["warn", 2],
6+
"valid-jsdoc": "warn",
7+
"no-undefined": "warn",
8+
"comma-dangle": "warn",
9+
"callback-return": ["warn", ["next"]]
10+
}
311
}

lib/core/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function shouldCompressBrotli(req) {
5555

5656
function hasGzipId12(gzipped, cb) {
5757
const stream = fs.createReadStream(gzipped, { start: 0, end: 1 });
58-
let buffer = Buffer('');
58+
let buffer = Buffer.from('');
5959
let hasBeenCalled = false;
6060

6161
stream.on('data', (chunk) => {
@@ -222,7 +222,6 @@ module.exports = function createMiddleware(_dir, _options) {
222222
// and brotli special case.
223223
const defaultType = opts.contentType || 'application/octet-stream';
224224
let contentType = mime.lookup(file, defaultType);
225-
let charSet;
226225
const range = (req.headers && req.headers.range);
227226
const lastModified = (new Date(stat.mtime)).toUTCString();
228227
const etag = generateEtag(stat, weakEtags);

lib/core/show-dir/last-modified-to-string.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
module.exports = function lastModifiedToString(stat) {
44
const t = new Date(stat.mtime);
5-
return (("0" + (t.getDate())).slice(-2) + '-' +
6-
t.toLocaleString('default', { month: 'short' }) + '-' +
5+
return (('0' + (t.getDate())).slice(-2) + '-' +
6+
t.toLocaleString('default', { month: 'short' }) + '-' +
77
t.getFullYear() + ' ' +
8-
("0" + t.getHours()).slice(-2) + ':' +
9-
("0" + t.getMinutes()).slice(-2));
8+
('0' + t.getHours()).slice(-2) + ':' +
9+
('0' + t.getMinutes()).slice(-2));
1010
};

lib/http-server.js

+14-15
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
'use strict';
22

33
var fs = require('fs'),
4-
union = require('union'),
5-
httpServerCore = require('./core'),
6-
auth = require('basic-auth'),
7-
httpProxy = require('http-proxy'),
8-
corser = require('corser'),
9-
path = require('path'),
10-
secureCompare = require('secure-compare');
4+
union = require('union'),
5+
httpServerCore = require('./core'),
6+
auth = require('basic-auth'),
7+
httpProxy = require('http-proxy'),
8+
corser = require('corser'),
9+
secureCompare = require('secure-compare');
1110

1211
//
1312
// Remark: backwards compatibility for previous
@@ -33,13 +32,12 @@ function HttpServer(options) {
3332

3433
if (options.root) {
3534
this.root = options.root;
36-
}
37-
else {
35+
} else {
3836
try {
37+
// eslint-disable-next-line no-sync
3938
fs.lstatSync('./public');
4039
this.root = './public';
41-
}
42-
catch (err) {
40+
} catch (err) {
4341
this.root = './';
4442
}
4543
}
@@ -48,11 +46,12 @@ function HttpServer(options) {
4846
this.headers['Accept-Ranges'] = 'bytes';
4947

5048
this.cache = (
49+
// eslint-disable-next-line no-nested-ternary
5150
options.cache === undefined ? 3600 :
5251
// -1 is a special case to turn off caching.
5352
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#Preventing_caching
54-
options.cache === -1 ? 'no-cache, no-store, must-revalidate' :
55-
options.cache // in seconds.
53+
options.cache === -1 ? 'no-cache, no-store, must-revalidate' :
54+
options.cache // in seconds.
5655
);
5756
this.showDir = options.showDir !== 'false';
5857
this.autoIndex = options.autoIndex !== 'false';
@@ -104,7 +103,7 @@ function HttpServer(options) {
104103
this.headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Range';
105104
if (options.corsHeaders) {
106105
options.corsHeaders.split(/\s*,\s*/)
107-
.forEach(function (h) { this.headers['Access-Control-Allow-Headers'] += ', ' + h; }, this);
106+
.forEach(function (h) { this.headers['Access-Control-Allow-Headers'] += ', ' + h; }, this);
108107
}
109108
before.push(corser.create(options.corsHeaders ? {
110109
requestHeaders: this.headers['Access-Control-Allow-Headers'].split(/\s*,\s*/)
@@ -146,7 +145,7 @@ function HttpServer(options) {
146145
proxy.web(req, res, {
147146
target: options.proxy,
148147
changeOrigin: true
149-
}, function (err, req, res, target) {
148+
}, function (err, req, res) {
150149
if (options.logFn) {
151150
options.logFn(req, res, {
152151
message: err.message,

0 commit comments

Comments
 (0)