Enforce a consistent coding style using eslint

This commit is contained in:
Rob Wu
2016-02-26 12:28:38 +01:00
parent e8f0e64168
commit 0872577729
9 changed files with 96 additions and 70 deletions
+28
View File
@@ -0,0 +1,28 @@
{
"env": {
"node": true
},
"rules": {
"array-bracket-spacing": [2, "never"],
"block-scoped-var": 2,
"brace-style": [2, "1tbs", {"allowSingleLine": true}],
"comma-dangle": [2, "always-multiline"],
"computed-property-spacing": [2, "never"],
"curly": 2,
"eol-last": 2,
"eqeqeq": [2, "smart"],
"max-len": [1, 125],
"new-cap": 1,
"no-extend-native": 2,
"no-mixed-spaces-and-tabs": 2,
"no-trailing-spaces": 2,
"no-undef": 2,
"no-unused-vars": 1,
"no-use-before-define": [2, "nofunc"],
"object-curly-spacing": [2, "never"],
"quotes": [2, "single", "avoid-escape"],
"semi": [2, "always"],
"keyword-spacing": 2,
"space-unary-ops": 2
}
}
-7
View File
@@ -1,7 +0,0 @@
{
"node": true,
"eqnull": true,
"undef": true,
"unused": "vars",
"mocha": true
}
+6 -7
View File
@@ -122,7 +122,6 @@ function proxyRequest(req, res, proxy) {
* @this {HttpProxy}
*/
function onProxyResponse(response, req, res) {
/* jshint validthis:true */
var proxy = this;
var requestState = req.corsAnywhereRequestState;
@@ -200,12 +199,12 @@ function parseURL(req_url) {
return null;
}
if (!match[1]) {
// scheme is omitted.
// Scheme is omitted.
if (req_url.lastIndexOf('//', 0) === -1) {
// "//" is omitted.
req_url = '//' + req_url;
}
req_url = (match[4] == '443' ? 'https:' : 'http:') + req_url;
req_url = (match[4] === '443' ? 'https:' : 'http:') + req_url;
}
return url.parse(req_url);
}
@@ -219,7 +218,7 @@ var getHandler = exports.getHandler = function(options, proxy) {
originWhitelist: [], // If non-empty, requests not from an origin in this list will be blocked.
requireHeader: null, // Require a header to be set?
removeHeaders: [], // Strip these request headers.
setHeaders: {} // Set these request headers.
setHeaders: {}, // Set these request headers.
};
if (options) {
Object.keys(corsAnywhere).forEach(function(option) {
@@ -248,7 +247,7 @@ var getHandler = exports.getHandler = function(options, proxy) {
return function(req, res) {
var cors_headers = withCORS({}, req);
if (req.method == 'OPTIONS') {
if (req.method === 'OPTIONS') {
// Pre-flight request. Reply successfully:
res.writeHead(200, cors_headers);
res.end();
@@ -320,7 +319,7 @@ var getHandler = exports.getHandler = function(options, proxy) {
location: location,
getProxyForUrl: corsAnywhere.getProxyForUrl,
maxRedirects: corsAnywhere.maxRedirects,
proxyBaseUrl: proxyBaseUrl
proxyBaseUrl: proxyBaseUrl,
};
proxyRequest(req, res, proxy);
@@ -330,7 +329,7 @@ var getHandler = exports.getHandler = function(options, proxy) {
// Create server with default and given values
// Creator still needs to call .listen()
exports.createServer = function createServer(options) {
if (!options) options = {};
options = options || {};
// Default options:
var httpProxyOptions = {
File diff suppressed because one or more lines are too long
+2
View File
@@ -26,11 +26,13 @@
"requires-port": "1.0.0"
},
"devDependencies": {
"eslint": "^2.2.0",
"mocha": "~2.2.4",
"nock": "~1.9.0",
"supertest": "~0.15.0"
},
"scripts": {
"lint": "eslint .",
"test": "./node_modules/.bin/mocha ./test/test*.js --reporter spec"
},
"engines": {
+3 -3
View File
@@ -19,12 +19,12 @@ cors_proxy.createServer({
'x-heroku-queue-wait-time',
'x-heroku-queue-depth',
'x-heroku-dynos-in-use',
'x-request-start'
'x-request-start',
],
httpProxyOptions: {
// Do not add X-Forwarded-For, etc. headers, because Heroku already adds it.
xfwd: false
}
xfwd: false,
},
}).listen(port, host, function() {
console.log('Running CORS Anywhere on ' + host + ':' + port);
});
+8 -8
View File
@@ -6,7 +6,7 @@ function echoheaders(origin) {
nock(origin)
.persist()
.get('/echoheaders')
.reply(function(uri) {
.reply(function() {
var headers = this.req.headers;
var excluded_headers = [
'accept-encoding',
@@ -49,18 +49,18 @@ nock('http://example.com')
.get('/redirecttarget')
.reply(200, 'redirect target', {
'Some-header': 'value'
'Some-header': 'value',
})
.head('/redirect')
.reply(302, '', {
'Location': '/redirecttarget'
Location: '/redirecttarget',
})
.get('/redirect')
.reply(302, 'redirecting...', {
'header at redirect': 'should not be here',
'Location': '/redirecttarget'
Location: '/redirecttarget',
})
.get('/redirectposttarget')
@@ -71,22 +71,22 @@ nock('http://example.com')
.post('/redirectpost')
.reply(302, 'redirecting...', {
'Location': '/redirectposttarget'
Location: '/redirectposttarget',
})
.post('/redirect307')
.reply(307, 'redirecting...', {
'Location': '/redirectposttarget'
Location: '/redirectposttarget',
})
.get('/redirect2redirect')
.reply(302, 'redirecting to redirect...', {
'Location': '/redirect'
Location: '/redirect',
})
.get('/redirectloop')
.reply(302, 'redirecting ad infinitum...', {
'Location': '/redirectloop'
Location: '/redirectloop',
})
.get('/proxyerror')
+1
View File
@@ -1,3 +1,4 @@
/* eslint-env mocha */
// Run this specific test using:
// npm test -- -f memory
var http = require('http');
+11 -10
View File
@@ -1,3 +1,4 @@
/* eslint-env mocha */
require('./setup');
var createServer = require('../').createServer;
@@ -8,7 +9,7 @@ var fs = require('fs');
var assert = require('assert');
var helpTextPath = path.join(__dirname, '../lib/help.txt');
var helpText = fs.readFileSync(helpTextPath, { encoding: 'utf8' });
var helpText = fs.readFileSync(helpTextPath, {encoding: 'utf8'});
request.Test.prototype.expectJSON = function(json, done) {
this.expect(function(res) {
@@ -132,7 +133,7 @@ describe('Basic functionality', function() {
.post('/example.com/echopost')
.attach('file', path.join(__dirname, 'dummy.txt'))
.expect('Access-Control-Allow-Origin', '*')
.expect(/\r\nContent-Disposition: form-data; name="file"; filename="dummy.txt"\r\nContent-Type: text\/plain\r\n\r\ndummy content\n\r\n/, done);
.expect(/\r\nContent-Disposition: form-data; name="file"; filename="dummy.txt"\r\nContent-Type: text\/plain\r\n\r\ndummy content\n\r\n/, done); // eslint-disable-line max-len
});
it('HEAD with redirect should be followed', function(done) {
@@ -494,7 +495,7 @@ describe('setHeaders', function() {
.expect('Access-Control-Allow-Origin', '*')
.expectJSON({
host: 'example.com',
'x-powered-by': 'CORS Anywhere'
'x-powered-by': 'CORS Anywhere',
}, done);
});
@@ -505,7 +506,7 @@ describe('setHeaders', function() {
.expect('Access-Control-Allow-Origin', '*')
.expectJSON({
host: 'example.com',
'x-powered-by': 'CORS Anywhere'
'x-powered-by': 'CORS Anywhere',
}, done);
});
});
@@ -527,7 +528,7 @@ describe('setHeaders + removeHeaders', function() {
.expect('Access-Control-Allow-Origin', '*')
.expectJSON({
host: 'example.com',
'x-powered-by': 'CORS Anywhere'
'x-powered-by': 'CORS Anywhere',
}, done);
});
@@ -538,7 +539,7 @@ describe('setHeaders + removeHeaders', function() {
.expect('Access-Control-Allow-Origin', '*')
.expectJSON({
host: 'example.com',
'x-powered-by': 'CORS Anywhere'
'x-powered-by': 'CORS Anywhere',
}, done);
});
});
@@ -547,8 +548,8 @@ describe('httpProxyOptions.xfwd=false', function() {
before(function() {
cors_anywhere = createServer({
httpProxyOptions: {
xfwd: false
}
xfwd: false,
},
});
cors_anywhere_port = cors_anywhere.listen(0).address().port;
});
@@ -577,8 +578,8 @@ describe('httpProxyOptions.getProxyForUrl', function() {
cors_anywhere = createServer({
httpProxyOptions: {
xfwd: false
}
xfwd: false,
},
});
cors_anywhere_port = cors_anywhere.listen(0).address().port;
});