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

add standard and prepare for standard lint #44

Merged
merged 4 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const warning = process.env['CI'] ? 2 : 1;

module.exports = {
parserOptions: {
ecmaVersion: 2018,
},
ignorePatterns: [
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved
'/bench'
],
extends: [
'eslint:recommended',
'plugin:node/recommended',
Expand Down
2 changes: 1 addition & 1 deletion deps/dicer/lib/HeaderParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var StreamSearch = require('../../streamsearch/sbmh');

var B_DCRLF = Buffer.from('\r\n\r\n'),
RE_CRLF = /\r\n/g,
RE_HDR = /^([^:]+):[ \t]?([\x00-\xFF]+)?$/,
RE_HDR = /^([^:]+):[ \t]?([\x00-\xFF]+)?$/, // eslint-disable-line no-control-regex
MAX_HEADER_PAIRS = 2000, // from node's http.js
MAX_HEADER_SIZE = 80 * 1024; // from node's http_parser

Expand Down
63 changes: 0 additions & 63 deletions deps/encoding/TextDecoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,6 @@ function decoderError(fatal, opt_code_point) {
return opt_code_point || 0xFFFD;
}

/**
* @param {number} code_point The code point that could not be encoded.
* @return {number} Always throws, no value is actually returned.
*/
function encoderError(code_point) {
throw new EncodingError('The code point ' + code_point +
' could not be encoded.');
}

/**
* @param {string} label The encoding label.
* @return {?{name:string,labels:Array.<string>}}
Expand Down Expand Up @@ -678,17 +669,6 @@ function indexCodePointFor(pointer, index) {
return index[pointer] || null;
}

/**
* @param {number} code_point The |code point| to search for.
* @param {Array.<?number>} index The |index| to search within.
* @return {?number} The first pointer corresponding to |code point| in
* |index|, or null if |code point| is not in |index|.
*/
function indexPointerFor(code_point, index) {
var pointer = index.indexOf(code_point);
return pointer === -1 ? null : pointer;
}

/** @type {Object.<string, (Array.<number>|Array.<Array.<number>>)>} */
var indexes = require('./encoding-indexes');

Expand Down Expand Up @@ -717,29 +697,6 @@ function indexGB18030CodePointFor(pointer) {
return code_point_offset + pointer - offset;
}

/**
* @param {number} code_point The |code point| to locate in the gb18030 index.
* @return {number} The first pointer corresponding to |code point| in the
* gb18030 index.
*/
function indexGB18030PointerFor(code_point) {
var /** @type {number} */ offset = 0,
/** @type {number} */ pointer_offset = 0,
/** @type {Array.<Array.<number>>} */ idx = indexes['gb18030'];
var i;
for (i = 0; i < idx.length; ++i) {
var entry = idx[i];
if (entry[1] <= code_point) {
offset = entry[1];
pointer_offset = entry[0];
} else {
break;
}
}
return pointer_offset + code_point - offset;
}


//
// 7. API
//
Expand Down Expand Up @@ -1719,26 +1676,6 @@ name_to_encoding['utf-16le'].getDecoder = function(options) {
// 14.5 x-user-defined
// TODO: Implement this encoding.

// NOTE: currently unused
/**
* @param {string} label The encoding label.
* @param {ByteInputStream} input_stream The byte stream to test.
*/
function detectEncoding(label, input_stream) {
if (input_stream.match([0xFF, 0xFE])) {
input_stream.offset(2);
return 'utf-16le';
}
if (input_stream.match([0xFE, 0xFF])) {
input_stream.offset(2);
return 'utf-16be';
}
if (input_stream.match([0xEF, 0xBB, 0xBF])) {
input_stream.offset(3);
return 'utf-8';
}
return label;
}
function hasEncoding(label) {
return Object.prototype.hasOwnProperty.call(label_to_encoding, String(label).trim().toLowerCase());
}
Expand Down
32 changes: 16 additions & 16 deletions deps/streamsearch/sbmh.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,31 @@ function SBMH(needle) {
throw new TypeError("The needle has to be a String or a Buffer.");
}

const needle_len = needle.length;
const needleLength = needle.length;

if (needle_len === 0) {
if (needleLength === 0) {
throw new Error("The needle cannot be an empty String/Buffer.");
}

if (needle_len > 256) {
if (needleLength > 256) {
throw new Error("The needle cannot have a length bigger than 256.");
}

this.maxMatches = Infinity;
this.matches = 0;

this._occ = new Array(256)
.fill(needle_len); // Initialize occurrence table.
.fill(needleLength); // Initialize occurrence table.
this._lookbehind_size = 0;
this._needle = needle;
this._bufpos = 0;

this._lookbehind = Buffer.alloc(needle_len);
this._lookbehind = Buffer.alloc(needleLength);

// Populate occurrence table with analysis of the needle,
// ignoring last letter.
for (var i = 0; i < needle_len - 1; ++i)
this._occ[needle[i]] = needle_len - 1 - i;
for (var i = 0; i < needleLength - 1; ++i)
this._occ[needle[i]] = needleLength - 1 - i;
}
inherits(SBMH, EventEmitter);

Expand All @@ -85,8 +85,8 @@ SBMH.prototype.push = function (chunk, pos) {
SBMH.prototype._sbmh_feed = function (data) {
const len = data.length,
needle = this._needle,
needle_len = needle.length,
last_needle_char = needle[needle_len - 1];
needleLength = needle.length,
lastNeedleChar = needle[needleLength - 1];

// Positive: points to a position in `data`
// pos == 3 points to data[3]
Expand All @@ -108,18 +108,18 @@ SBMH.prototype._sbmh_feed = function (data) {
// optimized loop.
// or until
// the character to look at lies outside the haystack.
while (pos < 0 && pos <= len - needle_len) {
ch = this._sbmh_lookup_char(data, pos + needle_len - 1);
while (pos < 0 && pos <= len - needleLength) {
ch = this._sbmh_lookup_char(data, pos + needleLength - 1);

if (
ch === last_needle_char &&
this._sbmh_memcmp(data, pos, needle_len - 1)
ch === lastNeedleChar &&
this._sbmh_memcmp(data, pos, needleLength - 1)
) {
this._lookbehind_size = 0;
++this.matches;
this.emit('info', true);

return (this._bufpos = pos + needle_len);
return (this._bufpos = pos + needleLength);
}
pos += this._occ[ch];
}
Expand Down Expand Up @@ -177,9 +177,9 @@ SBMH.prototype._sbmh_feed = function (data) {
else
this.emit('info', true);

return (this._bufpos = pos + needle_len);
return (this._bufpos = pos + needleLength);
} else {
pos = len - needle_len;
pos = len - needleLength;
}

// There was no match. If there's trailing haystack data that we cannot
Expand Down
2 changes: 1 addition & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Busboy.prototype._write = function(chunk, encoding, cb) {
this._parser.write(chunk, cb);
};

var TYPES = [
const TYPES = [
require('./types/multipart'),
require('./types/urlencoded'),
];
Expand Down
4 changes: 2 additions & 2 deletions lib/types/multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ function Multipart(boy, cfg) {
if (typeof boundary !== 'string')
throw new Error('Multipart: Boundary not found');

var fieldSizeLimit = getLimit(limits, 'fieldSize', 1 * 1024 * 1024),
const fieldSizeLimit = getLimit(limits, 'fieldSize', 1 * 1024 * 1024),
fileSizeLimit = getLimit(limits, 'fileSize', Infinity),
filesLimit = getLimit(limits, 'files', Infinity),
fieldsLimit = getLimit(limits, 'fields', Infinity),
partsLimit = getLimit(limits, 'parts', Infinity);

var nfiles = 0,
let nfiles = 0,
nfields = 0,
nends = 0,
curFile,
Expand Down
3 changes: 1 addition & 2 deletions lib/types/urlencoded.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ function UrlEncoded(boy, cfg) {
if (!(this instanceof UrlEncoded))
return new UrlEncoded(boy, cfg);
var limits = cfg.limits,
headers = cfg.headers,
parsedConType = cfg.parsedConType;
this.boy = boy;

Expand Down Expand Up @@ -91,7 +90,7 @@ UrlEncoded.prototype.write = function(data, cb) {
} else if (idxamp !== undefined) {
// key with no assignment
++this._fields;
var key, keyTrunc = this._keyTrunc;
let key, keyTrunc = this._keyTrunc;
if (idxamp > p)
key = (this._key += this.decoder.write(data.toString('binary', p, idxamp)));
else
Expand Down
24 changes: 12 additions & 12 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,20 @@ function basename(path) {
}

function getLimit(limits, name, defaultLimit) {
if (!limits)
return defaultLimit;
if (
!limits ||
limits[name] === undefined ||
limits[name] === null
)
return defaultLimit;

var limit = limits[name];
// Intentional double equals
if (limit == undefined)
return defaultLimit;
if (
typeof limits[name] !== 'number' ||
isNaN(limits[name])
)
throw new TypeError('Limit ' + name + ' is not a valid number');

// Ensure limit is a number and is not NaN
if (typeof limit !== 'number' || limit !== limit) {
throw new Error('Limit ' + name + ' is not a valid number');
}

return limit;
return limits[name];
}

module.exports = {
Expand Down
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"coveralls": "nyc report --reporter=lcov",
"lint": "eslint .",
"lint:everything": "npm run lint && npm run test:types",
"lint:fix": "standard --fix",
"lint:standard": "standard --verbose | snazzy",
"test:mocha": "mocha test",
"test:types": "tsd",
"test:coverage": "nyc npm run test",
Expand All @@ -37,9 +39,12 @@
"busboy": "^0.3.1",
"chai": "^4.3.4",
"eslint": "^8.3.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-node": "^11.1.0",
"mocha": "^9.1.3",
"nyc": "^15.1.0",
"snazzy": "^9.0.0",
"standard": "^16.0.4",
"tsd": "^0.19.0",
"typescript": "^4.5.2"
},
Expand All @@ -62,6 +67,13 @@
"target": "ES2017"
}
},
"standard": {
"globals": [ "describe", "it" ],
"ignore": [
"deps/encoding",
"bench"
]
},
"files": [
"README.md",
"LICENSE",
Expand Down
6 changes: 3 additions & 3 deletions test/dicer-multipart-extra-trailer.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const Dicer = require('../deps/dicer/lib/Dicer');
const assert = require('assert'),
fs = require('fs'),
path = require('path'),
inspect = require('util').inspect;

const FIXTURES_ROOT = __dirname + '/fixtures/';
const FIXTURES_ROOT = path.join(__dirname, '/fixtures/');
Uzlopak marked this conversation as resolved.
Show resolved Hide resolved

describe('dicer-multipart-extra-trailer', () => {
[
Expand All @@ -17,12 +18,11 @@ describe('dicer-multipart-extra-trailer', () => {
].forEach(function (v) {
it(v.what, (done) => {
let fixtureBase = FIXTURES_ROOT + v.source,
fd,
n = 0,
buffer = Buffer.allocUnsafe(v.chsize),
state = { parts: [] };

fd = fs.openSync(fixtureBase + '/original', 'r');
const fd = fs.openSync(fixtureBase + '/original', 'r');

const dicer = new Dicer(v.opts);
let error,
Expand Down
2 changes: 1 addition & 1 deletion test/dicer-multipart-nolisteners.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const assert = require('assert'),
path = require('path'),
inspect = require('util').inspect;

const FIXTURES_ROOT = path.resolve(__dirname, 'fixtures/');
const FIXTURES_ROOT = path.join(__dirname, '/fixtures/');

describe('dicer-multipart-nolisteners', () => {
[
Expand Down
6 changes: 2 additions & 4 deletions test/dicer-multipart.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const assert = require('assert'),
path = require('path'),
inspect = require('util').inspect;

const FIXTURES_ROOT = __dirname + '/fixtures/';
const FIXTURES_ROOT = path.join(__dirname, '/fixtures/');

describe('dicer-multipart', () => {
[
Expand Down Expand Up @@ -58,9 +58,7 @@ describe('dicer-multipart', () => {
it(v.what, (done) => {

const fixtureBase = FIXTURES_ROOT + v.source;
let n = 0,
buffer = Buffer.allocUnsafe(v.chsize),
state = { parts: [], preamble: undefined };
const state = { parts: [], preamble: undefined };

const dicer = new Dicer(v.opts);
let error,
Expand Down