From 8ba1d2c5728bf41c663f05063e7b2cfc05421925 Mon Sep 17 00:00:00 2001 From: Sehrope Sarkuni Date: Fri, 10 May 2019 13:23:49 -0400 Subject: [PATCH] Enable eslint:recommended and plugin/node/recommended (#1856) * Fix typo * Enable eslint:recommended and remove unused eslint plugins Enables eslint:recommended by disabling the options that would not pass. Also removes dependencies for included but unused eslint plugins. * Convert console.error(...) calls to use %s placeholders * Enable eslint no-console rule * Add and enable eslint-node-plugin * Correct typo * Enable eslint no-unused-vars --- .eslintrc | 16 ++++++++++++++-- lib/client.js | 6 +++++- lib/connection.js | 4 +++- lib/index.js | 2 ++ lib/native/client.js | 1 + lib/native/query.js | 4 +++- lib/query.js | 1 + lib/sasl.js | 1 + package.json | 4 ---- test/suite.js | 2 +- 10 files changed, 31 insertions(+), 10 deletions(-) diff --git a/.eslintrc b/.eslintrc index 6f96eccc..4a130fab 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,6 +1,18 @@ { - "extends": "standard", + "plugins": [ + "node" + ], + "extends": [ + "eslint:recommended", + "plugin:node/recommended" + ], + "parserOptions": { + "ecmaVersion": 2017 + }, + "env": { + "node": true, + "es6": true + }, "rules": { - "no-new-func": "off" } } diff --git a/lib/client.js b/lib/client.js index 517f5cc1..147637ee 100644 --- a/lib/client.js +++ b/lib/client.js @@ -292,11 +292,13 @@ Client.prototype._attachListeners = function (con) { }) // delegate portalSuspended to active query + // eslint-disable-next-line no-unused-vars con.on('portalSuspended', function (msg) { self.activeQuery.handlePortalSuspended(con) }) - // deletagate emptyQuery to active query + // delegate emptyQuery to active query + // eslint-disable-next-line no-unused-vars con.on('emptyQuery', function (msg) { self.activeQuery.handleEmptyQuery(con) }) @@ -309,12 +311,14 @@ Client.prototype._attachListeners = function (con) { // if a prepared statement has a name and properly parses // we track that its already been executed so we don't parse // it again on the same client + // eslint-disable-next-line no-unused-vars con.on('parseComplete', function (msg) { if (self.activeQuery.name) { con.parsedStatements[self.activeQuery.name] = self.activeQuery.text } }) + // eslint-disable-next-line no-unused-vars con.on('copyInResponse', function (msg) { self.activeQuery.handleCopyInResponse(self.connection) }) diff --git a/lib/connection.js b/lib/connection.js index 1ac2f668..abb6ad6d 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -237,9 +237,11 @@ Connection.prototype.parse = function (query, more) { // normalize missing query names to allow for null query.name = query.name || '' if (query.name.length > 63) { + /* eslint-disable no-console */ console.error('Warning! Postgres only supports 63 characters for query names.') - console.error('You supplied', query.name, '(', query.name.length, ')') + console.error('You supplied %s (%s)', query.name, query.name.length) console.error('This can cause conflicts and silent errors executing queries') + /* eslint-enable no-console */ } // normalize null type array query.types = query.types || [] diff --git a/lib/index.js b/lib/index.js index 00e3ceed..8e000a37 100644 --- a/lib/index.js +++ b/lib/index.js @@ -49,7 +49,9 @@ if (typeof process.env.NODE_PG_FORCE_NATIVE !== 'undefined') { if (err.code !== 'MODULE_NOT_FOUND') { throw err } + /* eslint-disable no-console */ console.error(err.message) + /* eslint-enable no-console */ } module.exports.native = native return native diff --git a/lib/native/client.js b/lib/native/client.js index 5338f7f1..0084d025 100644 --- a/lib/native/client.js +++ b/lib/native/client.js @@ -7,6 +7,7 @@ * README.md file in the root directory of this source tree. */ +// eslint-disable-next-line node/no-missing-require var Native = require('pg-native') var TypeOverrides = require('../type-overrides') var semver = require('semver') diff --git a/lib/native/query.js b/lib/native/query.js index db4eb8cc..74bfb060 100644 --- a/lib/native/query.js +++ b/lib/native/query.js @@ -130,9 +130,11 @@ NativeQuery.prototype.submit = function (client) { // named query if (this.name) { if (this.name.length > 63) { + /* eslint-disable no-console */ console.error('Warning! Postgres only supports 63 characters for query names.') - console.error('You supplied', this.name, '(', this.name.length, ')') + console.error('You supplied %s (%s)', this.name, this.name.length) console.error('This can cause conflicts and silent errors executing queries') + /* eslint-enable no-console */ } var values = (this.values || []).map(utils.prepareValue) diff --git a/lib/query.js b/lib/query.js index 41ed77ea..250e8950 100644 --- a/lib/query.js +++ b/lib/query.js @@ -222,6 +222,7 @@ Query.prototype.handleCopyInResponse = function (connection) { connection.sendCopyFail('No source stream defined') } +// eslint-disable-next-line no-unused-vars Query.prototype.handleCopyData = function (msg, connection) { // noop } diff --git a/lib/sasl.js b/lib/sasl.js index 537ca350..39c24bb3 100644 --- a/lib/sasl.js +++ b/lib/sasl.js @@ -1,3 +1,4 @@ +'use strict' const crypto = require('crypto') function startSession (mechanisms) { diff --git a/package.json b/package.json index e787b048..c7b3ce03 100644 --- a/package.json +++ b/package.json @@ -32,11 +32,7 @@ "bluebird": "3.5.2", "co": "4.6.0", "eslint": "^4.19.1", - "eslint-config-standard": "^11.0.0", - "eslint-plugin-import": "^2.14.0", "eslint-plugin-node": "^6.0.1", - "eslint-plugin-promise": "^4.0.1", - "eslint-plugin-standard": "^3.1.0", "pg-copy-streams": "0.3.0" }, "minNativeVersion": "2.0.0", diff --git a/test/suite.js b/test/suite.js index 72a4fdcb..eca96159 100644 --- a/test/suite.js +++ b/test/suite.js @@ -76,7 +76,7 @@ class Suite { process.on('unhandledRejection', (e) => { setImmediate(() => { - console.error('Uhandled promise rejection') + console.error('Unhandled promise rejection') throw e }) })