Skip to content

Commit

Permalink
fix more eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
eugef committed Jan 2, 2024
1 parent 784ee84 commit fd64a19
Show file tree
Hide file tree
Showing 10 changed files with 808 additions and 1,399 deletions.
15 changes: 13 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"airbnb-base",
"prettier"
],
"parser": "@typescript-eslint/parser",
"rules": {
"no-underscore-dangle": "off",
"no-console": "off",
Expand All @@ -11,6 +12,14 @@
"warn",
"as-needed"
],
"prefer-destructuring": [
"error",
{
"object": true,
"array": false
}
],
"no-prototype-builtins": "warn",
"no-restricted-syntax": [
"error",
{
Expand All @@ -26,11 +35,13 @@
"overrides": [
{
"files": [
"test/**/*.js"
"test/**/*.js",
"test/**/*.ts"
],
"env": {
"mocha": true
}
}
]
],
"root": true
}
12 changes: 4 additions & 8 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@ const istanbul = require('gulp-istanbul');

const files = {
src: ['./lib/**/*.js'],
test: ['./test/**/*.spec.js', './*.js'],
test: ['./test/**/*.spec.js', './test/**/*.spec.ts'],
testTs: ['./test/**/*.spec.ts']
};
gulp.task('dot', () => gulp.src(files.test, { read: false }).pipe(mocha({ reporter: 'dot' })));
gulp.task('dot', () =>
gulp.src(files.test, { read: false }).pipe(mocha({ reporter: 'spec', require: 'ts-node/register' }))
);

gulp.task('test', gulp.series('dot'));

gulp.task('test:ts', () =>
gulp.src(files.testTs, { read: false }).pipe(mocha({ reporter: 'dot', require: 'ts-node/register' }))
);

gulp.task('spec', () => gulp.src(files.test, { read: false }).pipe(mocha({ reporter: 'spec' })));

gulp.task('spec:ts', () => gulp.src(files.testTs, { read: false }).pipe(mocha({ reporter: 'spec' })));

gulp.task('coverage', (done) => {
gulp.src(files.src)
.pipe(istanbul())
Expand Down
2 changes: 1 addition & 1 deletion lib/express/mock-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ defineGetter(req, 'hostname', function hostname() {
const offset = host[0] === '[' ? host.indexOf(']') + 1 : 0;
const index = host.indexOf(':', offset);

return ~index ? host.substring(0, index) : host;
return index < 0 ? host.substring(0, index) : host;
});

defineGetter(req, 'host', function host() {
Expand Down
4 changes: 2 additions & 2 deletions lib/mockRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,7 @@ function createRequest(options) {
* @param value The value associated with the variable
*/
mockRequest._setHeadersVariable = function (variable, value) {
variable = variable.toLowerCase();
mockRequest.headers[variable] = value;
mockRequest.headers[variable.toLowerCase()] = value;
};

/**
Expand Down Expand Up @@ -605,6 +604,7 @@ function createRequest(options) {

try {
for (;;) {
// eslint-disable-next-line no-await-in-loop
await new Promise(promiseExecutor);
let i = 0;
for (;;) {
Expand Down
20 changes: 10 additions & 10 deletions lib/mockResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ function createResponse(options) {
* callback - Optional callback function, called once the logic has run
*
*/
mockResponse.end = function () {
mockResponse.end = function (...endArgs) {
if (_endCalled) {
// Do not emit this event twice.
return;
Expand All @@ -423,7 +423,7 @@ function createResponse(options) {

_endCalled = true;

const args = getEndArguments(arguments);
const args = getEndArguments(endArgs);

if (args.data) {
if (args.data instanceof Buffer) {
Expand Down Expand Up @@ -568,9 +568,10 @@ function createResponse(options) {
} else if (typeof field === 'string') {
return mockResponse.getHeader(field);
} else {
// eslint-disable-line
for (const key in field) {
mockResponse.setHeader(key, field[key]);
if ({}.hasOwnProperty.call(field, key)) {
mockResponse.setHeader(key, field[key]);
}
}
}
return mockResponse;
Expand Down Expand Up @@ -729,8 +730,7 @@ function createResponse(options) {

if (!mockRequest) {
throw new Error(
'Request object unavailable. Use createMocks or pass in a ' +
'request object in createResponse to use format.'
'Request object unavailable. Use createMocks or pass in a request object in createResponse to use format.'
);
}

Expand All @@ -756,12 +756,12 @@ function createResponse(options) {
// return writableStream.end.apply(this, arguments);
// };

mockResponse.destroy = function () {
return writableStream.destroy.apply(this, arguments);
mockResponse.destroy = function (...args) {
return writableStream.destroy.apply(this, args);
};

mockResponse.destroySoon = function () {
return writableStream.destroySoon.apply(this, arguments);
mockResponse.destroySoon = function (...args) {
return writableStream.destroySoon.apply(this, args);
};

// This mock object stores some state as well
Expand Down
Loading

0 comments on commit fd64a19

Please sign in to comment.