mirror of
https://github.com/desktop/desktop
synced 2024-10-31 11:07:25 +00:00
Just use ESLint
This commit is contained in:
parent
50cd5d5fdd
commit
d8fbe81be2
1 changed files with 10 additions and 29 deletions
|
@ -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 {
|
||||
// there’s other stuff; I’m not including it
|
||||
// because it’s not needed here.
|
||||
// If you want to add to it, here’s 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}}`
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue