Skip to content

Commit 382c6fc

Browse files
committed
test: Constrain eslint rules
Instead of disabling import/no-extraneous-dependencies and import/no-unresolved globally, constrain them to the specific instances where they are needed using eslint comments. In addition, explain why the no-console error must be disabled.
1 parent b1f3818 commit 382c6fc

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

.eslintrc.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ module.exports = {
55
},
66
rules: {
77
// Tweak rules set by airbnb config
8-
'no-console': 'off', // allow console
9-
'import/no-extraneous-dependencies': ["error", {"optionalDependencies": true}], // Allow optional dep import
10-
// Warn unresolved imports ie: idb-connector import will be unresolved when on non IBM i system.
11-
'import/no-unresolved': ['off', { commonjs: true }],
8+
// We need to allow use of console.log for verbose mode
9+
'no-console': 'off',
1210
},
1311
};

lib/transports/idbTransport.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
const idbCall = (config, xmlInput, cb) => {
1919
const {
2020
dbconn, dbstmt, IN, CLOB, CHAR, SQL_ATTR_DBC_SYS_NAMING, SQL_FALSE,
21-
// eslint-disable-next-line global-require
21+
// idb-connector is an optional dependency, since users may not use this transport
22+
// thus we can't globally require it
23+
// eslint-disable-next-line max-len
24+
// eslint-disable-next-line global-require, import/no-extraneous-dependencies, import/no-unresolved
2225
} = require('idb-connector');
2326

2427
const {

lib/transports/odbcTransport.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1717

1818
function odbcCall(config, xmlInput, done) {
19-
// eslint-disable-next-line global-require
19+
// odbc is an optional dependency, since users may not use this transport
20+
// eslint-disable-next-line global-require, import/no-extraneous-dependencies
2021
const odbc = require('odbc');
2122

2223
const {

lib/transports/sshTransport.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1717

1818
function sshCall(config, xmlIn, done) {
19-
// eslint-disable-next-line global-require
19+
// ssh2 is an optional dependency, since users may not use this transport
20+
// eslint-disable-next-line global-require, import/no-extraneous-dependencies
2021
const { Client } = require('ssh2');
2122

2223
const {

test/functional/checkObjectExists.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ const createLib = `CRTLIB LIB(${lib}) TYPE(*TEST) TEXT('Used to test Node.js too
33
const findLib = `SELECT SCHEMA_NAME FROM qsys2.sysschemas WHERE SCHEMA_NAME = '${lib}'`;
44

55
function checkObjectExistsSSH(config, object = {}, callback) {
6-
/* eslint-disable global-require */
6+
// ssh2 is an optional dependency, since users may not use this transport
7+
// thus we can't globally require it
8+
// eslint-disable-next-line global-require, import/no-extraneous-dependencies
79
const { Client } = require('ssh2');
810

911
const client = new Client();
@@ -68,6 +70,9 @@ function checkObjectExistsSSH(config, object = {}, callback) {
6870
}
6971

7072
function checkObjectExistsODBC(config, object = {}, callback) {
73+
// odbc is an optional dependency, since users may not use this transport
74+
// thus we can't globally require it
75+
// eslint-disable-next-line global-require, import/no-extraneous-dependencies
7176
const odbc = require('odbc');
7277

7378
const connectionString = config.dsn || `DRIVER=IBM i Access ODBC Driver;SYSTEM=${config.host};UID=${config.username};PWD=${config.password};`;
@@ -110,6 +115,10 @@ function checkObjectExistsODBC(config, object = {}, callback) {
110115
}
111116

112117
function checkObjectExistsIDB(config, object = {}, callback) {
118+
// idb-connector is an optional dependency, since users may not use this transport
119+
// thus we can't globally require it
120+
// eslint-disable-next-line max-len
121+
// eslint-disable-next-line global-require, import/no-extraneous-dependencies, import/no-unresolved
113122
const { dbconn, dbstmt } = require('idb-connector');
114123

115124
/* eslint-disable new-cap */

0 commit comments

Comments
 (0)