Skip to content

Standardise code and fix linter issues #919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 20, 2022
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
"lerna": "lerna",
"prepare": "husky install",
"lint-staged": "lint-staged",
"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",
"lint::core": "npm run ts-standard::core -- packages/core/src/ && npm run ts-standard::core -- packages/core/test/",
"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/",
"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/",
"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",
"lint::testkit-backend": "npm run standard -- packages/testkit-backend/src/**/*.js",
"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",
"ts-standard::core": "ts-standard --fix --project ./packages/core/tsconfig.json",
"ts-standard::bolt-connection": "ts-standard --fix --project ./packages/bolt-connection/tsconfig.json",
Expand Down
3 changes: 2 additions & 1 deletion packages/bolt-connection/src/bolt/bolt-protocol-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* limitations under the License.
*/
import { newError } from 'neo4j-driver-core'
// eslint-disable-next-line no-unused-vars
import { ResultStreamObserver } from './stream-observers'

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

/**
* Asserts that the passed-in impersonated user is empty
* @param {string} impersonatedUser
* @param {string} impersonatedUser
* @param {function (err:Error)} onProtocolError Called when it does have impersonated user set
* @param {any} observer
*/
Expand Down
3 changes: 3 additions & 0 deletions packages/bolt-connection/src/bolt/bolt-protocol-v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@ import {
assertTxConfigIsEmpty,
assertImpersonatedUserIsEmpty
} from './bolt-protocol-util'
// eslint-disable-next-line no-unused-vars
import { Chunker } from '../channel'
import { v1 } from '../packstream'
import RequestMessage from './request-message'
import {
LoginObserver,
ResetObserver,
ResultStreamObserver,
// eslint-disable-next-line no-unused-vars
StreamObserver
} from './stream-observers'
import { internal } from 'neo4j-driver-core'

const {
bookmarks: { Bookmarks },
constants: { ACCESS_MODE_WRITE, BOLT_PROTOCOL_V1 },
// eslint-disable-next-line no-unused-vars
logger: { Logger },
txConfig: { TxConfig }
} = internal
Expand Down
1 change: 1 addition & 0 deletions packages/bolt-connection/src/bolt/bolt-protocol-v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
import { internal } from 'neo4j-driver-core'

