Skip to content

Commit

Permalink
Notify the user when lesshint can't check a file (#18)
Browse files Browse the repository at this point in the history
Closes #17
  • Loading branch information
wohanley authored and jwilsson committed Oct 3, 2016
1 parent f453c21 commit f12d13f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 15 deletions.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ export default class LinterLesshint {
try {
errors = lesshint.checkString(text, filePath);
} catch (e) {
// Empty
atom.notifications.addError("lesshint couldn't check this file.", {
detail: e.stack,
dismissable: true
});
}

return errors.map(({ linter, message, line, column, severity }) => {
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/lesshint-breaker.less
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// lesshint wow
61 changes: 47 additions & 14 deletions spec/linter-lesshint-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,36 @@ describe('The lesshint provider for Linter', () => {
});
});

describe('lesshint-breaking files checks', () => {
let editor;

beforeEach(() => {
waitsForPromise(() => {
return atom.workspace.open(`${__dirname}/fixtures/lesshint-breaker.less`).then((openEditor) => {
editor = openEditor;
});
});
});

it('fails file that breaks lesshint', () => {
waitsForPromise(() => {

const priorNotificationsCount = atom.notifications.getNotifications().length;

return lint(editor).then(() => {

const notifications = atom.notifications.getNotifications();

expect(notifications[priorNotificationsCount].getType()).toEqual('error');
expect(notifications[priorNotificationsCount].getMessage()).toEqual('lesshint couldn\'t check this file.');
});
});
});
});

describe('invalid files checks', () => {
const Range = require('atom').Range;

let editor;

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

lint(editor).then((messages) => {
expect(messages[0].type).toBeDefined();
expect(messages[0].type).toEqual('warning');
expect(messages[0].html).toBeDefined();
expect(messages[0].html).toEqual(`<span class='badge badge-flexible'>${errorName}</span> ${errorMessage}`);
expect(messages[0].filePath).toBeDefined();
expect(messages[0].filePath).toMatch(/.+invalid\.less$/);
expect(messages[0].range).toBeDefined();
expect(messages[0].range.length).toEqual(2);
expect(messages[0].range).toEqual([[1, 0], [1, 4]]);
waitsForPromise(() => {
return lint(editor).then((messages) => {
expect(messages[0].type).toBeDefined();
expect(messages[0].type).toEqual('warning');
expect(messages[0].html).toBeDefined();
expect(messages[0].html).toEqual(`<span class='badge badge-flexible'>${errorName}</span> ${errorMessage}`);
expect(messages[0].filePath).toBeDefined();
expect(messages[0].filePath).toMatch(/.+invalid\.less$/);
expect(messages[0].range).toEqual(new Range([1, 0], [1, 4]));
});
});
});
});
Expand All @@ -54,8 +83,10 @@ describe('The lesshint provider for Linter', () => {
});

it('allows file without errors', () => {
lint(editor).then((messages) => {
expect(messages.length).toEqual(0);
waitsForPromise(() => {
return lint(editor).then((messages) => {
expect(messages.length).toEqual(0);
});
});
});
});
Expand All @@ -74,8 +105,10 @@ describe('The lesshint provider for Linter', () => {
});

it('should not check anything when "onlyWithRc" is true and no ".lesshintrc" is found', () => {
lint(editor).then((messages) => {
expect(messages.length).toEqual(0);
waitsForPromise(() => {
return lint(editor).then((messages) => {
expect(messages.length).toEqual(0);
});
});
});
});
Expand Down

0 comments on commit f12d13f

Please sign in to comment.