Skip to content

Commit

Permalink
chore: eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Jan 11, 2023
1 parent d046d09 commit c423e3d
Show file tree
Hide file tree
Showing 26 changed files with 1,657 additions and 238 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/dist
/docs
/generated
/node_modules
3 changes: 3 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: './node_modules/@companion-module/tools/eslint/main.cjs',
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"build:json-schema": "json2ts --input assets/manifest.schema.json --output generated/manifest.d.ts",
"build:ajv-validator": "ajv compile -s assets/manifest.schema.json -o generated/validate_manifest.js",
"docs:html": "typedoc --tsconfig tsconfig.build.json --entryPoints src/index.ts --excludePrivate --theme default --out docs",
"lint:raw": "eslint --ext .ts --ext .js",
"lint": "yarn lint:raw .",
"unit": "jest"
},
"engines": {
Expand All @@ -37,6 +39,7 @@
"tslib": "^2.4.1"
},
"devDependencies": {
"@companion-module/tools": "^0.5.2",
"@tsconfig/node18": "^1.0.1",
"@types/ejson": "^2.2.0",
"@types/jest": "^29.2.5",
Expand Down
4 changes: 2 additions & 2 deletions src/__mocks__/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const orgSetTimeout = setTimeout
export async function runAllTimers() {
export async function runAllTimers(): Promise<void> {
// Run all timers, and wait, multiple times.
// This is to allow timers AND internal promises to resolve in inner functions
for (let i = 0; i < 50; i++) {
Expand All @@ -8,7 +8,7 @@ export async function runAllTimers() {
}
}

export async function runTimersUntilNow() {
export async function runTimersUntilNow(): Promise<void> {
// Run all timers, and wait, multiple times.
// This is to allow timers AND internal promises to resolve in inner functions
for (let i = 0; i < 50; i++) {
Expand Down
27 changes: 14 additions & 13 deletions src/entrypoint.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import PTimeout from 'p-timeout'
import { HostApiNodeJsIpc, HostToModuleEventsInit, ModuleToHostEventsInit } from './host-api/versions.js'
/* eslint-disable no-process-exit */
import { HostApiNodeJsIpc, HostToModuleEventsInit, ModuleToHostEventsInit } from './host-api/versions'
import fs from 'fs/promises'
import { ModuleManifest } from './manifest.js'
import { CompanionStaticUpgradeScript } from './module-api/upgrade.js'
import { InstanceBase } from './module-api/base.js'
import { literal } from './util.js'
import { InstanceBaseProps } from './internal/base.js'
import { ModuleManifest } from './manifest'
import { CompanionStaticUpgradeScript } from './module-api/upgrade'
import { InstanceBase } from './module-api/base'
import { literal } from './util'
import { InstanceBaseProps } from './internal/base'
import { init, configureScope } from '@sentry/node'
import '@sentry/tracing'
import { IpcWrapper } from './host-api/ipc-wrapper.js'
import { IpcWrapper } from './host-api/ipc-wrapper'

let hasEntrypoint = false
// eslint-disable-next-line @typescript-eslint/no-unused-vars
let moduleInstance: InstanceBase<any> | undefined

export type InstanceConstructor<TConfig> = new (internal: unknown) => InstanceBase<TConfig>
Expand Down Expand Up @@ -38,8 +39,8 @@ export function runEntrypoint<TConfig>(
factory: InstanceConstructor<TConfig>,
upgradeScripts: CompanionStaticUpgradeScript<TConfig>[]
): void {
Promise.resolve().then(async () => {
try {
Promise.resolve()
.then(async () => {
// const pkgJsonStr = (await fs.readFile(path.join(__dirname, '../package.json'))).toString()
// const pkgJson = JSON.parse(pkgJsonStr)
// if (!pkgJson || pkgJson.name !== '@companion-module/base')
Expand Down Expand Up @@ -129,10 +130,10 @@ export function runEntrypoint<TConfig>(
process.exit(11)
}
)
} catch (e: any) {
})
.catch((e) => {
console.error(`Failed to startup module:`)
console.error(e.stack || e.message)
process.exit(1)
}
})
})
}
4 changes: 2 additions & 2 deletions src/helpers/telnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import EventEmitter from 'eventemitter3'
import { Transform, TransformCallback, TransformOptions } from 'stream'
import { TCPHelper, TCPHelperEvents, TCPHelperOptions } from './tcp'

const NULL = 0
// const NULL = 0
const DATA = 0
const SE = 240
const SB = 250
Expand Down Expand Up @@ -79,7 +79,7 @@ export class TelnetHelper extends EventEmitter<TelnetHelperEvents> {
connect(): boolean {
return this.#tcp.connect()
}
send(message: string | Buffer): Promise<boolean> {
async send(message: string | Buffer): Promise<boolean> {
return this.#tcp.send(message)
}

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/udp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class UDPHelper extends EventEmitter<UDPHelperEvents> {
}, 5000)
}

send(message: string | Buffer): Promise<void> {
async send(message: string | Buffer): Promise<void> {
if (this.#destroyed) throw new Error('Cannot write to destroyed socket')
if (!message || !message.length) throw new Error('No message to send')

Expand Down
18 changes: 9 additions & 9 deletions src/host-api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
* This will allow for cleaner and more stable apis which can both evolve at different rates
*/

import { CompanionFeedbackButtonStyleResult, SomeCompanionFeedbackInputField } from '../module-api/feedback.js'
import { OSCSomeArguments } from '../common/osc.js'
import { SomeCompanionConfigField } from '../module-api/config.js'
import { LogLevel, InstanceStatus } from '../module-api/enums.js'
import { InputValue, CompanionOptionValues, CompanionInputFieldBase } from '../module-api/input.js'
import { CompanionButtonPresetDefinition } from '../module-api/preset.js'
import { CompanionHTTPRequest, CompanionHTTPResponse } from '../module-api/http.js'
import { SomeCompanionActionInputField } from '../module-api/action.js'
import { CompanionVariableValue } from '../module-api/variable.js'
import { CompanionFeedbackButtonStyleResult, SomeCompanionFeedbackInputField } from '../module-api/feedback'
import { OSCSomeArguments } from '../common/osc'
import { SomeCompanionConfigField } from '../module-api/config'
import { LogLevel, InstanceStatus } from '../module-api/enums'
import { InputValue, CompanionOptionValues, CompanionInputFieldBase } from '../module-api/input'
import { CompanionButtonPresetDefinition } from '../module-api/preset'
import { CompanionHTTPRequest, CompanionHTTPResponse } from '../module-api/http'
import { SomeCompanionActionInputField } from '../module-api/action'
import { CompanionVariableValue } from '../module-api/variable'

export interface ModuleToHostEventsV0 {
'log-message': (msg: LogMessageMessage) => never
Expand Down
2 changes: 1 addition & 1 deletion src/host-api/ipc-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class IpcWrapper<TOutbound extends { [key: string]: any }, TInbound exten
name: T,
msg: ParamsIfReturnIsValid<TOutbound[T]>[0],
defaultResponse?: () => Error,
timeout: number = 0
timeout = 0
): Promise<ReturnType<TOutbound[T]>> {
if (timeout <= 0) timeout = this.#defaultTimeout

Expand Down
12 changes: 6 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './manifest.js'
export * from './module-api/index.js'
export * from './common/osc.js'
export { literal, combineRgb, splitRgb, RgbComponents, assertNever } from './util.js'
export * from './helpers/index.js'
export * from './manifest'
export * from './module-api/index'
export * from './common/osc'
export { literal, combineRgb, splitRgb, RgbComponents, assertNever } from './util'
export * from './helpers/index'

export { runEntrypoint } from './entrypoint.js'
export { runEntrypoint } from './entrypoint'
Loading

0 comments on commit c423e3d

Please sign in to comment.