Skip to content

Commit f12d13f

Browse files
wohanleyjwilsson
authored andcommitted
Notify the user when lesshint can't check a file (#18)
Closes #17
1 parent f453c21 commit f12d13f

File tree

3 files changed

+52
-15
lines changed

3 files changed

+52
-15
lines changed

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ export default class LinterLesshint {
5858
try {
5959
errors = lesshint.checkString(text, filePath);
6060
} catch (e) {
61-
// Empty
61+
atom.notifications.addError("lesshint couldn't check this file.", {
62+
detail: e.stack,
63+
dismissable: true
64+
});
6265
}
6366

6467
return errors.map(({ linter, message, line, column, severity }) => {

spec/fixtures/lesshint-breaker.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// lesshint wow

spec/linter-lesshint-spec.js

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,36 @@ describe('The lesshint provider for Linter', () => {
1313
});
1414
});
1515

16+
describe('lesshint-breaking files checks', () => {
17+
let editor;
18+
19+
beforeEach(() => {
20+
waitsForPromise(() => {
21+
return atom.workspace.open(`${__dirname}/fixtures/lesshint-breaker.less`).then((openEditor) => {
22+
editor = openEditor;
23+
});
24+
});
25+
});
26+
27+
it('fails file that breaks lesshint', () => {
28+
waitsForPromise(() => {
29+
30+
const priorNotificationsCount = atom.notifications.getNotifications().length;
31+
32+
return lint(editor).then(() => {
33+
34+
const notifications = atom.notifications.getNotifications();
35+
36+
expect(notifications[priorNotificationsCount].getType()).toEqual('error');
37+
expect(notifications[priorNotificationsCount].getMessage()).toEqual('lesshint couldn\'t check this file.');
38+
});
39+
});
40+
});
41+
});
42+
1643
describe('invalid files checks', () => {
44+
const Range = require('atom').Range;
45+
1746
let editor;
1847

1948
beforeEach(() => {
@@ -28,16 +57,16 @@ describe('The lesshint provider for Linter', () => {
2857
const errorName = 'emptyRule';
2958
const errorMessage = "There shouldn't be any empty rules present.";
3059

31-
lint(editor).then((messages) => {
32-
expect(messages[0].type).toBeDefined();
33-
expect(messages[0].type).toEqual('warning');
34-
expect(messages[0].html).toBeDefined();
35-
expect(messages[0].html).toEqual(`<span class='badge badge-flexible'>${errorName}</span> ${errorMessage}`);
36-
expect(messages[0].filePath).toBeDefined();
37-
expect(messages[0].filePath).toMatch(/.+invalid\.less$/);
38-
expect(messages[0].range).toBeDefined();
39-
expect(messages[0].range.length).toEqual(2);
40-
expect(messages[0].range).toEqual([[1, 0], [1, 4]]);
60+
waitsForPromise(() => {
61+
return lint(editor).then((messages) => {
62+
expect(messages[0].type).toBeDefined();
63+
expect(messages[0].type).toEqual('warning');
64+
expect(messages[0].html).toBeDefined();
65+
expect(messages[0].html).toEqual(`<span class='badge badge-flexible'>${errorName}</span> ${errorMessage}`);
66+
expect(messages[0].filePath).toBeDefined();
67+
expect(messages[0].filePath).toMatch(/.+invalid\.less$/);
68+
expect(messages[0].range).toEqual(new Range([1, 0], [1, 4]));
69+
});
4170
});
4271
});
4372
});
@@ -54,8 +83,10 @@ describe('The lesshint provider for Linter', () => {
5483
});
5584

5685
it('allows file without errors', () => {
57-
lint(editor).then((messages) => {
58-
expect(messages.length).toEqual(0);
86+
waitsForPromise(() => {
87+
return lint(editor).then((messages) => {
88+
expect(messages.length).toEqual(0);
89+
});
5990
});
6091
});
6192
});
@@ -74,8 +105,10 @@ describe('The lesshint provider for Linter', () => {
74105
});
75106

76107
it('should not check anything when "onlyWithRc" is true and no ".lesshintrc" is found', () => {
77-
lint(editor).then((messages) => {
78-
expect(messages.length).toEqual(0);
108+
waitsForPromise(() => {
109+
return lint(editor).then((messages) => {
110+
expect(messages.length).toEqual(0);
111+
});
79112
});
80113
});
81114
});

0 commit comments

Comments
 (0)