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

Commit 1b67722

Browse files
committed
Refactor to a default export
Bring everything into a ES2016 Module export.
1 parent cff8996 commit 1b67722

File tree

1 file changed

+61
-61
lines changed

1 file changed

+61
-61
lines changed

lib/index.js

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,6 @@ const { findAsync, generateRange } = lazyReq('atom-linter')('findAsync', 'genera
1111
const stripJSONComments = lazyReq('strip-json-comments');
1212
const tinyPromisify = lazyReq('tiny-promisify');
1313

14-
const grammarScopes = [];
15-
16-
let subscriptions;
17-
18-
export function activate() {
19-
require('atom-package-deps').install('linter-htmlhint');
20-
21-
subscriptions = new CompositeDisposable();
22-
subscriptions.add(atom.config.observe('linter-htmlhint.enabledScopes', (scopes) => {
23-
// Remove any old scopes
24-
grammarScopes.splice(0, grammarScopes.length);
25-
// Add the current scopes
26-
Array.prototype.push.apply(grammarScopes, scopes);
27-
}));
28-
}
29-
30-
export function deactivate() {
31-
subscriptions.dispose();
32-
}
33-
3414
const getConfig = async (filePath) => {
3515
const readFile = tinyPromisify()(fsReadFile);
3616
const configPath = await findAsync(dirname(filePath), '.htmlhintrc');
@@ -44,45 +24,65 @@ const getConfig = async (filePath) => {
4424
return null;
4525
};
4626

47-
export function provideLinter() {
48-
return {
49-
name: 'htmlhint',
50-
grammarScopes,
51-
scope: 'file',
52-
lintOnFly: true,
53-
lint: async (editor) => {
54-
if (!atom.workspace.isTextEditor(editor)) {
55-
return null;
56-
}
57-
58-
const filePath = editor.getPath();
59-
if (!filePath) {
60-
// Invalid path
61-
return null;
62-
}
63-
64-
const fileText = editor.getText();
65-
if (!fileText) {
66-
return [];
27+
export default {
28+
activate() {
29+
require('atom-package-deps').install('linter-htmlhint');
30+
31+
this.grammarScopes = [];
32+
33+
this.subscriptions = new CompositeDisposable();
34+
this.subscriptions.add(atom.config.observe('linter-htmlhint.enabledScopes', (scopes) => {
35+
// Remove any old scopes
36+
this.grammarScopes.splice(0, this.grammarScopes.length);
37+
// Add the current scopes
38+
Array.prototype.push.apply(this.grammarScopes, scopes);
39+
}));
40+
},
41+
42+
deactivate() {
43+
this.subscriptions.dispose();
44+
},
45+
46+
provideLinter() {
47+
return {
48+
name: 'htmlhint',
49+
grammarScopes: this.grammarScopes,
50+
scope: 'file',
51+
lintOnFly: true,
52+
lint: async (editor) => {
53+
if (!atom.workspace.isTextEditor(editor)) {
54+
return null;
55+
}
56+
57+
const filePath = editor.getPath();
58+
if (!filePath) {
59+
// Invalid path
60+
return null;
61+
}
62+
63+
const fileText = editor.getText();
64+
if (!fileText) {
65+
return [];
66+
}
67+
68+
const { HTMLHint } = require('htmlhint');
69+
70+
const ruleset = await getConfig(filePath);
71+
72+
const messages = HTMLHint.verify(fileText, ruleset || undefined);
73+
74+
if (editor.getText() !== fileText) {
75+
// Editor contents have changed, tell Linter not to update
76+
return null;
77+
}
78+
79+
return messages.map(message => ({
80+
range: generateRange(editor, message.line - 1, message.col - 1),
81+
type: message.type,
82+
text: message.message,
83+
filePath
84+
}));
6785
}
68-
69-
const { HTMLHint } = require('htmlhint');
70-
71-
const ruleset = await getConfig(filePath);
72-
73-
const messages = HTMLHint.verify(fileText, ruleset || undefined);
74-
75-
if (editor.getText() !== fileText) {
76-
// Editor contents have changed, tell Linter not to update
77-
return null;
78-
}
79-
80-
return messages.map(message => ({
81-
range: generateRange(editor, message.line - 1, message.col - 1),
82-
type: message.type,
83-
text: message.message,
84-
filePath
85-
}));
86-
}
87-
};
88-
}
86+
};
87+
}
88+
};

0 commit comments

Comments
 (0)