const {
// eslint-disable-next-line no-unused-vars
bookmarks: { Bookmarks },
constants: { BOLT_PROTOCOL_V3 },
txConfig: { TxConfig }
Expand Down
1 change: 1 addition & 0 deletions packages/bolt-connection/src/bolt/bolt-protocol-v4x0.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
import { internal } from 'neo4j-driver-core'

const {
// eslint-disable-next-line no-unused-vars
bookmarks: { Bookmarks },
constants: { BOLT_PROTOCOL_V4_0, FETCH_ALL },
txConfig: { TxConfig }
Expand Down
5 changes: 2 additions & 3 deletions packages/bolt-connection/src/bolt/bolt-protocol-v4x4.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import { RouteObserver, ResultStreamObserver } from './stream-observers'

const {
constants: { BOLT_PROTOCOL_V4_4, FETCH_ALL },
bookmarks: { Bookmarks },
bookmarks: { Bookmarks }
} = internal

export default class BoltProtocol extends BoltProtocolV43 {
get version() {
get version () {
return BOLT_PROTOCOL_V4_4
}

Expand Down Expand Up @@ -153,5 +153,4 @@ export default class BoltProtocol extends BoltProtocolV43 {

return observer
}

}
4 changes: 2 additions & 2 deletions packages/bolt-connection/src/bolt/bolt-protocol-v5x0.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import { v5 } from '../packstream'
import { internal } from 'neo4j-driver-core'

const {
constants: { BOLT_PROTOCOL_V5_0 },
constants: { BOLT_PROTOCOL_V5_0 }
} = internal

export default class BoltProtocol extends BoltProtocolV44 {
get version() {
get version () {
return BOLT_PROTOCOL_V5_0
}

Expand Down
1 change: 1 addition & 0 deletions packages/bolt-connection/src/bolt/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import BoltProtocolV4x2 from './bolt-protocol-v4x2'
import BoltProtocolV4x3 from './bolt-protocol-v4x3'
import BoltProtocolV4x4 from './bolt-protocol-v4x4'
import BoltProtocolV5x0 from './bolt-protocol-v5x0'
// eslint-disable-next-line no-unused-vars
import { Chunker, Dechunker } from '../channel'
import ResponseHandler from './response-handler'

Expand Down
6 changes: 3 additions & 3 deletions packages/bolt-connection/src/bolt/request-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,14 @@ export default class RequestMessage {
* @param {string} databaseContext.impersonatedUser The name of the user to impersonation when getting the routing table.
* @return {RequestMessage} the ROUTE message.
*/
static routeV4x4 (routingContext = {}, bookmarks = [], databaseContext = {}) {
static routeV4x4 (routingContext = {}, bookmarks = [], databaseContext = {}) {
const dbContext = {}

if ( databaseContext.databaseName ) {
if (databaseContext.databaseName) {
dbContext.db = databaseContext.databaseName
}

if ( databaseContext.impersonatedUser ) {
if (databaseContext.impersonatedUser) {
dbContext.imp_user = databaseContext.impersonatedUser
}

Expand Down
1 change: 0 additions & 1 deletion packages/bolt-connection/src/bolt/response-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,4 @@ export default class ResponseHandler {
_resetFailure () {
this._currentFailure = null
}

}
1 change: 1 addition & 0 deletions packages/bolt-connection/src/bolt/routing-table-raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// eslint-disable-next-line no-unused-vars
import Record from 'neo4j-driver-core'

/**
Expand Down
18 changes: 13 additions & 5 deletions packages/bolt-connection/src/bolt/stream-observers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { newError, error, Integer, Record, json, internal } from 'neo4j-driver-core'
import {
newError,
error,
// eslint-disable-next-line no-unused-vars
Integer,
Record,
json,
internal
} from 'neo4j-driver-core'
import RawRoutingTable from './routing-table-raw'

const {
constants: { FETCH_ALL },
constants: { FETCH_ALL }
} = internal
const { PROTOCOL_ERROR } = error
class StreamObserver {
onNext (rawRecord) {}

onError (error) {}
onError (_error) {}

onCompleted (meta) {}
}
Expand Down Expand Up @@ -100,7 +108,7 @@ class ResultStreamObserver extends StreamObserver {
this._highRecordWatermark = highRecordWatermark
this._setState(reactive ? _states.READY : _states.READY_STREAMING)
this._setupAutoPull()
this._paused = false;
this._paused = false
}

/**
Expand Down Expand Up @@ -643,7 +651,7 @@ const _states = {
pull: () => {}
},
FAILED: {
onError: error => {
onError: _error => {
// more errors are ignored
},
name: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* eslint-env browser */
import ChannelBuffer from '../channel-buf'
import { newError, internal } from 'neo4j-driver-core'

Expand All @@ -26,8 +26,10 @@ const {

// Just to be sure that these values are with us even after WebSocket is injected
// for tests.
// eslint-disable-next-line no-unused-vars
const WS_CONNECTING = 0
const WS_OPEN = 1
// eslint-disable-next-line no-unused-vars
const WS_CLOSING = 2
const WS_CLOSED = 3

Expand Down Expand Up @@ -184,7 +186,7 @@ export default class WebSocketChannel {
/**
* Stops the receive timeout for the channel.
*/
stopReceiveTimeout() {
stopReceiveTimeout () {
}

/**
Expand Down Expand Up @@ -265,7 +267,7 @@ function isIPv6Address (hostAndPort) {

function asWindowsFriendlyIPv6Address (scheme, address) {
// replace all ':' with '-'
const hostWithoutColons = address.host().replace(new RegExp(':', 'g'), '-')
const hostWithoutColons = address.host().replace(/:/g, '-')

// replace '%' with 's' for link-local IPv6 address like 'fe80::1%lo0'
const hostWithoutPercent = hostWithoutColons.replace('%', 's')
Expand Down
3 changes: 1 addition & 2 deletions packages/bolt-connection/src/channel/channel-buf.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,14 @@ export default class ChannelBuffer extends BaseBuffer {

/**
* Allocate a buffer
*
*
* @param {number} size The buffer sizzer
* @returns {BaseBuffer} The buffer
*/
export function alloc (size) {
return new ChannelBuffer(size)
}


function newChannelJSBuffer (arg) {
if (arg instanceof buffer.Buffer) {
return arg
Expand Down
1 change: 0 additions & 1 deletion packages/bolt-connection/src/channel/channel-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,3 @@ function extractTrustedCertificates (driverConfig) {
function extractKnownHostsPath (driverConfig) {
return driverConfig.knownHosts || null
}

1 change: 0 additions & 1 deletion packages/bolt-connection/src/channel/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ NOTE: exports in this module should have exactly the same names/structure as exp

export const Channel = NodeChannel
export const HostNameResolver = NodeHostNameResolver

2 changes: 1 addition & 1 deletion packages/bolt-connection/src/channel/node/node-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export default class NodeChannel {
/**
* Stops the receive timeout for the channel.
*/
stopReceiveTimeout() {
stopReceiveTimeout () {
if (this._receiveTimeout !== null && this._receiveTimeoutStarted) {
this._receiveTimeoutStarted = false
this._conn.setTimeout(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const {
constants: { BOLT_PROTOCOL_V3, BOLT_PROTOCOL_V4_0, BOLT_PROTOCOL_V4_4 }
} = internal

const { SERVICE_UNAVAILABLE, newError } = error
const { SERVICE_UNAVAILABLE } = error

export default class DirectConnectionProvider extends PooledConnectionProvider {
constructor ({ id, config, log, address, userAgent, authToken }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@ const {
}
} = internal


const PROCEDURE_NOT_FOUND_CODE = 'Neo.ClientError.Procedure.ProcedureNotFound'
const DATABASE_NOT_FOUND_CODE = 'Neo.ClientError.Database.DatabaseNotFound'
const INVALID_BOOKMARK_CODE = 'Neo.ClientError.Transaction.InvalidBookmark'
const INVALID_BOOKMARK_MIXTURE_CODE =
const INVALID_BOOKMARK_MIXTURE_CODE =
'Neo.ClientError.Transaction.InvalidBookmarkMixture'
const AUTHORIZATION_EXPIRED_CODE =
const AUTHORIZATION_EXPIRED_CODE =
'Neo.ClientError.Security.AuthorizationExpired'

const SYSTEM_DB_NAME = 'system'
Expand Down Expand Up @@ -257,7 +256,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
})

const servers = accessMode === WRITE ? routingTable.writers : routingTable.readers

let error = newError(
`No servers available for database '${context.database}' with access mode '${accessMode}'`,
SERVICE_UNAVAILABLE
Expand Down Expand Up @@ -285,7 +284,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
}

forgetWriter (address, database) {
this._routingTableRegistry.apply( database, {
this._routingTableRegistry.apply(database, {
applyWhenExists: routingTable => routingTable.forgetWriter(address)
})
}
Expand Down Expand Up @@ -510,7 +509,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
errorCode: SESSION_EXPIRED,
handleAuthorizationExpired: (error, address) => this._handleAuthorizationExpired(error, address)
})

const connectionProvider = new SingleConnectionProvider(
new DelegateConnection(connection, databaseSpecificErrorHandler))

Expand All @@ -535,7 +534,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
}
}

_handleRediscoveryError(error, routerAddress) {
_handleRediscoveryError (error, routerAddress) {
if (_isFailFastError(error) || _isFailFastSecurityError(error)) {
throw error
} else if (error.code === PROCEDURE_NOT_FOUND_CODE) {
Expand Down Expand Up @@ -578,9 +577,9 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
this._routingTableRegistry.register(
newRoutingTable
)

onDatabaseNameResolved(newRoutingTable.database)

this._log.info(`Updated routing table ${newRoutingTable}`)
}

Expand Down Expand Up @@ -639,14 +638,14 @@ class RoutingTableRegistry {

/**
* Retrieves a routing table from a given database name
*
*
* @param {string|impersonatedUser} impersonatedUser The impersonated User
* @param {string} database The database name
* @param {function()|RoutingTable} defaultSupplier The routing table supplier, if it's not a function or not exists, it will return itself as default value
* @returns {RoutingTable} The routing table for the respective database
*/
get (database, defaultSupplier) {
if (this._tables.has(database) ) {
if (this._tables.has(database)) {
return this._tables.get(database)
}
return typeof defaultSupplier === 'function'
Expand Down Expand Up @@ -690,14 +689,13 @@ function _isFailFastError (error) {
return [
DATABASE_NOT_FOUND_CODE,
INVALID_BOOKMARK_CODE,
INVALID_BOOKMARK_MIXTURE_CODE,
INVALID_BOOKMARK_MIXTURE_CODE
].includes(error.code)
}

function _isFailFastSecurityError (error) {
return error.code.startsWith('Neo.ClientError.Security.') &&
return error.code.startsWith('Neo.ClientError.Security.') &&
![
AUTHORIZATION_EXPIRED_CODE,
AUTHORIZATION_EXPIRED_CODE
].includes(error.code)
}

Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export default class ChannelConnection extends Connection {
* Starts and stops the receive timeout timer.
* @param {number} requestsNumber Ongoing requests number
*/
_handleOngoingRequestsNumberChange(requestsNumber) {
_handleOngoingRequestsNumberChange (requestsNumber) {
if (requestsNumber === 0) {
this._ch.stopReceiveTimeout()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export default class ConnectionErrorHandler {
}

function isAutorizationExpiredError (error) {
return error && (
error.code === 'Neo.ClientError.Security.AuthorizationExpired' ||
return error && (
error.code === 'Neo.ClientError.Security.AuthorizationExpired' ||
error.code === 'Neo.ClientError.Security.TokenExpired'
)
}
Expand Down
Loading