Skip to content

Commit 4b93e49

Browse files
authored
Standardise code and fix linter issues (#919)
Fix and apply the configured standard to the code base makes easier for the next changes go through the pipeline without have to mess up with tech debts. This also enables the lint stage be part of test routine, not only in the pre-commit hook (which could be by passed).
1 parent 1cfc700 commit 4b93e49

File tree

169 files changed

+2046
-2012
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+2046
-2012
lines changed

package.json

+6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
"lerna": "lerna",
5050
"prepare": "husky install",
5151
"lint-staged": "lint-staged",
52+
"lint": "npm run lint::core && npm run lint::bolt-connection && npm run lint::bolt-connection && npm run lint::neo4j-driver-lite && npm run lint::neo4j-driver && npm run lint::testkit-backend",
53+
"lint::core": "npm run ts-standard::core -- packages/core/src/ && npm run ts-standard::core -- packages/core/test/",
54+
"lint::bolt-connection": "npm run ts-standard::bolt-connection -- packages/bolt-connection/types/ && npm run standard -- packages/bolt-connection/src/ && npm run standard -- packages/bolt-connection/test/",
55+
"lint::neo4j-driver-lite": "npm run ts-standard::neo4j-driver-lite -- packages/neo4j-driver-lite/src/ && npm run ts-standard::neo4j-driver-lite -- packages/neo4j-driver-lite/test/",
56+
"lint::neo4j-driver": "npm run ts-standard::neo4j-driver -- packages/neo4j-driver/types/ && npm run ts-standard::neo4j-driver -- packages/neo4j-driver/test/types/ && npm run standard -- packages/neo4j-driver/src/ && npm run standard -- packages/neo4j-driver/test/**/*.js",
57+
"lint::testkit-backend": "npm run standard -- packages/testkit-backend/src/**/*.js",
5258
"ts-standard": "npm run ts-standard::core && npm run ts-standard::bolt-connection && npm run ts-standard::neo4j-driver-lite && npm run ts-standard::neo4j-driver",
5359
"ts-standard::core": "ts-standard --fix --project ./packages/core/tsconfig.json",
5460
"ts-standard::bolt-connection": "ts-standard --fix --project ./packages/bolt-connection/tsconfig.json",

packages/bolt-connection/src/bolt/bolt-protocol-util.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* limitations under the License.
1818
*/
1919
import { newError } from 'neo4j-driver-core'
20+
// eslint-disable-next-line no-unused-vars
2021
import { ResultStreamObserver } from './stream-observers'
2122

2223
/**
@@ -59,7 +60,7 @@ function assertDatabaseIsEmpty (database, onProtocolError = () => {}, observer)
5960

6061
/**
6162
* Asserts that the passed-in impersonated user is empty
62-
* @param {string} impersonatedUser
63+
* @param {string} impersonatedUser
6364
* @param {function (err:Error)} onProtocolError Called when it does have impersonated user set
6465
* @param {any} observer
6566
*/

packages/bolt-connection/src/bolt/bolt-protocol-v1.js

+3
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,23 @@ import {
2121
assertTxConfigIsEmpty,
2222
assertImpersonatedUserIsEmpty
2323
} from './bolt-protocol-util'
24+
// eslint-disable-next-line no-unused-vars
2425
import { Chunker } from '../channel'
2526
import { v1 } from '../packstream'
2627
import RequestMessage from './request-message'
2728
import {
2829
LoginObserver,
2930
ResetObserver,
3031
ResultStreamObserver,
32+
// eslint-disable-next-line no-unused-vars
3133
StreamObserver
3234
} from './stream-observers'
3335
import { internal } from 'neo4j-driver-core'
3436

3537
const {
3638
bookmarks: { Bookmarks },
3739
constants: { ACCESS_MODE_WRITE, BOLT_PROTOCOL_V1 },
40+
// eslint-disable-next-line no-unused-vars
3841
logger: { Logger },
3942
txConfig: { TxConfig }
4043
} = internal

packages/bolt-connection/src/bolt/bolt-protocol-v3.js

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
import { internal } from 'neo4j-driver-core'
2929

3030
const {
31+
// eslint-disable-next-line no-unused-vars
3132
bookmarks: { Bookmarks },
3233
constants: { BOLT_PROTOCOL_V3 },
3334
txConfig: { TxConfig }

packages/bolt-connection/src/bolt/bolt-protocol-v4x0.js

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
import { internal } from 'neo4j-driver-core'
2828

2929
const {
30+
// eslint-disable-next-line no-unused-vars
3031
bookmarks: { Bookmarks },
3132
constants: { BOLT_PROTOCOL_V4_0, FETCH_ALL },
3233
txConfig: { TxConfig }

packages/bolt-connection/src/bolt/bolt-protocol-v4x4.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ import { RouteObserver, ResultStreamObserver } from './stream-observers'
2424

2525
const {
2626
constants: { BOLT_PROTOCOL_V4_4, FETCH_ALL },
27-
bookmarks: { Bookmarks },
27+
bookmarks: { Bookmarks }
2828
} = internal
2929

3030
export default class BoltProtocol extends BoltProtocolV43 {
31-
get version() {
31+
get version () {
3232
return BOLT_PROTOCOL_V4_4
3333
}
3434

@@ -153,5 +153,4 @@ export default class BoltProtocol extends BoltProtocolV43 {
153153

154154
return observer
155155
}
156-
157156
}

packages/bolt-connection/src/bolt/bolt-protocol-v5x0.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import { v5 } from '../packstream'
2222
import { internal } from 'neo4j-driver-core'
2323

2424
const {
25-
constants: { BOLT_PROTOCOL_V5_0 },
25+
constants: { BOLT_PROTOCOL_V5_0 }
2626
} = internal
2727

2828
export default class BoltProtocol extends BoltProtocolV44 {
29-
get version() {
29+
get version () {
3030
return BOLT_PROTOCOL_V5_0
3131
}
3232

packages/bolt-connection/src/bolt/create.js

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import BoltProtocolV4x2 from './bolt-protocol-v4x2'
2727
import BoltProtocolV4x3 from './bolt-protocol-v4x3'
2828
import BoltProtocolV4x4 from './bolt-protocol-v4x4'
2929
import BoltProtocolV5x0 from './bolt-protocol-v5x0'
30+
// eslint-disable-next-line no-unused-vars
3031
import { Chunker, Dechunker } from '../channel'
3132
import ResponseHandler from './response-handler'
3233

packages/bolt-connection/src/bolt/request-message.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,14 @@ export default class RequestMessage {
250250
* @param {string} databaseContext.impersonatedUser The name of the user to impersonation when getting the routing table.
251251
* @return {RequestMessage} the ROUTE message.
252252
*/
253-
static routeV4x4 (routingContext = {}, bookmarks = [], databaseContext = {}) {
253+
static routeV4x4 (routingContext = {}, bookmarks = [], databaseContext = {}) {
254254
const dbContext = {}
255255

256-
if ( databaseContext.databaseName ) {
256+
if (databaseContext.databaseName) {
257257
dbContext.db = databaseContext.databaseName
258258
}
259259

260-
if ( databaseContext.impersonatedUser ) {
260+
if (databaseContext.impersonatedUser) {
261261
dbContext.imp_user = databaseContext.impersonatedUser
262262
}
263263

packages/bolt-connection/src/bolt/response-handler.js

-1
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,4 @@ export default class ResponseHandler {
193193
_resetFailure () {
194194
this._currentFailure = null
195195
}
196-
197196
}

packages/bolt-connection/src/bolt/routing-table-raw.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19+
// eslint-disable-next-line no-unused-vars
1920
import Record from 'neo4j-driver-core'
2021

2122
/**

packages/bolt-connection/src/bolt/stream-observers.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,25 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
import { newError, error, Integer, Record, json, internal } from 'neo4j-driver-core'
19+
import {
20+
newError,
21+
error,
22+
// eslint-disable-next-line no-unused-vars
23+
Integer,
24+
Record,
25+
json,
26+
internal
27+
} from 'neo4j-driver-core'
2028
import RawRoutingTable from './routing-table-raw'
2129

2230
const {
23-
constants: { FETCH_ALL },
31+
constants: { FETCH_ALL }
2432
} = internal
2533
const { PROTOCOL_ERROR } = error
2634
class StreamObserver {
2735
onNext (rawRecord) {}
2836

29-
onError (error) {}
37+
onError (_error) {}
3038

3139
onCompleted (meta) {}
3240
}
@@ -100,7 +108,7 @@ class ResultStreamObserver extends StreamObserver {
100108
this._highRecordWatermark = highRecordWatermark
101109
this._setState(reactive ? _states.READY : _states.READY_STREAMING)
102110
this._setupAutoPull()
103-
this._paused = false;
111+
this._paused = false
104112
}
105113

106114
/**
@@ -643,7 +651,7 @@ const _states = {
643651
pull: () => {}
644652
},
645653
FAILED: {
646-
onError: error => {
654+
onError: _error => {
647655
// more errors are ignored
648656
},
649657
name: () => {

packages/bolt-connection/src/channel/browser/browser-channel.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
19+
/* eslint-env browser */
2020
import ChannelBuffer from '../channel-buf'
2121
import { newError, internal } from 'neo4j-driver-core'
2222

@@ -26,8 +26,10 @@ const {
2626

2727
// Just to be sure that these values are with us even after WebSocket is injected
2828
// for tests.
29+
// eslint-disable-next-line no-unused-vars
2930
const WS_CONNECTING = 0
3031
const WS_OPEN = 1
32+
// eslint-disable-next-line no-unused-vars
3133
const WS_CLOSING = 2
3234
const WS_CLOSED = 3
3335

@@ -184,7 +186,7 @@ export default class WebSocketChannel {
184186
/**
185187
* Stops the receive timeout for the channel.
186188
*/
187-
stopReceiveTimeout() {
189+
stopReceiveTimeout () {
188190
}
189191

190192
/**
@@ -265,7 +267,7 @@ function isIPv6Address (hostAndPort) {
265267

266268
function asWindowsFriendlyIPv6Address (scheme, address) {
267269
// replace all ':' with '-'
268-
const hostWithoutColons = address.host().replace(new RegExp(':', 'g'), '-')
270+
const hostWithoutColons = address.host().replace(/:/g, '-')
269271

270272
// replace '%' with 's' for link-local IPv6 address like 'fe80::1%lo0'
271273
const hostWithoutPercent = hostWithoutColons.replace('%', 's')

packages/bolt-connection/src/channel/channel-buf.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,14 @@ export default class ChannelBuffer extends BaseBuffer {
7676

7777
/**
7878
* Allocate a buffer
79-
*
79+
*
8080
* @param {number} size The buffer sizzer
8181
* @returns {BaseBuffer} The buffer
8282
*/
8383
export function alloc (size) {
8484
return new ChannelBuffer(size)
8585
}
8686

87-
8887
function newChannelJSBuffer (arg) {
8988
if (arg instanceof buffer.Buffer) {
9089
return arg

packages/bolt-connection/src/channel/channel-config.js

-1
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,3 @@ function extractTrustedCertificates (driverConfig) {
8787
function extractKnownHostsPath (driverConfig) {
8888
return driverConfig.knownHosts || null
8989
}
90-

packages/bolt-connection/src/channel/node/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,3 @@ NOTE: exports in this module should have exactly the same names/structure as exp
3333

3434
export const Channel = NodeChannel
3535
export const HostNameResolver = NodeHostNameResolver
36-

packages/bolt-connection/src/channel/node/node-channel.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ export default class NodeChannel {
361361
/**
362362
* Stops the receive timeout for the channel.
363363
*/
364-
stopReceiveTimeout() {
364+
stopReceiveTimeout () {
365365
if (this._receiveTimeout !== null && this._receiveTimeoutStarted) {
366366
this._receiveTimeoutStarted = false
367367
this._conn.setTimeout(0)

packages/bolt-connection/src/connection-provider/connection-provider-direct.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const {
2929
constants: { BOLT_PROTOCOL_V3, BOLT_PROTOCOL_V4_0, BOLT_PROTOCOL_V4_4 }
3030
} = internal
3131

32-
const { SERVICE_UNAVAILABLE, newError } = error
32+
const { SERVICE_UNAVAILABLE } = error
3333

3434
export default class DirectConnectionProvider extends PooledConnectionProvider {
3535
constructor ({ id, config, log, address, userAgent, authToken }) {

packages/bolt-connection/src/connection-provider/connection-provider-routing.js

+13-15
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,12 @@ const {
4141
}
4242
} = internal
4343

44-
4544
const PROCEDURE_NOT_FOUND_CODE = 'Neo.ClientError.Procedure.ProcedureNotFound'
4645
const DATABASE_NOT_FOUND_CODE = 'Neo.ClientError.Database.DatabaseNotFound'
4746
const INVALID_BOOKMARK_CODE = 'Neo.ClientError.Transaction.InvalidBookmark'
48-
const INVALID_BOOKMARK_MIXTURE_CODE =
47+
const INVALID_BOOKMARK_MIXTURE_CODE =
4948
'Neo.ClientError.Transaction.InvalidBookmarkMixture'
50-
const AUTHORIZATION_EXPIRED_CODE =
49+
const AUTHORIZATION_EXPIRED_CODE =
5150
'Neo.ClientError.Security.AuthorizationExpired'
5251

5352
const SYSTEM_DB_NAME = 'system'
@@ -257,7 +256,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
257256
})
258257

259258
const servers = accessMode === WRITE ? routingTable.writers : routingTable.readers
260-
259+
261260
let error = newError(
262261
`No servers available for database '${context.database}' with access mode '${accessMode}'`,
263262
SERVICE_UNAVAILABLE
@@ -285,7 +284,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
285284
}
286285

287286
forgetWriter (address, database) {
288-
this._routingTableRegistry.apply( database, {
287+
this._routingTableRegistry.apply(database, {
289288
applyWhenExists: routingTable => routingTable.forgetWriter(address)
290289
})
291290
}
@@ -510,7 +509,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
510509
errorCode: SESSION_EXPIRED,
511510
handleAuthorizationExpired: (error, address) => this._handleAuthorizationExpired(error, address)
512511
})
513-
512+
514513
const connectionProvider = new SingleConnectionProvider(
515514
new DelegateConnection(connection, databaseSpecificErrorHandler))
516515

@@ -535,7 +534,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
535534
}
536535
}
537536

538-
_handleRediscoveryError(error, routerAddress) {
537+
_handleRediscoveryError (error, routerAddress) {
539538
if (_isFailFastError(error) || _isFailFastSecurityError(error)) {
540539
throw error
541540
} else if (error.code === PROCEDURE_NOT_FOUND_CODE) {
@@ -578,9 +577,9 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
578577
this._routingTableRegistry.register(
579578
newRoutingTable
580579
)
581-
580+
582581
onDatabaseNameResolved(newRoutingTable.database)
583-
582+
584583
this._log.info(`Updated routing table ${newRoutingTable}`)
585584
}
586585

@@ -639,14 +638,14 @@ class RoutingTableRegistry {
639638

640639
/**
641640
* Retrieves a routing table from a given database name
642-
*
641+
*
643642
* @param {string|impersonatedUser} impersonatedUser The impersonated User
644643
* @param {string} database The database name
645644
* @param {function()|RoutingTable} defaultSupplier The routing table supplier, if it's not a function or not exists, it will return itself as default value
646645
* @returns {RoutingTable} The routing table for the respective database
647646
*/
648647
get (database, defaultSupplier) {
649-
if (this._tables.has(database) ) {
648+
if (this._tables.has(database)) {
650649
return this._tables.get(database)
651650
}
652651
return typeof defaultSupplier === 'function'
@@ -690,14 +689,13 @@ function _isFailFastError (error) {
690689
return [
691690
DATABASE_NOT_FOUND_CODE,
692691
INVALID_BOOKMARK_CODE,
693-
INVALID_BOOKMARK_MIXTURE_CODE,
692+
INVALID_BOOKMARK_MIXTURE_CODE
694693
].includes(error.code)
695694
}
696695

697696
function _isFailFastSecurityError (error) {
698-
return error.code.startsWith('Neo.ClientError.Security.') &&
697+
return error.code.startsWith('Neo.ClientError.Security.') &&
699698
![
700-
AUTHORIZATION_EXPIRED_CODE,
699+
AUTHORIZATION_EXPIRED_CODE
701700
].includes(error.code)
702701
}
703-

packages/bolt-connection/src/connection/connection-channel.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ export default class ChannelConnection extends Connection {
355355
* Starts and stops the receive timeout timer.
356356
* @param {number} requestsNumber Ongoing requests number
357357
*/
358-
_handleOngoingRequestsNumberChange(requestsNumber) {
358+
_handleOngoingRequestsNumberChange (requestsNumber) {
359359
if (requestsNumber === 0) {
360360
this._ch.stopReceiveTimeout()
361361
} else {

packages/bolt-connection/src/connection/connection-error-handler.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ export default class ConnectionErrorHandler {
7777
}
7878

7979
function isAutorizationExpiredError (error) {
80-
return error && (
81-
error.code === 'Neo.ClientError.Security.AuthorizationExpired' ||
80+
return error && (
81+
error.code === 'Neo.ClientError.Security.AuthorizationExpired' ||
8282
error.code === 'Neo.ClientError.Security.TokenExpired'
8383
)
8484
}

0 commit comments

Comments
 (0)