This repository has been archived by the owner on Aug 7, 2023. It is now read-only.
/
helpers.js
66 lines (55 loc) · 1.63 KB
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use babel'
import ChildProcess from 'child_process'
import { createFromProcess } from 'process-communication'
import { join } from 'path'
// eslint-disable-next-line import/no-extraneous-dependencies, import/extensions
import { Disposable } from 'atom'
const RULE_OFF_SEVERITY = 0
export function spawnWorker() {
const env = Object.create(process.env)
delete env.NODE_PATH
delete env.NODE_ENV
delete env.OS
const child = ChildProcess.fork(join(__dirname, 'worker.js'), [], { env, silent: true })
const worker = createFromProcess(child)
child.stdout.on('data', (chunk) => {
console.log('[Linter-ESLint] STDOUT', chunk.toString())
})
child.stderr.on('data', (chunk) => {
console.log('[Linter-ESLint] STDERR', chunk.toString())
})
return {
worker,
subscription: new Disposable(() => {
worker.kill()
})
}
}
export function showError(givenMessage, givenDetail = null) {
let detail
let message
if (message instanceof Error) {
detail = message.stack
message = message.message
} else {
detail = givenDetail
message = givenMessage
}
atom.notifications.addError(`[Linter-ESLint] ${message}`, {
detail,
dismissable: true
})
}
export function idsToIgnoredRules(ruleIds = []) {
return ruleIds.reduce((ids, id) => {
ids[id] = RULE_OFF_SEVERITY
return ids
}, {})
}
export function validatePoint(textEditor, line, col) {
const buffer = textEditor.getBuffer()
// Clip the given point to a valid one, and check if it equals the original
if (!buffer.clipPosition([line, col]).isEqual([line, col])) {
throw new Error(`${line}:${col} isn't a valid point!`)
}
}