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
85 lines (72 loc) · 1.77 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
/** @babel */
import {CompositeDisposable} from 'atom';
import {install} from 'atom-package-deps';
import fix from './lib/fix';
import format from './lib/format';
import lint from './lib/lint';
const SUPPORTED_SCOPES = [
'source.js',
'source.jsx',
'source.js.jsx',
'source.ts',
'source.tsx'
];
export function activate() {
install('linter-xo');
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)(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)(editor.getText(), atom.config.get('linter-xo.rulesToDisableWhileFixingOnSave'));
});
}));
}
export const 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'
}
}
};
export function deactivate() {
this.subscriptions.dispose();
}
export function provideLinter() {
return {
name: 'XO',
grammarScopes: SUPPORTED_SCOPES,
scope: 'file',
lintsOnChange: true,
lint: async editor => {
const result = await lint(editor)(editor.getText());
return format(editor)(result);
}
};
}