This repository has been archived by the owner on Aug 7, 2023. It is now read-only.
/
helpers.js
85 lines (67 loc) · 2.27 KB
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
'use strict';
'use babel';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.spawnWorker = spawnWorker;
exports.showError = showError;
exports.idsToIgnoredRules = idsToIgnoredRules;
exports.validatePoint = validatePoint;
var _child_process = require('child_process');
var _child_process2 = _interopRequireDefault(_child_process);
var _processCommunication = require('process-communication');
var _path = require('path');
var _atom = require('atom');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var RULE_OFF_SEVERITY = 0;
// eslint-disable-next-line import/no-extraneous-dependencies, import/extensions
function spawnWorker() {
var env = Object.create(process.env);
delete env.NODE_PATH;
delete env.NODE_ENV;
delete env.OS;
var child = _child_process2.default.fork((0, _path.join)(__dirname, 'worker.js'), [], { env: env, silent: true });
var worker = (0, _processCommunication.createFromProcess)(child);
child.stdout.on('data', function (chunk) {
console.log('[Linter-ESLint] STDOUT', chunk.toString());
});
child.stderr.on('data', function (chunk) {
console.log('[Linter-ESLint] STDERR', chunk.toString());
});
return {
worker: worker,
subscription: new _atom.Disposable(function () {
worker.kill();
})
};
}
function showError(givenMessage) {
var givenDetail = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var detail = void 0;
var message = void 0;
if (message instanceof Error) {
detail = message.stack;
message = message.message;
} else {
detail = givenDetail;
message = givenMessage;
}
atom.notifications.addError('[Linter-ESLint] ' + message, {
detail: detail,
dismissable: true
});
}
function idsToIgnoredRules() {
var ruleIds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
return ruleIds.reduce(function (ids, id) {
ids[id] = RULE_OFF_SEVERITY;
return ids;
}, {});
}
function validatePoint(textEditor, line, col) {
var buffer = textEditor.getBuffer();
// Clip the given point to a valid one, and check if it equals the original
if (!buffer.clipPosition([line, col]).isEqual([line, col])) {
throw new Error(line + ':' + col + ' isn\'t a valid point!');
}
}