Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
Apply automatic ESLint fixes in backend/ directory
Browse files Browse the repository at this point in the history
- Thereby properly configure ESLint `quotes` rule
- Disable ESLint in code where auto-fixing would be applicable but not
  wise from a maintainability point of view
  • Loading branch information
rmoestl committed Oct 30, 2017
1 parent d65738f commit 9e442db
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 44 deletions.
6 changes: 4 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"yoda": [2],
"key-spacing": [1],
"max-len": ["error", 120, 4, {
"ignoreUrls": true
ignoreUrls: true
}],
"new-cap": [0],
"no-shadow": [1],
Expand All @@ -92,7 +92,9 @@
"no-unused-vars": [1],
"no-use-before-define": [2, "nofunc"],
"semi": [2, "always"],
"quotes": [2, "single", "avoid-escape"],
"quotes": [2, "single", {
avoidEscape: true
}],
"valid-jsdoc": [1],
"react/jsx-closing-bracket-location": [1, "line-aligned"],
"jsx-quotes": [2, "prefer-double"],
Expand Down
2 changes: 1 addition & 1 deletion backend/certificates.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function fetchCertsFromCA() {
));
}).then((res) => {
if (res.status !== 201) {
let errorMessage = `An error occured requesting certificates from the CA, ` +
let errorMessage = 'An error occured requesting certificates from the CA, ' +
`status ${res.status} was returned.`;
res.json().then(json => {
errorMessage += `JSON response was: ${JSON.stringify(json)}`;
Expand Down
8 changes: 6 additions & 2 deletions backend/persistent/datastores/Sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ export function tables(connection) {
export function schemas(connection) {
const {database, dialect} = connection;

// Suppressing ESLint cause single quote strings beside template strings
// would be inconvenient when changed queries
/* eslint-disable quotes */
let queryString;
switch (dialect) {
case DIALECTS.MYSQL:
Expand All @@ -171,7 +174,7 @@ export function schemas(connection) {
`WHERE table_catalog = '${database}' AND table_schema = 'public' ORDER BY table_name`;
break;
case DIALECTS.REDSHIFT:
queryString = `SELECT tablename, "column", "type" FROM pg_table_def WHERE schemaname = 'public';`
queryString = `SELECT tablename, "column", "type" FROM pg_table_def WHERE schemaname = 'public';`;
break;
case DIALECTS.MSSQL:
queryString =
Expand All @@ -181,11 +184,12 @@ export function schemas(connection) {
`FROM sys.objects AS T ` +
` JOIN sys.columns AS C ON T.object_id = C.object_id ` +
` JOIN sys.types AS P ON C.system_type_id = P.system_type_id ` +
`WHERE T.type_desc = 'USER_TABLE';`
`WHERE T.type_desc = 'USER_TABLE';`;
break;
default:
throw new Error(`Dialect ${dialect} is not one of the SQL DIALECTS`);
}
/* eslint-enable quotes */

return query(queryString, connection);
}
2 changes: 1 addition & 1 deletion backend/persistent/datastores/ibmdb2.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function tables(connection) {

export function schemas(connection) {
return query(
`SELECT TABNAME, COLNAME, TYPENAME FROM syscat.columns WHERE SUBSTR(TABSCHEMA,1,3) != 'SYS'`,
"SELECT TABNAME, COLNAME, TYPENAME FROM syscat.columns WHERE SUBSTR(TABSCHEMA,1,3) != 'SYS'",
connection
);
}
4 changes: 2 additions & 2 deletions backend/persistent/datastores/impala.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function tables(connection) {
}

export function schemas(connection) {
let columnnames = ['tablename', 'column_name', 'data_type'];
const columnnames = ['tablename', 'column_name', 'data_type'];
const showTables = (connection.database) ?
`show tables in ${connection.database}` :
'show tables';
Expand Down Expand Up @@ -88,6 +88,6 @@ export function query(query, connection) {
return {columnnames, rows};
}).catch(err => {
Logger.log(err);
throw new Error(err)
throw new Error(err);
});
}
4 changes: 2 additions & 2 deletions backend/persistent/datastores/livy.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ export function tables(connection) {
export function schemas(connection) {
const showTables = (connection.database) ?
`"show tables in ${connection.database}"` :
`"show tables"`;
'"show tables"';
const describeTable = (connection.database) ?
`"describe ${connection.database}."` :
`"describe "`;
'"describe "';
// Supressed ESLint cause comlex expression is easier to maintain this way
// eslint-disable-next-line max-len
const expression = `plotlyContext.sql(${showTables}).select("tableName").collect().map(tn => plotlyContext.sql(${describeTable} + tn(0)).withColumn("tableName", lit(tn(0).toString)).select("tableName", "col_name", "data_type")).reduce((l,r)=>l.union(r))`;
Expand Down
28 changes: 12 additions & 16 deletions backend/plugins/authorization.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,25 @@ export function PlotlyOAuth(electron) {
headers: {'Authorization': `Bearer ${plotlyAuthToken}`}
})
.then(userRes => userRes.json().then(userMeta => {

if (userRes.status !== 200) {
res.json(401, {error: {message: 'Please login to access this page.'}});
return;
} else {
if (!contains(userMeta.username, getSetting('ALLOWED_USERS'))) {

// Remove any existing credentials and return error
res.clearCookie('db-connector-auth-token');
res.clearCookie('plotly-auth-token');
res.clearCookie('db-connector-user');
res.json(403, {error: {message: `User ${userMeta.username} is not allowed to view this app`}});
return;
}

} else {
if (!contains(userMeta.username, getSetting('ALLOWED_USERS'))) {

const dbConnectorAccessToken = generateAndSaveAccessToken();
res.setCookie('db-connector-auth-token',
dbConnectorAccessToken, getAccessTokenCookieOptions());
return (next());
}
// Remove any existing credentials and return error
res.clearCookie('db-connector-auth-token');
res.clearCookie('plotly-auth-token');
res.clearCookie('db-connector-user');
res.json(403, {error: {message: `User ${userMeta.username} is not allowed to view this app`}});
return;
}

const dbConnectorAccessToken = generateAndSaveAccessToken();
res.setCookie('db-connector-auth-token',
dbConnectorAccessToken, getAccessTokenCookieOptions());
return (next());
}))
.catch(err => {
Logger.log(err, 0);
Expand Down
37 changes: 19 additions & 18 deletions backend/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,26 +370,27 @@ export default class Servers {
if (connectionsOnFile) {
res.send(409, {connectionId: connectionsOnFile.id});
return;
} else {
}

// Check that the connections are valid
const connectionObject = req.params;
validateConnection(req.params).then(validation => {
if (isEmpty(validation)) {
res.json(200, {connectionId: saveConnection(req.params)});
return;
} else {
Logger.log(validation, 2);
res.json(400, {error: {message: validation.message}
});
return;
}
}).catch(err => {
Logger.log(err, 2);
res.json(400, {error: {message: err.message}
});
// Check that the connections are valid
const connectionObject = req.params;
validateConnection(req.params).then(validation => {
if (isEmpty(validation)) {
res.json(200, {connectionId: saveConnection(req.params)});
return;
}

Logger.log(validation, 2);
res.json(400, {
error: {message: validation.message}
});
}
return;
}).catch(err => {
Logger.log(err, 2);
res.json(400, {
error: {message: err.message}
});
});
});

// return sanitized connections
Expand Down

0 comments on commit 9e442db

Please sign in to comment.