Skip to content

Commit

Permalink
Merge pull request #91 from mantoni/v7
Browse files Browse the repository at this point in the history
ES 6 and unit tests
  • Loading branch information
mantoni authored Aug 21, 2018
2 parents 6d41c00 + d979eca commit 6159e90
Show file tree
Hide file tree
Showing 21 changed files with 1,465 additions and 563 deletions.
72 changes: 0 additions & 72 deletions .eslintrc

This file was deleted.

5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- "6"
- "8"
- "10"
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# eslint\_d

[![Build Status]](https://travis-ci.org/mantoni/eslint_d.js)
[![SemVer]](http://semver.org)
[![License]](https://github.com/mantoni/eslint\_d.js/blob/master/LICENSE)

Expand Down Expand Up @@ -152,19 +153,21 @@ $ eslint_d . --cache

## Compatibility

- `6.0.0`: eslint 5.0+
- `7.0.0`: eslint 5.4+, node 6, 8 and 10
- `6.0.0`: eslint 5.0+, node 6+ (eslint dropped node 4)
- `5.0.0`: eslint 4.0+
- `4.0.0`: eslint 3.0+
- `4.0.0`: eslint 3.0+, node 4+ (eslint dropped node 0.10 and 0.12)
- `3.0.0`: eslint 2.2+
- `1.0.0`, `2.0.0`: eslint 1.4+
- `1.0.0`, `2.0.0`: eslint 1.4+, node 4 (and probably older)

## License

MIT

[SemVer]: http://img.shields.io/:semver-%E2%9C%93-brightgreen.svg
[License]: http://img.shields.io/npm/l/eslint_d.svg
[eslint]: http://eslint.org
[Build Status]: https://img.shields.io/travis/mantoni/eslint_d.js/master.svg
[SemVer]: https://img.shields.io/:semver-%E2%9C%93-brightgreen.svg
[License]: https://img.shields.io/npm/l/eslint_d.svg
[eslint]: https://eslint.org
[SublimeLinter]: https://github.com/roadhump/SublimeLinter-contrib-eslint_d
[syntastic]: https://github.com/scrooloose/syntastic
[change220]: https://github.com/mantoni/eslint_d.js/blob/master/CHANGES.md#220
Expand Down
32 changes: 11 additions & 21 deletions bin/eslint_d.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
'use strict';

function start() {
require('../lib/launcher')();
require('../lib/launcher').launch();
}

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

start();
Expand All @@ -18,38 +18,28 @@ 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);

// If color is not supported, pass the `--no-color` switch to eslint. We
// enforce color support in the daemon with `FORCE_COLOR=1` (see
// `launcher.js`).
if (!require('supports-color').stdout) {
args.unshift('--no-color');
}
const args = process.argv.slice(2);

if (useStdIn) {
var text = '';
if (args.indexOf('--stdin') > -1) {
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
109 changes: 59 additions & 50 deletions lib/client.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
'use strict';

var net = require('net');
var portfile = require('./portfile');
const net = require('net');
const out = require('./out');
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.once('error', () => {
process.exitCode = 1;
callback('Could not connect');
});
});
}

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

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

function lint(socket, token, args, text) {
// If color is not supported, pass the `--no-color` switch to eslint. We
// enforce color support in the daemon with `FORCE_COLOR=1` (see
// `launcher.js`).
if (!require('supports-color').stdout) {
args = ['--no-color'].concat(args);
}

let buf = '';
socket.on('data', (chunk) => {
buf += chunk;
const p = buf.lastIndexOf('\n');
if (p !== -1) {
out.write(buf.substring(0, p + 1));
buf = buf.substring(p + 1);
}
});
socket.on('end', () => {
if (buf) {
if (buf === '# exit 1') {
process.exitCode = 1;
} else {
out.write(buf);
}
}
});
const cwd = process.cwd();
socket.end(`${token} ${JSON.stringify({ cwd, args, text })}`);
}

exports.lint = function (args, text) {
if (!args.length && !text) {
process.stdout.write('No files specified\n');
out.write('No files specified\n');
return;
}

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

const server = require('./server');
const portfile = require('./portfile');

const instance = server.start();

process.on('exit', () => {
portfile.unlink();
});
process.on('SIGTERM', () => {
instance.stop();
});
process.on('SIGINT', () => {
instance.stop();
});
Loading

0 comments on commit 6159e90

Please sign in to comment.