Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eslint config - replace common-style with eslint-config-populist #744

Merged
merged 3 commits into from Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,11 @@
{
"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
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
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
@@ -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