Skip to content

Commit

Permalink
Switch to eslint config to @studio/eslint-config
Browse files Browse the repository at this point in the history
BREAKING: This introduces various es6 features.
  • Loading branch information
mantoni committed Aug 20, 2018
1 parent 6d41c00 commit d25082a
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 186 deletions.
72 changes: 0 additions & 72 deletions .eslintrc

This file was deleted.

22 changes: 10 additions & 12 deletions bin/eslint_d.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function start() {
require('../lib/launcher')();
}

var cmd = process.argv[2];
const cmd = process.argv[2];
if (cmd === 'start') {

start();
Expand All @@ -18,21 +18,21 @@ if (cmd === 'start') {

} else if (cmd === '-h' || cmd === '--help') {

var options = require('../lib/options');
const options = require('../lib/options');
console.log(options.generateHelp());

} else {

var client = require('../lib/client');
const client = require('../lib/client');
if (cmd === 'restart') {
client.stop(function () {
client.stop(() => {
process.nextTick(start);
});
} else {
var commands = ['stop', 'status', 'restart'];
const commands = ['stop', 'status', 'restart'];
if (commands.indexOf(cmd) === -1) {
var useStdIn = (process.argv.indexOf('--stdin') > -1);
var args = process.argv.slice(2);
const useStdIn = (process.argv.indexOf('--stdin') > -1);
const args = process.argv.slice(2);

// If color is not supported, pass the `--no-color` switch to eslint. We
// enforce color support in the daemon with `FORCE_COLOR=1` (see
Expand All @@ -42,14 +42,12 @@ if (cmd === 'start') {
}

if (useStdIn) {
var text = '';
let text = '';
process.stdin.setEncoding('utf8');

process.stdin.on('data', function (chunk) {
process.stdin.on('data', (chunk) => {
text += chunk;
});

process.stdin.on('end', function () {
process.stdin.on('end', () => {
client.lint(args, text);
});
} else {
Expand Down
55 changes: 26 additions & 29 deletions lib/client.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
'use strict';

var net = require('net');
var portfile = require('./portfile');
const net = require('net');
const portfile = require('./portfile');

function connect(callback) {
portfile.read(function (config) {
portfile.read((config) => {
if (!config) {
callback('Not running');
return;
}
var socket = net.connect(config.port, '127.0.0.1', function () {
const socket = net.connect(config.port, '127.0.0.1', () => {
callback(null, socket, config.token);
});
socket.on('error', function () {
socket.on('error', () => {
callback('Could not connect');
});
});
}

exports.stop = function (callback) {
connect(function (err, socket, token) {
connect((err, socket, token) => {
if (err) {
process.stdout.write(err + '\n');
process.stdout.write(`${err}\n`);
return;
}
socket.end(token + ' stop', function () {
socket.end(`${token} stop`, () => {
if (typeof callback === 'function') {
callback();
}
Expand All @@ -33,18 +33,18 @@ exports.stop = function (callback) {
};

exports.status = function () {
connect(function (err, socket, token) {
connect((err, socket, token) => {
if (err) {
process.stdout.write(err + '\n');
process.stdout.write(`${err}\n`);
return;
}
socket.on('data', function (chunk) {
process.stdout.write('' + chunk);
socket.on('data', (chunk) => {
process.stdout.write(String(chunk));
});
socket.on('end', function () {
socket.on('end', () => {
process.stdout.write('\n');
});
socket.end(token + ' status');
socket.end(`${token} status`);
});
};

Expand All @@ -55,16 +55,16 @@ exports.lint = function (args, text) {
}

function lint(socket, token) {
var buf = '';
socket.on('data', function (chunk) {
let buf = '';
socket.on('data', (chunk) => {
buf += chunk;
var p = buf.lastIndexOf('\n');
const p = buf.lastIndexOf('\n');
if (p !== -1) {
process.stdout.write(buf.substring(0, p + 1));
buf = buf.substring(p + 1);
}
});
socket.on('end', function () {
socket.on('end', () => {
if (buf) {
if (buf === '# exit 1') {
process.exitCode = 1;
Expand All @@ -73,21 +73,18 @@ exports.lint = function (args, text) {
}
}
});
socket.end(token + ' ' + JSON.stringify({
cwd: process.cwd(),
args: args,
text: text
}));
const cwd = process.cwd();
socket.end(`${token} ${JSON.stringify({ cwd, args, text })}`);
}
connect(function (err, socket, token) {
connect((err, socket, token) => {
if (err) {
require('./launcher')(function () {
connect(function (err, socket, token) {
require('./launcher')(() => {
connect((err, socket, token) => {
if (err) {
process.stdout.write(err + '\n');
} else {
lint(socket, token);
process.stdout.write(`${err}\n`);
return;
}
lint(socket, token);
});
});
} else {
Expand Down
28 changes: 14 additions & 14 deletions lib/launcher.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
'use strict';

var net = require('net');
var portfile = require('../lib/portfile');
const net = require('net');
const portfile = require('../lib/portfile');

function check(callback) {
portfile.read(function (data) {
portfile.read((data) => {
if (!data) {
callback(false);
return;
}
var socket = net.connect(data.port, '127.0.0.1', function () {
const socket = net.connect(data.port, '127.0.0.1', () => {
socket.end();
callback(true);
});
socket.on('error', function () {
socket.on('error', () => {
callback(false);
});
});
}

function wait(callback) {
check(function (running) {
check((running) => {
if (running) {
if (typeof callback === 'function') {
callback(null);
}
} else {
setTimeout(function () {
setTimeout(() => {
wait(callback);
}, 100);
}
});
}

function launch(callback) {
var env = Object.create(process.env);
const env = Object.create(process.env);
// Force enable color support in `supports-color`. The client adds
// `--no-color` to disable color if not supported.
env.FORCE_COLOR = 1;
var spawn = require('child_process').spawn;
var server = require.resolve('../lib/server');
var child = spawn('node', [server], {
const spawn = require('child_process').spawn;
const server = require.resolve('../lib/server');
const child = spawn('node', [server], {
detached: true,
env: env,
env,
stdio: ['ignore', 'ignore', 'ignore']
});
child.unref();
setTimeout(function () {
setTimeout(() => {
wait(callback);
}, 100);
}

module.exports = function (callback) {
check(function (running) {
check((running) => {
if (running) {
process.stdout.write('Already running\n');
} else {
Expand Down
Loading

0 comments on commit d25082a

Please sign in to comment.