Skip to content

Commit

Permalink
fix lint errors and enable lint checks on circleci
Browse files Browse the repository at this point in the history
  • Loading branch information
msmathers committed Apr 23, 2020
1 parent 2024221 commit 40aa9e6
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
command: npm install
- run:
name: Run server tests
command: npm run type-check
command: npm run type-check && npm run lint
- run:
name: Install UI deps
command: npm install
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:
- run: npm install
- run:
name: Run tests
command: npm run type-check
command: npm run type-check && npm run lint

- save_cache:
paths:
Expand Down
1 change: 1 addition & 0 deletions inputs/file/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"plugins": ["@typescript-eslint"],
"extends": ["airbnb-base", "plugin:@typescript-eslint/recommended"],
"rules": {
"import/extensions": "off",
"import/no-unresolved": "off",
"semi": "off",
"@typescript-eslint/member-delimiter-style": "off"
Expand Down
3 changes: 2 additions & 1 deletion inputs/file/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ const CONFIG_PATH = process.env.LOGIO_FILE_INPUT_CONFIG_PATH

function loadConfig(configPath: string): InputConfig {
const config = JSON.parse(fs.readFileSync(configPath, { encoding: 'utf8' }))
if (!!ROOT_PATH) {
if (ROOT_PATH) {
config.inputs.forEach((input: FileInputConfig) => {
// eslint-disable-next-line no-param-reassign
input.config.path = path.resolve(ROOT_PATH, input.config.path)
})
}
Expand Down
9 changes: 4 additions & 5 deletions inputs/file/src/input.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import chokidar from 'chokidar'
import fs from 'fs'
import { Socket } from 'net'
import path from 'path'
import { promisify } from 'util'
import {
FileInputConfig,
FileSizeMap,
InputConfig,
WatcherOptions,
} from './types'

const openAsync = promisify(fs.open)
const readAsync = promisify(fs.read)
const readdirAsync = promisify(fs.readdir)
const statAsync = promisify(fs.stat)

const fds: {[filePath: string]: number} = {}
Expand All @@ -35,7 +34,7 @@ async function sendNewMessages(
const offset = Math.max(newSize - oldSize, 0)
const readBuffer = Buffer.alloc(offset)
await readAsync(fd, readBuffer, 0, offset, oldSize)
const messages = readBuffer.toString().split('\r\n').filter(msg => !!msg.trim())
const messages = readBuffer.toString().split('\r\n').filter((msg) => !!msg.trim())
messages.forEach((message) => {
client.write(`+msg|${streamName}|${sourceName}|${message}\0`)
})
Expand All @@ -59,9 +58,9 @@ async function startFileWatcher(
streamName: string,
sourceName: string,
inputPath: string,
watcherOptions: any,
watcherOptions: WatcherOptions,
): Promise<void> {
let fileSizes: FileSizeMap = {}
const fileSizes: FileSizeMap = {}
const watcher = chokidar.watch(inputPath, watcherOptions)
// Capture byte size of a new file
watcher.on('add', async (filePath: string) => {
Expand Down
22 changes: 21 additions & 1 deletion inputs/file/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
export type FileSizeMap = { [path: string]: number }

export type WatcherOptions = {
persistent: boolean,
ignored: string,
ignoreInitial: boolean,
followSymlinks: boolean,
cwd: string,
disableGlobbing: boolean,
usePolling: boolean,
interval: number,
binaryInterval: number,
alwaysStat: boolean,
depth: number,
awaitWriteFinish: {
stabilityThreshold: number,
pollInterval: number
},
ignorePermissionErrors: boolean,
atomic: boolean | number
}

export type FileInputConfig = {
source: string,
stream: string,
config: {
path: string,
watcherOptions: any,
watcherOptions: WatcherOptions,
},
}

Expand Down
1 change: 1 addition & 0 deletions server/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"plugins": ["@typescript-eslint"],
"extends": ["airbnb-base", "plugin:@typescript-eslint/recommended"],
"rules": {
"import/extensions": "off",
"import/no-unresolved": "off",
"semi": "off",
"@typescript-eslint/member-delimiter-style": "off"
Expand Down
9 changes: 7 additions & 2 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ async function handleNewMessage(
const msg = msgParts.slice(3).join('|')
const inputName = inputs.add(stream, source)
// Broadcast message to input channel
io.to(inputName).emit(mtype, { inputName, msg, stream, source })
io.to(inputName).emit(mtype, {
inputName,
msg,
stream,
source,
})
// Broadcast ping to all browsers
io.emit('+ping', { inputName, stream, source })
if (config.debug) {
Expand Down Expand Up @@ -82,7 +87,7 @@ async function broadcastMessage(
const msgs = data.toString()
.split('\0')
.slice(0, -1)
.filter(msg => !!msg.trim())
.filter((msg) => !!msg.trim())
msgs.forEach(async (msg) => {
const msgParts = msg.split('|')
const messageHandler = messageHandlers[msgParts[0]]
Expand Down

0 comments on commit 40aa9e6

Please sign in to comment.