Skip to content

Commit 89e67e6

Browse files
authored
Merge pull request #288 from IBM/eslint-mocha
test: Configure eslint properly for Mocha tests
2 parents b1f3818 + 63ccb9d commit 89e67e6

32 files changed

+81
-42
lines changed

.eslintrc.js

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
1-
module.exports = {
2-
"extends": "airbnb-base",
3-
env: {
4-
node: true
5-
},
6-
rules: {
7-
// 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 }],
1+
module.exports = {
2+
extends: 'airbnb-base',
3+
plugins: [
4+
'mocha',
5+
],
6+
env: {
7+
node: true,
8+
},
9+
rules: {
10+
// Tweak rules set by airbnb config
11+
// We need to allow use of console.log for verbose mode
12+
'no-console': 'off',
13+
},
14+
overrides: [
15+
{
16+
files: ['test/**/*.js'],
17+
env: {
18+
node: true,
19+
mocha: true,
20+
},
21+
extends: 'plugin:mocha/recommended',
22+
rules: {
23+
// These are set by airbnb-base, but go against Mocha conventions
24+
// See https://mochajs.org/#arrow-functions
25+
// and https://github.com/airbnb/javascript/issues/433
26+
'func-names': 'off',
27+
'prefer-arrow-callback': 'off',
28+
29+
// The following rules cause problems for our existing tests, so they are disabled for now:
30+
'mocha/no-mocha-arrows': 'off',
31+
'mocha/no-skipped-tests': 'off',
32+
'mocha/no-hooks-for-single-case': 'off',
33+
'mocha/no-identical-title': 'off',
1234
},
35+
},
36+
],
1337
};

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 {

package-lock.json

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"eslint": "^6.2.0",
4949
"eslint-config-airbnb-base": "^14.0.0",
5050
"eslint-plugin-import": "^2.18.2",
51+
"eslint-plugin-mocha": "^7.0.1",
5152
"mocha": "^6.2.3",
5253
"sinon": "^7.4.1",
5354
"standard-version": "^7.0.0"

test/functional/CommandCallFunctional.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1616
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1717

18-
/* eslint-env mocha */
19-
2018
const { expect } = require('chai');
2119
const { parseString } = require('xml2js');
2220
const { CommandCall, Connection } = require('../../lib/itoolkit');

test/functional/ProgramCallFunctional.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1616
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1717

18-
/* eslint-env mocha */
1918

2019
const { expect } = require('chai');
2120
const { parseString } = require('xml2js');

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 */

test/functional/deprecated/commandsFunctional.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1616
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1717

18-
/* eslint-env mocha */
1918
/* eslint-disable new-cap */
2019

2120

0 commit comments

Comments
 (0)