Skip to content

Commit

Permalink
Upgrade eslint and scality config, and fix lint problems
Browse files Browse the repository at this point in the history
Issue: BKTCLT-33
  • Loading branch information
KillianG committed Nov 4, 2024
1 parent 0182438 commit 0b9dc9c
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 98 deletions.
13 changes: 13 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});
export default [...compat.extends("scality")];
18 changes: 9 additions & 9 deletions lib/RESTClient.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict'; // eslint-disable-line strict
'use strict';

const assert = require('assert');
const http = require('http');
Expand Down Expand Up @@ -351,9 +351,9 @@ class RESTClient {
ret.push(data);
retLen += data.length;
}).on('error', callback)
.on('end', () => {
callback(null, Buffer.concat(ret, retLen).toString());
});
.on('end', () => {
callback(null, Buffer.concat(ret, retLen).toString());
});
return undefined;
});
}
Expand Down Expand Up @@ -421,11 +421,11 @@ class RESTClient {
}

req.on('response', res => this.endRespond(res, res, log, callback))
.on('error', error => {
// covers system errors like ECONNREFUSED, ECONNRESET etc.
log.error('error sending request to metadata', { error });
callback(errors.InternalError);
}).end();
.on('error', error => {
// covers system errors like ECONNREFUSED, ECONNRESET etc.
log.error('error sending request to metadata', { error });
callback(errors.InternalError);
}).end();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/shell.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict'; // eslint-disable-line strict
'use strict';

const readline = require('readline');

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"devDependencies": {
"eslint": "^9.14.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-scality": "scality/Guidelines#ec33dfb",
"eslint-config-scality": "scality/Guidelines#8.3.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-react": "7.37.2",
"mocha": "10.8.2"
},
Expand Down
54 changes: 27 additions & 27 deletions tests/functional/client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict'; // eslint-disable-line strict
'use strict';

const assert = require('assert');

Expand All @@ -18,7 +18,7 @@ describe('Bucket Client tests', function testClient() {

it('should create a new bucket', done => {
client.createBucket(bucketName, reqUids,
JSON.stringify(bucketAttributes), done);
JSON.stringify(bucketAttributes), done);
});

it('should try to create the same bucket and fail', done => {
Expand Down Expand Up @@ -90,31 +90,31 @@ describe('Bucket Client tests', function testClient() {
dataBufs.push(data);
dataLen += data.length;
}).on('error', done)
.on('end', () => {
const data = Buffer.concat(dataBufs, dataLen).toString();
const obj = JSON.parse(data);
assert.strictEqual(Object.prototype.hasOwnProperty.call(
obj, 'info'), true);
const info = obj.info;
assert.strictEqual(['start', 'end', 'cseq', 'prune']
.every(key => Object.prototype.hasOwnProperty.call(
obj.info, key)), true);
assert.strictEqual(info.start >= start, true);
assert.strictEqual(info.end <= end, true);
// NOTE: this check will be removed when pruned logs are
// retrieved also
assert.strictEqual(info.prune <= info.start, true);
assert.strictEqual(info.cseq >= info.end, true);
assert.strictEqual(Object.prototype.hasOwnProperty.call(
obj, 'log'), true);
const logs = obj.log;
assert.strictEqual(Array.isArray(logs), true);
assert.strictEqual(logs.length >= 1, true);
assert.strictEqual(logs.every(log =>
(typeof log === 'object') && (Object.keys(log).length > 0)
), true);
return done();
});
.on('end', () => {
const data = Buffer.concat(dataBufs, dataLen).toString();
const obj = JSON.parse(data);
assert.strictEqual(Object.prototype.hasOwnProperty.call(
obj, 'info'), true);
const info = obj.info;
assert.strictEqual(['start', 'end', 'cseq', 'prune']
.every(key => Object.prototype.hasOwnProperty.call(
obj.info, key)), true);
assert.strictEqual(info.start >= start, true);
assert.strictEqual(info.end <= end, true);
// NOTE: this check will be removed when pruned logs are
// retrieved also
assert.strictEqual(info.prune <= info.start, true);
assert.strictEqual(info.cseq >= info.end, true);
assert.strictEqual(Object.prototype.hasOwnProperty.call(
obj, 'log'), true);
const logs = obj.log;
assert.strictEqual(Array.isArray(logs), true);
assert.strictEqual(logs.length >= 1, true);
assert.strictEqual(logs.every(log =>
(typeof log === 'object') && (Object.keys(log).length > 0)
), true);
return done();
});
return undefined;
});
});
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/simple_tests.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict'; // eslint-disable-line strict
'use strict';

const assert = require('assert');
const fs = require('fs');
Expand Down Expand Up @@ -54,11 +54,11 @@ const env = {
https: {
s: handler => https.createServer(httpsOptions, handler),
c: new RESTClient(['bucketclient.testing.local:9000'],
undefined,
true,
httpsOptions.key,
httpsOptions.cert,
httpsOptions.ca[0]),
undefined,
true,
httpsOptions.key,
httpsOptions.cert,
httpsOptions.ca[0]),
},
};

Expand Down
Loading

0 comments on commit 0b9dc9c

Please sign in to comment.