Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit 2d27aef

Browse files
authored
Merge pull request #55 from AtomLinter/arcanemagus/update-js-linting
Update linting configuration
2 parents 6ac58a7 + bf532ca commit 2d27aef

File tree

6 files changed

+754
-827
lines changed

6 files changed

+754
-827
lines changed

.eslintrc.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

lib/index.js

Lines changed: 61 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,58 @@
11
/* @flow */
22

3-
import net from 'net'
4-
import { CompositeDisposable } from 'atom'
5-
import { spawnServer, terminateServer } from './server'
6-
import type { Server } from './types'
3+
import net from 'net';
4+
import { CompositeDisposable } from 'atom';
5+
import { spawnServer, terminateServer } from './server';
6+
import type { Server } from './types';
77

8-
let spawnedServer: ?Server = null
9-
let subscriptions: ?Object = null
8+
let spawnedServer: ?Server = null;
9+
let subscriptions: ?Object = null;
1010

11-
let ignoreInfo
12-
let ignoreWarning
13-
let showErrorCodes
14-
let ignoreIssueCodes
11+
let ignoreInfo;
12+
let ignoreWarning;
13+
let showErrorCodes;
14+
let ignoreIssueCodes;
1515

1616
export function activate() {
1717
// eslint-disable-next-line global-require
18-
require('atom-package-deps').install('linter-julia')
19-
subscriptions = new CompositeDisposable()
18+
require('atom-package-deps').install('linter-julia');
19+
subscriptions = new CompositeDisposable();
2020
subscriptions.add(atom.config.observe('linter-julia.executablePath', async (executablePath) => {
2121
if (spawnedServer) {
2222
try {
23-
await terminateServer(spawnedServer)
24-
spawnedServer = null
25-
spawnedServer = await spawnServer(executablePath)
23+
await terminateServer(spawnedServer);
24+
spawnedServer = null;
25+
spawnedServer = await spawnServer(executablePath);
2626
} catch (e) {
27-
console.error('[Linter-Julia] Unable to spawn server after config change', e)
27+
const message = '[Linter-Julia] '
28+
+ 'Unable to spawn server after config change';
29+
atom.notifications.addError(`${message}. See console for details.`);
30+
// eslint-disable-next-line no-console
31+
console.error(`${message}: `, e);
2832
}
2933
}
30-
}))
34+
}));
3135
subscriptions.add(atom.config.observe('linter-julia.ignoreInfo', (_ignoreInfo) => {
32-
ignoreInfo = _ignoreInfo
33-
}))
36+
ignoreInfo = _ignoreInfo;
37+
}));
3438
subscriptions.add(atom.config.observe('linter-julia.ignoreWarning', (_ignoreWarning) => {
35-
ignoreWarning = _ignoreWarning
36-
}))
39+
ignoreWarning = _ignoreWarning;
40+
}));
3741
subscriptions.add(atom.config.observe('linter-julia.showErrorCodes', (_showErrorCodes) => {
38-
showErrorCodes = _showErrorCodes
39-
}))
42+
showErrorCodes = _showErrorCodes;
43+
}));
4044
subscriptions.add(atom.config.observe('linter-julia.ignoreIssueCodes', (_ignoreIssueCodes) => {
41-
ignoreIssueCodes = _ignoreIssueCodes
42-
}))
45+
ignoreIssueCodes = _ignoreIssueCodes;
46+
}));
4347
}
4448

4549
export function deactivate() {
4650
if (spawnedServer) {
47-
terminateServer(spawnedServer)
48-
spawnedServer = null
51+
terminateServer(spawnedServer);
52+
spawnedServer = null;
4953
}
5054
if (subscriptions) {
51-
subscriptions.dispose()
55+
subscriptions.dispose();
5256
}
5357
}
5458

@@ -60,45 +64,48 @@ export function provideLinter() {
6064
grammarScopes: ['source.julia'],
6165
async lint(textEditor: Object) {
6266
if (!spawnedServer) {
63-
spawnedServer = await spawnServer(atom.config.get('linter-julia.executablePath'))
67+
spawnedServer = await spawnServer(atom.config.get('linter-julia.executablePath'));
6468
}
65-
const connection = net.createConnection(spawnedServer.path)
66-
connection.on('connect', function() {
69+
const connection = net.createConnection(spawnedServer.path);
70+
connection.on('connect', () => {
6771
this.write(JSON.stringify({
6872
file: textEditor.getPath(),
6973
code_str: textEditor.getText(),
7074
show_code: showErrorCodes,
7175
ignore_info: ignoreInfo,
7276
ignore_codes: ignoreIssueCodes,
7377
ignore_warnings: ignoreWarning,
74-
}))
75-
})
78+
}));
79+
});
7680

