Skip to content
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

chore: Add @typescript-eslint/no-confusing-void-expression rule #2910

Merged
merged 7 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export default [
allowTemplateLiterals: true
}],
'@typescript-eslint/default-param-last': 'error',
'@typescript-eslint/no-confusing-void-expression': ['error', {
ignoreArrowShorthand: true
}],
'@typescript-eslint/no-extraneous-class': 'error',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/no-invalid-this': 'error',
Expand Down
18 changes: 12 additions & 6 deletions packages/autocertifier-server/src/DnsServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ export class DnsServer {
if (parts.length < 4 || parts[0] !== '_acme-challenge') {
// @ts-ignore private field
response.header.rcode = FORMERR
return send(response)
send(response)
return
}

const subdomain = parts[1]
Expand All @@ -105,7 +106,8 @@ export class DnsServer {
if (!subdomainRecord) {
// @ts-ignore private field
response.header.rcode = NXDOMAIN
return send(response)
send(response)
return
}

const acmeChallenge = subdomainRecord.acmeChallenge
Expand Down Expand Up @@ -162,7 +164,8 @@ export class DnsServer {
if (parts.length < 3) {
// @ts-ignore private field
response.header.rcode = NXDOMAIN
return send(response)
send(response)
return
}

const subdomain = parts[0]
Expand All @@ -182,7 +185,8 @@ export class DnsServer {
logger.info('handleAQuery() not found: ' + name)
// @ts-ignore private field
response.header.rcode = NXDOMAIN
return send(response)
send(response)
return
}
retIp = subdomainRecord.ip
}
Expand All @@ -207,7 +211,8 @@ export class DnsServer {
logger.debug('filtering invalid question')
// @ts-ignore private field
response.header.rcode = FORMERR
return send(response)
send(response)
return
}
const mixedCaseName = question.name
const name = mixedCaseName.toLowerCase()
Expand All @@ -216,7 +221,8 @@ export class DnsServer {
logger.debug('invalid domain name in query: ' + name)
// @ts-ignore private field
response.header.rcode = NXDOMAIN
return send(response)
send(response)
return
}

const parts = mixedCaseName.split('.')
Expand Down
2 changes: 1 addition & 1 deletion packages/autocertifier-server/src/StreamrChallenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const runStreamrChallenge = (
const communicator = new RoutingRpcCommunicator(SERVICE_ID,
async (msg: Message): Promise<void> => {
logger.info('sending message to peer')
return managedConnection.send(Message.toBinary(msg))
managedConnection.send(Message.toBinary(msg))
})
managedConnection.on('managedData', (msg: Uint8Array) => {
communicator.handleMessageFromPeer(Message.fromBinary(msg))
Expand Down
2 changes: 1 addition & 1 deletion packages/dht/src/connection/ConnectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
this.metrics.sendMessagesPerSecond.record(1)

if (this.endpoints.get(nodeId)!.connected) {
return (connection as ManagedConnection).send(binary)
(connection as ManagedConnection).send(binary)
} else {
return (this.endpoints.get(nodeId)! as ConnectingEndpoint).buffer.push(binary)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/dht/src/connection/simulator/Simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ export class Simulator {

if (!target) {
logger.error('Target connector not found when executing connect operation')
return operation.association.connectedCallback!('Target connector not found')
operation.association.connectedCallback!('Target connector not found')
return
}

target.handleIncomingConnection(operation.sourceConnection)
Expand Down
10 changes: 10 additions & 0 deletions packages/dht/test/integration/ConnectionLocking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ describe('Connection Locking', () => {
const nodeId2 = toNodeId(mockPeerDescriptor2)
await Promise.all([
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
teogeb marked this conversation as resolved.
Show resolved Hide resolved
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock')
])
expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
Expand All @@ -73,10 +74,12 @@ describe('Connection Locking', () => {
const nodeId2 = toNodeId(mockPeerDescriptor2)
await Promise.all([
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1')
])
await Promise.all([
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock2')
])
expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
Expand All @@ -89,6 +92,7 @@ describe('Connection Locking', () => {
const nodeId2 = toNodeId(mockPeerDescriptor2)
await Promise.all([
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock')
])
expect(connectionManager1.hasConnection(nodeId2))
Expand All @@ -106,10 +110,12 @@ describe('Connection Locking', () => {
const nodeId2 = toNodeId(mockPeerDescriptor2)
await Promise.all([
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1')
])
await Promise.all([
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock2')
])

Expand All @@ -130,7 +136,9 @@ describe('Connection Locking', () => {
await Promise.all([
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
until(() => connectionManager1.hasRemoteLockedConnection(nodeId2)),
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1'),
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
connectionManager2.lockConnection(mockPeerDescriptor1, 'testLock1')
])

Expand All @@ -155,7 +163,9 @@ describe('Connection Locking', () => {
await Promise.all([
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
until(() => connectionManager1.hasRemoteLockedConnection(nodeId2)),
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1'),
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
connectionManager2.lockConnection(mockPeerDescriptor1, 'testLock1')
])
expect(connectionManager1.hasConnection(nodeId2))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const mqttPort = 13611
const wsPort = 13612
const httpPort = 13613

const sendPostRequest = (url: string, content: object): Promise<unknown> => {
return fetch(url, {
const sendPostRequest = async (url: string, content: object): Promise<void> => {
await fetch(url, {
method: 'POST',
body: JSON.stringify(content),
headers: { 'Content-Type': 'application/json' }
Expand All @@ -24,7 +24,7 @@ const sendPostRequest = (url: string, content: object): Promise<unknown> => {

interface PluginPublisher {
connect: (streamId: string) => Promise<void>
publish: (msg: object, streamId: string) => Promise<unknown>
publish: (msg: object, streamId: string) => Promise<void>
close: () => Promise<void>
}

Expand All @@ -33,7 +33,7 @@ class MqttPluginPublisher implements PluginPublisher {
async connect(): Promise<void> {
this.client = await mqtt.connectAsync(`mqtt://127.0.0.1:${mqttPort}`)
}
publish(msg: object, streamId: string): Promise<unknown> {
publish(msg: object, streamId: string): Promise<void> {
return this.client!.publish(streamId, JSON.stringify(msg))
}
close(): Promise<void> {
Expand All @@ -47,19 +47,19 @@ class WebsocketPluginPublisher implements PluginPublisher {
this.client = new WebSocket(`ws://127.0.0.1:${wsPort}/streams/${encodeURIComponent(streamId)}/publish`)
await waitForEvent(this.client, 'open')
}
async publish(msg: object): Promise<unknown> {
return this.client!.send(JSON.stringify(msg))
async publish(msg: object): Promise<void> {
this.client!.send(JSON.stringify(msg))
}
async close(): Promise<void> {
return this.client!.close()
this.client!.close()
}
}

/* eslint-disable class-methods-use-this */
class HttpPluginPublisher implements PluginPublisher {
async connect(): Promise<void> {
}
async publish(msg: object, streamId: string): Promise<unknown> {
async publish(msg: object, streamId: string): Promise<void> {
return sendPostRequest(`http://127.0.0.1:${httpPort}/streams/${encodeURIComponent(streamId)}`, msg)
}
async close(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ProxyClient {
if (this.hasError(query)) {
resultCallback!(ProxyClient.ERROR, undefined)
} else {
return this.realClient.eachRow(query, params, options, rowCallback, resultCallback)
this.realClient.eachRow(query, params, options, rowCallback, resultCallback)
}
}

Expand Down
8 changes: 5 additions & 3 deletions packages/node/test/unit/ConfigWizard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,8 @@ function act(
}

if (action === 'enter') {
return void events.keypress('enter')
events.keypress('enter')
return
}

if ('find' in action) {
Expand All @@ -1506,7 +1507,8 @@ function act(
}

if ('type' in action) {
return void events.type(action.type)
events.type(action.type)
return
}

events.keypress(action.keypress)
Expand Down Expand Up @@ -1643,7 +1645,7 @@ async function scenario(mocks: AnswerMock[]): Promise<Scenario> {
jest.spyOn(process.stdout, 'clearLine').mockImplementation(() => true)
}

void [checkbox, confirm, input, password, select].forEach((prompt) => {
[checkbox, confirm, input, password, select].forEach((prompt) => {
prompt.mockImplementation(async (config: any) => {
const inq = mocksCopy.find(
(inq) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/node/test/unit/helpers/weightedSample.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { range, repeat, sum } from 'lodash'

describe(weightedSample, () => {
it('returns undefined on empty array', () => {
const result = weightedSample([], () => 1)
const result = weightedSample<number>([], () => 1)
expect(result).toBeUndefined()
})

Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/MetricsPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class MetricsPublisher {
const metricsContext = await this.node.getMetricsContext()
const nodeId = await this.node.getNodeId()
this.config.periods.forEach((config) => {
return metricsContext.createReportProducer(async (report: MetricsReport) => {
metricsContext.createReportProducer(async (report: MetricsReport) => {
await this.publish(report, config.streamId, nodeId)
}, config.duration, this.destroySignal.abortSignal)
})
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/src/utils/PushPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ export class PushPipeline<InType, OutType = InType> extends Pipeline<InType, Out
}

end(err?: Error): void {
return this.source.end(err)
this.source.end(err)
}

endWrite(err?: Error): void {
return this.source.endWrite(err)
this.source.endWrite(err)
}

isDone(): boolean {
Expand All @@ -61,6 +61,6 @@ export class PushPipeline<InType, OutType = InType> extends Pipeline<InType, Out
}

clear(): void {
return this.source.clear()
this.source.clear()
}
}
6 changes: 4 additions & 2 deletions packages/sdk/src/utils/Scaffold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ export function Scaffold(
collectErrors(err)
}
onDownSteps.push(onDownStep ?? (() => {}))
return await nextScaffoldStep() // return await gives us a better stack trace
await nextScaffoldStep() // return await gives us a better stack trace
return
}
} else if (onDownSteps.length) {
isDone = false
Expand All @@ -129,7 +130,8 @@ export function Scaffold(
collectErrors(err)
}
nextSteps.push(prevSteps.pop()!)
return await nextScaffoldStep() // return await gives us a better stack trace
await nextScaffoldStep() // return await gives us a better stack trace
return
} else if (error) {
const err = error
error = undefined
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/utils/Signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export class Signal<ArgsType extends any[] = []> {
const task = this.execTrigger(...args)
this.currentTask = task
try {
return await this.currentTask
await this.currentTask
} finally {
if (this.currentTask === task) {
this.currentTask = undefined
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/test/end-to-end/Permissions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('Stream permissions', () => {
await stream.grantPermissions({ public: true, permissions: [StreamPermission.PUBLISH] })
const permissions = await stream.getPermissions()
const owner = await client.getUserId()
return expect(permissions).toIncludeSameMembers([{
expect(permissions).toIncludeSameMembers([{
userId: owner,
permissions: [
StreamPermission.EDIT,
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/test/end-to-end/StorageNodeRegistry2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('StorageNodeRegistry2', () => {

it('all', async () => {
const storageNodeUrls = await client.getStorageNodes()
return expect(storageNodeUrls).toContain(storageNodeAddress)
expect(storageNodeUrls).toContain(storageNodeAddress)
}, TIMEOUT)
})

Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/test/end-to-end/StreamRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ describe('StreamRegistry', () => {
it('returns true for valid publishers', async () => {
const userId = await client.getUserId()
const valid = await client.isStreamPublisher(createdStream.id, userId)
return expect(valid).toBe(true)
expect(valid).toBe(true)
}, TIMEOUT)
it('returns false for invalid publishers', async () => {
const valid = await client.isStreamPublisher(createdStream.id, randomUserId())
return expect(valid).toBe(false)
expect(valid).toBe(false)
}, TIMEOUT)
})

Expand All @@ -227,11 +227,11 @@ describe('StreamRegistry', () => {
it('returns true for valid subscribers', async () => {
const userId = await client.getUserId()
const valid = await client.isStreamSubscriber(createdStream.id, userId)
return expect(valid).toBe(true)
expect(valid).toBe(true)
}, TIMEOUT)
it('returns false for invalid subscribers', async () => {
const valid = await client.isStreamSubscriber(createdStream.id, randomUserId())
return expect(valid).toBe(false)
expect(valid).toBe(false)
}, TIMEOUT)
})

Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/test/integration/basics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('Basics', () => {
}
}
expect(received.map((s) => s.content)).toEqual(published.map((s) => s.content))
return expect(received.map((streamMessage) => streamMessage.timestamp)).toEqual(published.map(() => 1111111))
expect(received.map((streamMessage) => streamMessage.timestamp)).toEqual(published.map(() => 1111111))
}
const stream2 = await createTestStream(client, module)
await stream2.grantPermissions({ permissions: [StreamPermission.SUBSCRIBE], public: true })
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/test/unit/iterators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ describe('nextValue', () => {
})

it('empty', async () => {
const generator = async function* () {}()
const generator: AsyncGenerator<number, any, any> = async function* () {}()
expect(await nextValue(generator)).toBe(undefined)
})
})
Loading
Loading