Eslint errors

This commit is contained in:
Daniel García Aubert 2019-12-26 17:46:27 +01:00
parent 43481b42e5
commit 014158c968
17 changed files with 53 additions and 70 deletions

View File

@ -1,7 +1,5 @@
'use strict'; 'use strict';
// jshint ignore:start
const debug = require('debug')('>'); const debug = require('debug')('>');
debug.enabled = true; debug.enabled = true;
const { promisify } = require('util'); const { promisify } = require('util');
@ -129,5 +127,3 @@ async function main () {
} }
main().then(() => process.exit(0)); main().then(() => process.exit(0));
// jshint ignore:end

View File

@ -185,7 +185,6 @@ JobFallback.prototype.setFallbackStatus = function (status, job, hasChanged) {
}; };
JobFallback.prototype.shiftStatus = function (status, hasChanged) { JobFallback.prototype.shiftStatus = function (status, hasChanged) {
// jshint maxcomplexity: 7
if (hasChanged.appliedToFallback) { if (hasChanged.appliedToFallback) {
if (!this.hasNextQueryFromQueries() && (status === JobStatus.DONE || status === JobStatus.FAILED)) { if (!this.hasNextQueryFromQueries() && (status === JobStatus.DONE || status === JobStatus.FAILED)) {
status = this.getLastFinishedStatus(); status = this.getLastFinishedStatus();

View File

@ -40,7 +40,6 @@ QueryFallback.prototype.getNextQuery = function (job) {
}; };
QueryFallback.prototype.setStatus = function (status, job, previous, errorMesssage) { QueryFallback.prototype.setStatus = function (status, job, previous, errorMesssage) {
// jshint maxcomplexity: 9
var isValid = false; var isValid = false;
var appliedToFallback = false; var appliedToFallback = false;

View File

@ -19,7 +19,6 @@ BinaryFormat.prototype._extractTypeFromName = function (name) {
} }
}; };
// jshint maxcomplexity:12
BinaryFormat.prototype.transform = function (result, options, callback) { BinaryFormat.prototype.transform = function (result, options, callback) {
var total_rows = result.rowCount; var total_rows = result.rowCount;
var rows = result.rows; var rows = result.rows;

View File

@ -14,7 +14,6 @@ JsonFormat.prototype = new Pg('json');
JsonFormat.prototype._contentType = 'application/json; charset=utf-8'; JsonFormat.prototype._contentType = 'application/json; charset=utf-8';
// jshint maxcomplexity:10
JsonFormat.prototype.formatResultFields = function (flds) { JsonFormat.prototype.formatResultFields = function (flds) {
flds = flds || []; flds = flds || [];
var nfields = {}; var nfields = {};
@ -93,7 +92,6 @@ JsonFormat.prototype.handleQueryRow = function (row, result) {
} }
}; };
// jshint maxcomplexity:13
JsonFormat.prototype.handleQueryEnd = function (result) { JsonFormat.prototype.handleQueryEnd = function (result) {
if (this.error && !this._streamingStarted) { if (this.error && !this._streamingStarted) {
this.callback(this.error); this.callback(this.error);

View File

@ -2,18 +2,18 @@
var Pg = require('./../pg'); var Pg = require('./../pg');
var svg_width = 1024.0; var svgWidth = 1024.0;
var svg_height = 768.0; var svgHeight = 768.0;
var svg_ratio = svg_width / svg_height; var svgRatio = svgWidth / svgHeight;
var radius = 5; // in pixels (based on svg_width and svg_height) var radius = 5; // in pixels (based on svgWidth and svgHeight)
var stroke_width = 1; // in pixels (based on svg_width and svg_height) var strokeWidth = 1; // in pixels (based on svgWidth and svgHeight)
var stroke_color = 'black'; var strokeColor = 'black';
// fill settings affect polygons and points (circles) // fill settings affect polygons and points (circles)
var fill_opacity = 0.5; // 0.0 is fully transparent, 1.0 is fully opaque var fillOpacity = 0.5; // 0.0 is fully transparent, 1.0 is fully opaque
// unused if fill_color='none' // unused if fillColor='none'
var fill_color = 'none'; // affects polygons and circles var fillColor = 'none'; // affects polygons and circles
function SvgFormat () { function SvgFormat () {
this.totalRows = 0; this.totalRows = 0;
@ -37,11 +37,11 @@ SvgFormat.prototype.getQuery = function (sql, options) {
'st_xmax(e)-st_xmin(e) as ew, ' + 'st_xmax(e)-st_xmin(e) as ew, ' +
'st_ymax(e)-st_ymin(e) as eh FROM extent )' + 'st_ymax(e)-st_ymin(e) as eh FROM extent )' +
', trans AS ( SELECT CASE WHEN ' + ', trans AS ( SELECT CASE WHEN ' +
'eh = 0 THEN ' + svg_width + 'eh = 0 THEN ' + svgWidth +
'/ COALESCE(NULLIF(ew,0),' + svg_width + ') WHEN ' + '/ COALESCE(NULLIF(ew,0),' + svgWidth + ') WHEN ' +
svg_ratio + ' <= (ew / eh) THEN (' + svgRatio + ' <= (ew / eh) THEN (' +
svg_width + '/ew ) ELSE (' + svgWidth + '/ew ) ELSE (' +
svg_height + '/eh ) END as s ' + svgHeight + '/eh ) END as s ' +
', ex0 as x0, ey0 as y0 FROM extent_info ) ' + ', ex0 as x0, ey0 as y0 FROM extent_info ) ' +
'SELECT st_TransScale(e, -x0, -y0, s, s)::box2d as ' + 'SELECT st_TransScale(e, -x0, -y0, s, s)::box2d as ' +
gn + '_box, ST_Dimension(' + gn + ') as ' + gn + gn + '_box, ST_Dimension(' + gn + ') as ' + gn +
@ -66,7 +66,7 @@ SvgFormat.prototype.startStreaming = function () {
if (this.bbox) { if (this.bbox) {
// expand box by "radius" + "stroke-width" // expand box by "radius" + "stroke-width"
// TODO: use a Box2d class for these ops // TODO: use a Box2d class for these ops
var growby = radius + stroke_width; var growby = radius + strokeWidth;
this.bbox.xmin -= growby; this.bbox.xmin -= growby;
this.bbox.ymin -= growby; this.bbox.ymin -= growby;
this.bbox.xmax += growby; this.bbox.xmax += growby;
@ -76,8 +76,8 @@ SvgFormat.prototype.startStreaming = function () {
rootTag += 'viewBox="' + this.bbox.xmin + ' ' + (-this.bbox.ymax) + ' ' + rootTag += 'viewBox="' + this.bbox.xmin + ' ' + (-this.bbox.ymax) + ' ' +
this.bbox.width + ' ' + this.bbox.height + '" '; this.bbox.width + ' ' + this.bbox.height + '" ';
} }
rootTag += 'style="fill-opacity:' + fill_opacity + '; stroke:' + stroke_color + '; ' + rootTag += 'style="fill-opacity:' + fillOpacity + '; stroke:' + strokeColor + '; ' +
'stroke-width:' + stroke_width + '; fill:' + fill_color + '" '; 'stroke-width:' + strokeWidth + '; fill:' + fillColor + '" ';
rootTag += 'xmlns="http://www.w3.org/2000/svg" version="1.1">\n'; rootTag += 'xmlns="http://www.w3.org/2000/svg" version="1.1">\n';
header.push(rootTag); header.push(rootTag);
@ -87,11 +87,10 @@ SvgFormat.prototype.startStreaming = function () {
this._streamingStarted = true; this._streamingStarted = true;
}; };
// jshint maxcomplexity:11
SvgFormat.prototype.handleQueryRow = function (row) { SvgFormat.prototype.handleQueryRow = function (row) {
this.totalRows++; this.totalRows++;
if (!row.hasOwnProperty(this.opts.gn)) { if (!Object.prototype.hasOwnProperty.call(row, this.opts.gn)) {
this.error = new Error('column "' + this.opts.gn + '" does not exist'); this.error = new Error('column "' + this.opts.gn + '" does not exist');
} }
@ -100,19 +99,17 @@ SvgFormat.prototype.handleQueryRow = function (row) {
return; return;
} // null or empty } // null or empty
// jshint ignore:start
var gdims = row[this.opts.gn + '_dimension']; var gdims = row[this.opts.gn + '_dimension'];
// TODO: add an identifier, if any of "cartodb_id", "oid", "id", "gid" are found // TODO: add an identifier, if any of "cartodb_id", "oid", "id", "gid" are found
// TODO: add "class" attribute to help with styling ? // TODO: add "class" attribute to help with styling ?
if (gdims == '0') { if (gdims === 0) {
this.buffer += '<circle r="' + radius + '" ' + g + ' />\n'; this.buffer += '<circle r="' + radius + '" ' + g + ' />\n';
} else if (gdims == '1') { } else if (gdims === 1) {
// Avoid filling closed linestrings // Avoid filling closed linestrings
this.buffer += '<path ' + (fill_color !== 'none' ? 'fill="none" ' : '') + 'd="' + g + '" />\n'; this.buffer += '<path ' + (fillColor !== 'none' ? 'fill="none" ' : '') + 'd="' + g + '" />\n';
} else if (gdims == '2') { } else if (gdims === 2) {
this.buffer += '<path d="' + g + '" />\n'; this.buffer += '<path d="' + g + '" />\n';
} }
// jshint ignore:end
if (!this.bbox) { if (!this.bbox) {
// Parse layer extent: "BOX(x y, X Y)" // Parse layer extent: "BOX(x y, X Y)"

View File

@ -1,7 +1,5 @@
'use strict'; 'use strict';
// jshint ignore:start
var Pg = require('./../pg'); var Pg = require('./../pg');
var _ = require('underscore'); var _ = require('underscore');
var geojson = require('./geojson'); var geojson = require('./geojson');
@ -55,6 +53,7 @@ TopoJsonFormat.prototype.handleQueryEnd = function () {
var immediately = global.setImmediate || process.nextTick; var immediately = global.setImmediate || process.nextTick;
/* eslint-disable */
function streamObjectSubtree (obj, key, done) { function streamObjectSubtree (obj, key, done) {
buffer += '"' + key + '":'; buffer += '"' + key + '":';
@ -97,6 +96,7 @@ TopoJsonFormat.prototype.handleQueryEnd = function () {
done(); done();
} }
} }
/* eslint-enable */
if (jsonpCallback) { if (jsonpCallback) {
buffer += jsonpCallback + '('; buffer += jsonpCallback + '(';
@ -136,5 +136,3 @@ TopoJsonFormat.prototype.cancel = function () {
}; };
module.exports = TopoJsonFormat; module.exports = TopoJsonFormat;
// jshint ignore:end

View File

@ -15,7 +15,6 @@ process.env.PGAPPNAME = process.env.PGAPPNAME || 'cartodb_sqlapi';
// override Date.toJSON // override Date.toJSON
require('./utils/date-to-json'); require('./utils/date-to-json');
// jshint maxcomplexity:9
module.exports = function createServer (statsClient) { module.exports = function createServer (statsClient) {
const options = getServerOptions(); const options = getServerOptions();
const app = express(); const app = express();

View File

@ -25,7 +25,7 @@ function createTimeoutError () {
' Refactor your query before running again or contact CARTO support for more details.', ' Refactor your query before running again or contact CARTO support for more details.',
context: 'limit', context: 'limit',
detail: 'datasource', detail: 'datasource',
http_status: 429 httpStatus: 429
}); });
} }
@ -35,7 +35,7 @@ function createGenericError (err) {
context: err.context, context: err.context,
detail: err.detail, detail: err.detail,
hint: err.hint, hint: err.hint,
http_status: err.http_status, httpStatus: err.http_status,
name: codeToCondition[err.code] || err.name name: codeToCondition[err.code] || err.name
}); });
} }

View File

@ -1,10 +1,10 @@
'use strict'; 'use strict';
class ErrorHandler extends Error { class ErrorHandler extends Error {
constructor ({ message, context, detail, hint, http_status, name }) { constructor ({ message, context, detail, hint, httpStatus, name }) {
super(message); super(message);
this.http_status = this.getHttpStatus(http_status); this.http_status = this.getHttpStatus(httpStatus);
this.context = context; this.context = context;
this.detail = detail; this.detail = detail;
this.hint = hint; this.hint = hint;
@ -23,12 +23,12 @@ class ErrorHandler extends Error {
}; };
} }
getHttpStatus (http_status = 400) { getHttpStatus (httpStatus = 400) {
if (this.message.includes('permission denied')) { if (this.message.includes('permission denied')) {
return 403; return 403;
} }
return http_status; return httpStatus;
} }
} }

View File

@ -25,16 +25,16 @@ module.exports = {
instance = new StatsD(config); instance = new StatsD(config);
instance.last_error = { msg: '', count: 0 }; instance.last_error = { msg: '', count: 0 };
instance.socket.on('error', function (err) { instance.socket.on('error', function (err) {
var last_err = instance.last_error; var lastErr = instance.last_error;
var last_msg = last_err.msg; var lastMsg = lastErr.msg;
var this_msg = '' + err; var thisMsg = '' + err;
if (this_msg !== last_msg) { if (thisMsg !== lastMsg) {
debug('statsd client socket error: ' + err); debug('statsd client socket error: ' + err);
instance.last_error.count = 1; instance.last_error.count = 1;
instance.last_error.msg = this_msg; instance.last_error.msg = thisMsg;
} else { } else {
++last_err.count; ++lastErr.count;
if (!last_err.interval) { if (!lastErr.interval) {
instance.last_error.interval = setInterval(function () { instance.last_error.interval = setInterval(function () {
var count = instance.last_error.count; var count = instance.last_error.count;
if (count > 1) { if (count > 1) {

View File

@ -1,10 +1,10 @@
'use strict'; 'use strict';
// jshint ignore:start
function pad (n) { function pad (n) {
return n < 10 ? '0' + n : n; return n < 10 ? '0' + n : n;
} }
/* eslint-disable no-extend-native */
Date.prototype.toJSON = function () { Date.prototype.toJSON = function () {
var s = this.getFullYear() + '-' + pad(this.getMonth() + 1) + '-' + pad(this.getDate()) + 'T' + var s = this.getFullYear() + '-' + pad(this.getMonth() + 1) + '-' + pad(this.getDate()) + 'T' +
pad(this.getHours()) + ':' + pad(this.getMinutes()) + ':' + pad(this.getSeconds()); pad(this.getHours()) + ':' + pad(this.getMinutes()) + ':' + pad(this.getSeconds());
@ -16,4 +16,4 @@ Date.prototype.toJSON = function () {
} }
return s; return s;
}; };
// jshint ignore:end /* eslint-enable no-extend-native */

View File

@ -2,8 +2,8 @@
var path = require('path'); var path = require('path');
module.exports = function sanitize_filename (filename) { module.exports = function sanitizeFilename (filename) {
filename = path.basename(filename, path.extname(filename)); filename = path.basename(filename, path.extname(filename));
filename = filename.replace(/[;()\[\]<>'"\s]/g, '_'); filename = filename.replace(/[;()\[\]<>'"\s]/g, '_'); // eslint-disable-line no-useless-escape
return filename; return filename;
}; };

View File

@ -6,14 +6,14 @@ module.exports = {
* from object for logs RegEx * from object for logs RegEx
* *
* @param {Object} object * @param {Object} object
* @param {Number} max_string_length * @param {Number} maxStringLength
*/ */
stringifyForLogs (object, max_string_length = 1024) { stringifyForLogs (object, maxStringLength = 1024) {
return JSON.stringify(cloneAndFilter(object, max_string_length)); return JSON.stringify(cloneAndFilter(object, maxStringLength));
} }
}; };
function cloneAndFilter (object, max_string_length) { function cloneAndFilter (object, maxStringLength) {
if (!object || !(object instanceof Object)) { if (!object || !(object instanceof Object)) {
return null; return null;
} }
@ -22,13 +22,13 @@ function cloneAndFilter (object, max_string_length) {
Object.keys(object).map(key => { Object.keys(object).map(key => {
if (typeof object[key] === 'string') { if (typeof object[key] === 'string') {
newObject[key] = filterString(object[key], max_string_length); newObject[key] = filterString(object[key], maxStringLength);
} else if (typeof object[key] === 'object') { } else if (typeof object[key] === 'object') {
newObject[key] = cloneAndFilter(object[key], max_string_length); newObject[key] = cloneAndFilter(object[key], maxStringLength);
} else if (object[key] instanceof Array) { } else if (object[key] instanceof Array) {
newObject[key] = []; newObject[key] = [];
for (const element of object[key]) { for (const element of object[key]) {
newObject[key].push(cloneAndFilter(element, max_string_length)); newObject[key].push(cloneAndFilter(element, maxStringLength));
} }
} else { } else {
newObject[key] = object[key]; newObject[key] = object[key];
@ -38,8 +38,8 @@ function cloneAndFilter (object, max_string_length) {
return newObject; return newObject;
} }
function filterString (s, max_string_length) { function filterString (s, maxStringLength) {
return s return s
.substring(0, max_string_length) .substring(0, maxStringLength)
.replace(/[^a-zA-Z0-9]/g, ' '); .replace(/[^a-zA-Z0-9]/g, ' ');
} }

View File

@ -41,7 +41,6 @@ describe('results-pagination', function () {
var authorized = 0; var authorized = 0;
var testing = 0; var testing = 0;
var method = 0; var method = 0;
// jshint maxcomplexity:7
var testNext = function () { var testNext = function () {
if (testing >= pr.length) { if (testing >= pr.length) {
if (method + 1 >= methods.length) { if (method + 1 >= methods.length) {

View File

@ -34,7 +34,6 @@ assert.response = function (server, req, res, callback) {
debug('Request definition', req); debug('Request definition', req);
// jshint maxcomplexity:10
function onServerListening () { function onServerListening () {
debug('Server listening on port = %d', port); debug('Server listening on port = %d', port);
var status = res.status || res.statusCode; var status = res.status || res.statusCode;

View File

@ -32,7 +32,7 @@ describe('error-handler-factory', function () {
context: error.context, context: error.context,
detail: error.detail, detail: error.detail,
hint: error.hint, hint: error.hint,
http_status: error.http_status, httpStatus: error.http_status,
name: codeToCondition[error.code] || error.name name: codeToCondition[error.code] || error.name
}); });
@ -48,7 +48,7 @@ describe('error-handler-factory', function () {
' Refactor your query before running again or contact CARTO support for more details.', ' Refactor your query before running again or contact CARTO support for more details.',
context: 'limit', context: 'limit',
detail: 'datasource', detail: 'datasource',
http_status: 429 httpStatus: 429
}); });
assert.deepStrictEqual(errorHandler, expectedError); assert.deepStrictEqual(errorHandler, expectedError);
@ -62,7 +62,7 @@ describe('error-handler-factory', function () {
context: error.context, context: error.context,
detail: error.detail, detail: error.detail,
hint: error.hint, hint: error.hint,
http_status: 403, httpStatus: 403,
name: codeToCondition[error.code] || error.name name: codeToCondition[error.code] || error.name
}); });