77-
return new Promise(function(resolve, reject) {
78-
setTimeout(function() {
81+
return new Promise(((resolve, reject) => {
82+
setTimeout(() => {
7983
// This is the timeout because net.Socket doesn't have one for connections
80-
reject(new Error('Request timed out'))
81-
connection.end()
82-
}, 60 * 1000)
83-
connection.on('error', reject)
84+
reject(new Error('Request timed out'));
85+
connection.end();
86+
}, 60 * 1000);
87+
connection.on('error', reject);
8488

85-
const data = []
86-
connection.on('data', function(chunk) {
87-
data.push(chunk)
88-
})
89-
connection.on('close', function() {
90-
let parsed
91-
const merged = data.join('')
89+
const data = [];
90+
connection.on('data', (chunk) => {
91+
data.push(chunk);
92+
});
93+
connection.on('close', () => {
94+
let parsed;
95+
const merged = data.join('');
9296
try {
93-
parsed = JSON.parse(merged)
97+
parsed = JSON.parse(merged);
9498
} catch (_) {
95-
console.error('[Linter-Julia] Server returned non-JSON response: ', merged)
96-
reject(new Error('Error parsing server response. See console for more info'))
97-
return
99+
const msg = '[Linter-Julia] Server returned non-JSON response';
100+
atom.notifications.addError(`${msg}. See console for more info`);
101+
// eslint-disable-next-line no-console
102+
console.error(`${msg}: `, merged);
103+
resolve(null);
104+
return;
98105
}
99-
resolve(parsed)
100-
})
101-
})
106+
resolve(parsed);
107+
});
108+
}));
102109
},
103-
}
110+
};
104111
}

lib/server.js

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,70 @@
11
/* @flow */
22

3-
import os from 'os'
4-
import FS from 'fs'
5-
import Path from 'path'
6-
import uuid from 'uuid4'
7-
import { async as getAsyncEnv } from 'consistent-env'
8-
import { BufferedProcess, Disposable, CompositeDisposable } from 'atom'
9-
import type { Server } from './types'
3+
import os from 'os';
4+
import FS from 'fs';
5+
import Path from 'path';
6+
import uuid from 'uuid4';
7+
import { async as getAsyncEnv } from 'consistent-env';
8+
import { BufferedProcess, Disposable, CompositeDisposable } from 'atom';
9+
import type { Server } from './types';
1010

11-
const JULIA_SERVER_PATH = Path.join(__dirname, 'julia-server.jl')
11+
const JULIA_SERVER_PATH = Path.join(__dirname, 'julia-server.jl');
1212

1313
export async function getPipePath(): Promise<string> {
14-
const baseDir = process.platform === 'win32' ? '\\\\.\\pipe\\' : `${os.tmpdir()}/`
15-
const uniqueId = uuid.sync()
16-
return baseDir + uniqueId
14+
const baseDir = process.platform === 'win32' ? '\\\\.\\pipe\\' : `${os.tmpdir()}/`;
15+
const uniqueId = uuid.sync();
16+
return baseDir + uniqueId;
1717
}
1818

1919
export async function spawnServer(juliaExecutable: string): Promise<Server> {
20-
const path = await getPipePath()
20+
const path = await getPipePath();
2121
const server = {
2222
pid: 0,
2323
path,
2424
subscriptions: new CompositeDisposable(),
25-
}
26-
const processEnv = await getAsyncEnv()
25+
};
26+
const processEnv = await getAsyncEnv();
2727

28-
await new Promise(function(resolve, reject) {
29-
const data = { stdout: '', stderr: '', resolved: false }
28+
await new Promise(((resolve, reject) => {
29+
const data = { stdout: '', stderr: '', resolved: false };
3030
const spawnedProcess = new BufferedProcess({
3131
command: juliaExecutable,
3232
args: [JULIA_SERVER_PATH, path],
3333
options: { env: processEnv },
3434
stdout(chunk) {
35-
data.stdout += chunk.toString('utf8')
35+
data.stdout += chunk.toString('utf8');
3636
if (!data.resolved && data.stdout.includes('Server running on port')) {
37-
data.resolved = true
38-
resolve()
37+
data.resolved = true;
38+
resolve();
3939
}
4040
},
4141
stderr(chunk) {
42-
data.stderr += chunk.toString('utf8')
42+
data.stderr += chunk.toString('utf8');
4343
},
4444
exit(exitCode) {
45-
console.debug('[Linter-Julia] Server exited with code:', exitCode, 'STDOUT:', data.stdout, 'STDERR:', data.stderr)
45+
// eslint-disable-next-line no-console
46+
console.debug(
47+
'[Linter-Julia] Server exited with code:', exitCode,
48+
'STDOUT:', data.stdout,
49+
'STDERR:', data.stderr,
50+
);
4651
},
47-
})
52+
});
4853

49-
server.pid = spawnedProcess.process.pid
50-
spawnedProcess.process.on('error', reject)
51-
server.subscriptions.add(new Disposable(function() {
52-
spawnedProcess.kill()
53-
FS.access(path, FS.R_OK, function(error) {
54-
if (error) return
55-
FS.unlink(path, function() { /* No Op */ })
56-
})
57-
}))
58-
})
54+
server.pid = spawnedProcess.process.pid;
55+
spawnedProcess.process.on('error', reject);
56+
server.subscriptions.add(new Disposable((() => {
57+
spawnedProcess.kill();
58+
FS.access(path, FS.R_OK, (error) => {
59+
if (error) return;
60+
FS.unlink(path, () => { /* No Op */ });
61+
});
62+
})));
63+
}));
5964

60-
return server
65+
return server;
6166
}
6267

6368
export function terminateServer(server: Server): void {
64-
server.subscriptions.dispose()
69+
server.subscriptions.dispose();
6570
}

0 commit comments

Comments
 (0)