This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
95 lines (80 loc) · 2.09 KB
/
index.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
86
87
88
89
90
91
92
93
94
95
const {CompositeDisposable, Disposable} = require('atom');
const fix = require('./lib/fix.js');
const format = require('./lib/format.js');
const {lint, startWorker, stopWorker} = require('./lib/worker.js');
const SUPPORTED_SCOPES = [
'source.js',
'source.jsx',
'source.js.jsx',
'source.ts',
'source.tsx'
];
function install() {
const callbackId = window.requestIdleCallback(() => {
require('atom-package-deps').install('linter-xo');
startWorker();
});
return new Disposable(() => {
window.cancelIdleCallback(callbackId);
});
}
module.exports.activate = function () {
this.subscriptions = new CompositeDisposable();
this.subscriptions.add(atom.commands.add('atom-text-editor', {
'XO:Fix': () => {
const editor = atom.workspace.getActiveTextEditor();
if (!editor) {
return;
}
fix(editor, lint)(editor.getText());
}
}));
this.subscriptions.add(atom.workspace.observeTextEditors(editor => {
editor.getBuffer().onWillSave(() => {
if (!atom.config.get('linter-xo.fixOnSave')) {
return;
}
const {scopeName} = editor.getGrammar();
if (!SUPPORTED_SCOPES.includes(scopeName)) {
return;
}
return fix(editor, lint)(editor.getText(), atom.config.get('linter-xo.rulesToDisableWhileFixingOnSave'));
});
}));
this.subscriptions.add(install());
};
module.exports.config = {
fixOnSave: {
type: 'boolean',
default: false
},
rulesToDisableWhileFixingOnSave: {
title: 'Disable specific rules while fixing on save',
description: 'Prevent rules from being auto-fixed by XO. Applies to fixes made on save but not when running the `XO:Fix` command.',
type: 'array',
default: [
'capitalized-comments',
'ava/no-only-test',
'ava/no-skip-test'
],
items: {
type: 'string'
}
}
};
module.exports.deactivate = function () {
this.subscriptions.dispose();
stopWorker();
};
module.exports.provideLinter = function () {
return {
name: 'XO',
grammarScopes: SUPPORTED_SCOPES,
scope: 'file',
lintsOnChange: true,
lint: async editor => {
const result = await lint(editor.getPath())(editor.getText());
return format(editor)(result);
}
};
};