Skip to content

Commit

Permalink
enable eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
eugef committed Dec 29, 2023
1 parent 236d902 commit 784ee84
Show file tree
Hide file tree
Showing 28 changed files with 3,390 additions and 3,155 deletions.
126 changes: 36 additions & 90 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,90 +1,36 @@
env:
node: true
es2017: true

parserOptions:
ecmaVersion: 2019

rules:
comma-dangle: 2
no-alert: 2
no-array-constructor: 2
no-caller: 2
no-catch-shadow: 2
no-control-regex: 2
no-debugger: 2
no-div-regex: 2
no-dupe-keys: 2
no-else-return: 2
no-empty: 2
no-empty-character-class: 2
no-eq-null: 2
no-eval: 2
no-ex-assign: 2
no-func-assign: 0
no-floating-decimal: 2
no-implied-eval: 2
no-with: 2
no-fallthrough: 2
no-unreachable: 2
no-undef: 2
no-undef-init: 2
no-unused-expressions: 2
no-octal: 2
no-octal-escape: 2
no-obj-calls: 2
no-multi-str: 2
no-new-wrappers: 2
no-new: 2
no-new-func: 2
no-native-reassign: 2
no-delete-var: 2
no-return-assign: 2
no-new-object: 2
no-label-var: 2
no-self-compare: 2
no-sync: 2
no-loop-func: 2
no-labels: 2
no-unused-vars:
- 1
- argsIgnorePattern: ^_
varsIgnorePattern: ^_
no-script-url: 2
no-proto: 2
no-iterator: 2
no-mixed-requires:
- 0
- false
no-extra-parens: 2
no-shadow: 2
no-use-before-define: 2
no-redeclare: 2
no-regex-spaces: 2
no-mixed-spaces-and-tabs: 2
no-underscore-dangle: 0

brace-style: 2
camelcase: 2
consistent-this:
- 2
- self
curly: 2
dot-notation: 2
eqeqeq: 2
new-cap: 2
new-parens: 2
quotes:
- 2
- single
semi: 2
strict:
- 2
- global
use-isnan: 2
valid-typeof: 2
wrap-iife: 2
indent:
- 1
- 4
- SwitchCase: 1
{
"extends": [
"airbnb-base",
"prettier"
],
"rules": {
"no-underscore-dangle": "off",
"no-console": "off",
"no-plusplus": "off",
"func-names": [
"warn",
"as-needed"
],
"no-restricted-syntax": [
"error",
{
"selector": "LabeledStatement",
"message": "Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.",
},
{
"selector": "WithStatement",
"message": "`with` is disallowed in strict mode because it makes code impossible to predict and optimize.",
},
]
},
"overrides": [
{
"files": [
"test/**/*.js"
],
"env": {
"mocha": true
}
}
]
}
3 changes: 2 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run format
npm run format && npm run lint

16 changes: 7 additions & 9 deletions examples/express-route.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
'use strict';

var httpMocks = require('../lib/http-mock');
const httpMocks = require('../lib/http-mock');

// Suppose you have the following Express route:

// app.get('/user/:id', routeHandler);

// And you have created a function to handle that route's call:

