Just use ESLint

This commit is contained in:
joshaber 2017-11-28 10:33:37 -05:00
parent 50cd5d5fdd
commit d8fbe81be2

View file

@ -1,29 +1,10 @@
#!/usr/bin/env ts-node
import * as Path from 'path'
import chalk from 'chalk'
import { execFile } from 'child_process'
/**
* A partial `eslint_d` client interface.
* It currently only includes the methods actually used by this file.
*/
interface IClient {
// theres other stuff; Im not including it
// because its not needed here.
// If you want to add to it, heres the source:
// https://github.com/mantoni/eslint_d.js/blob/v5.1.0/lib/client.js
/**
* Lint a project using the ESLint server instance,
* or start a new instance if one is not available.
* @param args The arguments to pass to ESLint.
* Interpreted as if passed after `eslint` on the command line.
* @param text The text to lint, if no files are passed as arguments.
*/
lint(args: string[], text?: string): void
}
const client: IClient = require('eslint_d/lib/client')
const ESLINT_ARGS = [
const args = [
'--cache',
'--rulesdir=./eslint-rules',
'./{script,eslint-rules}/**/*.{j,t}s?(x)',
@ -33,14 +14,14 @@ const ESLINT_ARGS = [
...process.argv.slice(2),
]
client.lint(ESLINT_ARGS)
const root = Path.join(__dirname, '..')
const eslintPath = Path.join(root, 'node_modules', '.bin', 'eslint')
const child = execFile(eslintPath, args, { cwd: root }, (err, stdout) => {
console.log(stdout)
})
type ProcessOnExit = (cb: (code: number) => void) => void
/** HACK: allow process.on('exit') to be called with a `number` */
const onExit = process.on.bind(process, 'exit') as ProcessOnExit
onExit(code => {
if (code && ESLINT_ARGS.indexOf('--fix') === -1) {
child.on('exit', code => {
if (code && args.indexOf('--fix') === -1) {
console.error(
chalk`{bold.green → To fix some of these errors, run {underline yarn eslint:fix}}`
)