Skip to content

Commit

Permalink
style: eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed May 2, 2023
1 parent c5e9846 commit 047fef1
Show file tree
Hide file tree
Showing 18 changed files with 4,189 additions and 1,366 deletions.
6 changes: 6 additions & 0 deletions packages/cli/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
root = true

[*]
indent_size = 2
indent_style = space
insert_final_newline = true
3 changes: 3 additions & 0 deletions packages/cli/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": [ "@tpluscode/eslint-config/js" ]
}
4 changes: 4 additions & 0 deletions packages/cli/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
9 changes: 5 additions & 4 deletions packages/cli/bin/barnard59.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ const sdk = new NodeSDK({
autoDetectResources: false,
instrumentations: [
new HttpInstrumentation(),
new WinstonInstrumentation()
new WinstonInstrumentation(),
],
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'barnard59'
})
[SemanticResourceAttributes.SERVICE_NAME]: 'barnard59',
}),
})

const onError = async err => {
Expand All @@ -30,6 +30,7 @@ const onError = async err => {
process.off('SIGTERM', onError)

if (err) {
// eslint-disable-next-line no-console
console.log(err)
}
await sdk.shutdown()
Expand Down Expand Up @@ -81,7 +82,7 @@ const onError = async err => {
const exporter = new CollectorMetricExporter()
sdk.configureMeterProvider({
exporter,
interval: otelMetricsInterval
interval: otelMetricsInterval,
})
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/findPipeline.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import clownface from 'clownface'
import ns from './lib/namespaces.js'

function findPipeline (dataset, iri) {
function findPipeline(dataset, iri) {
let ptr = clownface({ dataset })

if (iri) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import runner from './runner.js'

export {
findPipeline,
runner
runner,
}
8 changes: 4 additions & 4 deletions packages/cli/lib/Histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import padStart from 'lodash/padStart.js'
import range from 'lodash/range.js'

class Histogram {
constructor ({ max = 100, width = 40 } = {}) {
constructor({ max = 100, width = 40 } = {}) {
this.max = max
this.width = width
}

bar (value) {
bar(value) {
const pos = Math.round(value / this.max * this.width)

return range(this.width).map(i => pos > i ? '=' : ' ').join('')
}

generate (data) {
generate(data) {
const maxTextLength = Object.keys(data).reduce((max, text) => Math.max(max, text.length), 0)

return Object.entries(data).map(([key, value]) => {
Expand All @@ -26,7 +26,7 @@ class Histogram {
}).join('\n')
}

async draw (data) {
async draw(data) {
if (this.height) {
readline.moveCursor(process.stderr, 0, -this.height)
}
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/lib/bufferDebug.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import Histogram from './Histogram.js'

const { finished } = stream

function bufferStatePair ({ index, mode, state, step }) {
function bufferStatePair({ index, mode, state, step }) {
const key = `[${index}] (${mode}) ${step.ptr.value} (${state.length}/${state.highWaterMark})`
const value = state.length > 0 ? Math.round(state.length / state.highWaterMark * 100.0) : 0

return { key, value }
}

function bufferInfo (pipeline) {
function bufferInfo(pipeline) {
const steps = pipeline.children

if (!steps) {
Expand All @@ -23,7 +23,7 @@ function bufferInfo (pipeline) {
index,
mode: 'write',
state: step.stream._writableState,
step
step,
})

data[key] = value
Expand All @@ -34,7 +34,7 @@ function bufferInfo (pipeline) {
index,
mode: 'read',
state: step.stream._readableState,
step
step,
})

data[key] = value
Expand All @@ -44,7 +44,7 @@ function bufferInfo (pipeline) {
}, {})
}

function bufferDebug (pipeline, { interval = 10 } = {}) {
function bufferDebug(pipeline, { interval = 10 } = {}) {
let done = false

finished(pipeline.stream, () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import runner from '../runner.js'
import bufferDebug from './bufferDebug.js'
import tracer from './tracer.js'

async function fileToDataset (filename) {
async function fileToDataset(filename) {
return rdf.dataset().import(fromFile(filename))
}

function createOutputStream (output) {
function createOutputStream(output) {
if (output === '-') {
// Use a PassThrough stream instead of just process.stdout to avoid closing
// stdout too early
Expand All @@ -29,7 +29,7 @@ function createOutputStream (output) {
return createWriteStream(output)
}

function setVariable (str, all) {
function setVariable(str, all) {
let [key, value] = str.split('=', 2)

if (typeof value === 'undefined') {
Expand Down Expand Up @@ -68,7 +68,7 @@ const runCommand = program
basePath: resolve(dirname(filename)),
level,
outputStream,
variables
variables,
})

if (enableBufferMonitor) {
Expand All @@ -88,7 +88,7 @@ const runCommand = program
})
})

async function run (commonOptions) {
async function run(commonOptions) {
// Add the common options that were parsed earlier to properly have them
// shown in --help
for (const option of commonOptions) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/lib/namespaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import namespace from '@rdfjs/namespace'

const ns = {
p: namespace('https://pipeline.described.at/'),
rdf: namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#')
rdf: namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#'),
}

export default ns
Loading

0 comments on commit 047fef1

Please sign in to comment.