var routeHandler = function (request, response) {
var id = request.params.id;
const routeHandler = function (request, response) {
const { id } = request.params;

console.log("We have a '%s' request for %s (ID: %d)", request.method, request.url, id);

var body = {
const body = {
name: 'Bob Dog',
age: 42,
email: '[email protected]'
Expand All @@ -30,19 +28,19 @@ var routeHandler = function (request, response) {
// with some code like this using the testing framework of your choice:

exports['routeHandler - Simple testing'] = function (test) {
var request = httpMocks.createRequest({
const request = httpMocks.createRequest({
method: 'GET',
url: '/user/42',
params: {
id: 42
}
});

var response = httpMocks.createResponse();
const response = httpMocks.createResponse();

routeHandler(request, response);

var data = response._getJSONData();
const data = response._getJSONData();

test.equal('Bob Dog', data.name);
test.equal(42, data.age);
Expand Down
14 changes: 6 additions & 8 deletions examples/express-status-vs-json.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
'use strict';

var httpMocks = require('../lib/http-mock');
const httpMocks = require('../lib/http-mock');

// Suppose you have the following Express route:

// app.post('/users', routeHandler);

// And you have created a function to handle that route's call:

var routeHandler = function (request, response) {
const routeHandler = function (request, response) {
console.log("We have a '%s' request for %s", request.method, request.url);

var body = {
const body = {
name: 'Bob Dog',
age: 42,
email: '[email protected]'
Expand All @@ -26,16 +24,16 @@ var routeHandler = function (request, response) {
// with some code like this using the testing framework of your choice:

exports['routeHandler - Simple testing of status() vs json()'] = function (test) {
var request = httpMocks.createRequest({
const request = httpMocks.createRequest({
method: 'POST',
url: '/users'
});

var response = httpMocks.createResponse();
const response = httpMocks.createResponse();

routeHandler(request, response);

var data = response._getJSONData();
const data = response._getJSONData();

test.equal('Bob Dog', data.name);
test.equal(42, data.age);
Expand Down
49 changes: 13 additions & 36 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,29 @@
'use strict';
const gulp = require('gulp');
const mocha = require('gulp-mocha');
const istanbul = require('gulp-istanbul');

var gulp = require('gulp');
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
var eslint = require('gulp-eslint');

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

gulp.task('lint', function () {
return gulp
.src(files.src.concat(files.test))
.pipe(
eslint({
// configFile: './.eslintrc',
useEslintrc: true
})
)
.pipe(eslint.format())
.pipe(eslint.failOnError());
});

gulp.task('dot', function () {
return gulp.src(files.test, { read: false }).pipe(mocha({ reporter: 'dot' }));
});

gulp.task('test', gulp.series('dot' /*, 'lint'*/));
gulp.task('test', gulp.series('dot'));

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

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

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

gulp.task('coverage', function (done) {
gulp.task('coverage', (done) => {
gulp.src(files.src)
.pipe(istanbul())
.pipe(istanbul.hookRequire())
.on('finish', function () {
.on('finish', () => {
gulp.src(files.test)
.pipe(mocha({ reporter: 'dot' }))
.pipe(
Expand Down
16 changes: 7 additions & 9 deletions lib/express/mock-application.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
'use strict';
const methods = require('methods');
const deprecate = require('depd')('express');

var methods = require('methods');
var deprecate = require('depd')('express');

var app = (exports = module.exports = {});
var trustProxyDefaultSymbol = '@@symbol:trust_proxy_default';
const app = (exports = module.exports = {});
const trustProxyDefaultSymbol = '@@symbol:trust_proxy_default';

app.init = function () {
this.cache = {};
Expand All @@ -16,7 +14,7 @@ app.init = function () {
app.defaultConfiguration = function () {
this.enable('x-powered-by');
this.set('etag', 'weak');
var env = process.env.NODE_ENV || 'development';
const env = process.env.NODE_ENV || 'development';
this.set('env', env);
this.set('query parser', 'extended');
this.set('subdomain offset', 2);
Expand All @@ -36,7 +34,7 @@ app.defaultConfiguration = function () {
}

Object.defineProperty(this, 'router', {
get: function () {
get() {
throw new Error(
"'app.router' is deprecated!\nPlease see the 3.x to 4.x migration guide for details on how to update your app."
);
Expand Down Expand Up @@ -91,7 +89,7 @@ app.disable = function (setting) {
return this.set(setting, false);
};

methods.forEach(function (method) {
methods.forEach((method) => {
app[method] = function () {
return this;
};
Expand Down
20 changes: 9 additions & 11 deletions lib/express/mock-express.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
'use strict';
const { EventEmitter } = require('events');

var EventEmitter = require('events').EventEmitter;
const mixin = require('merge-descriptors');

var mixin = require('merge-descriptors');
const application = require('./mock-application');
const request = require('./mock-request');
const response = require('../mockResponse');

var application = require('./mock-application');
var request = require('./mock-request');
var response = require('../mockResponse');

var expressResponse = {
const expressResponse = {
createResponse: response.createResponse
};

function createApplication() {
var app = function () {};
const app = function () {};

mixin(app, EventEmitter.prototype, false);
mixin(app, application, false);

app.request = {
__proto__: request,
app: app
app
};
app.response = {
__proto__: expressResponse.createResponse(),
app: app
app
};
app.init();
return app;
Expand Down
Loading

0 comments on commit 784ee84

Please sign in to comment.