Skip to content

Commit

Permalink
apply minimal eslint rule overrides
Browse files Browse the repository at this point in the history
apply a few small eslint fixes
  • Loading branch information
chris--jones committed Oct 9, 2021
1 parent e692640 commit 46af9d0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
10 changes: 9 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{
"extends": "eslint-config-populist"
"extends": "eslint-config-populist",
"rules": {
"strict": "warn",
"indent": ["warn", 2],
"valid-jsdoc": "warn",
"no-undefined": "warn",
"comma-dangle": "warn",
"callback-return": ["warn", ["next"]]
}
}
3 changes: 1 addition & 2 deletions lib/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function shouldCompressBrotli(req) {

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

stream.on('data', (chunk) => {
Expand Down Expand Up @@ -222,7 +222,6 @@ module.exports = function createMiddleware(_dir, _options) {
// and brotli special case.
const defaultType = opts.contentType || 'application/octet-stream';
let contentType = mime.lookup(file, defaultType);
let charSet;
const range = (req.headers && req.headers.range);
const lastModified = (new Date(stat.mtime)).toUTCString();
const etag = generateEtag(stat, weakEtags);
Expand Down
8 changes: 4 additions & 4 deletions lib/core/show-dir/last-modified-to-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

module.exports = function lastModifiedToString(stat) {
const t = new Date(stat.mtime);
return (("0" + (t.getDate())).slice(-2) + '-' +
t.toLocaleString('default', { month: 'short' }) + '-' +
return (('0' + (t.getDate())).slice(-2) + '-' +
t.toLocaleString('default', { month: 'short' }) + '-' +
t.getFullYear() + ' ' +
("0" + t.getHours()).slice(-2) + ':' +
("0" + t.getMinutes()).slice(-2));
('0' + t.getHours()).slice(-2) + ':' +
('0' + t.getMinutes()).slice(-2));
};
29 changes: 14 additions & 15 deletions lib/http-server.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
'use strict';

var fs = require('fs'),
union = require('union'),
httpServerCore = require('./core'),
auth = require('basic-auth'),
httpProxy = require('http-proxy'),
corser = require('corser'),
path = require('path'),
secureCompare = require('secure-compare');
union = require('union'),
httpServerCore = require('./core'),
auth = require('basic-auth'),
httpProxy = require('http-proxy'),
corser = require('corser'),
secureCompare = require('secure-compare');

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

if (options.root) {
this.root = options.root;
}
else {
} else {
try {
// eslint-disable-next-line no-sync
fs.lstatSync('./public');
this.root = './public';
}
catch (err) {
} catch (err) {
this.root = './';
}
}
Expand All @@ -48,11 +46,12 @@ function HttpServer(options) {
this.headers['Accept-Ranges'] = 'bytes';

this.cache = (
// eslint-disable-next-line no-nested-ternary
options.cache === undefined ? 3600 :
// -1 is a special case to turn off caching.
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#Preventing_caching
options.cache === -1 ? 'no-cache, no-store, must-revalidate' :
options.cache // in seconds.
options.cache === -1 ? 'no-cache, no-store, must-revalidate' :
options.cache // in seconds.
);
this.showDir = options.showDir !== 'false';
this.autoIndex = options.autoIndex !== 'false';
Expand Down Expand Up @@ -104,7 +103,7 @@ function HttpServer(options) {
this.headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Range';
if (options.corsHeaders) {
options.corsHeaders.split(/\s*,\s*/)
.forEach(function (h) { this.headers['Access-Control-Allow-Headers'] += ', ' + h; }, this);
.forEach(function (h) { this.headers['Access-Control-Allow-Headers'] += ', ' + h; }, this);
}
before.push(corser.create(options.corsHeaders ? {
requestHeaders: this.headers['Access-Control-Allow-Headers'].split(/\s*,\s*/)
Expand Down Expand Up @@ -146,7 +145,7 @@ function HttpServer(options) {
proxy.web(req, res, {
target: options.proxy,
changeOrigin: true
}, function (err, req, res, target) {
}, function (err, req, res) {
if (options.logFn) {
options.logFn(req, res, {
message: err.message,
Expand Down

0 comments on commit 46af9d0

Please sign in to comment.