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

Commit

Permalink
feat: update to Linter v2 API
Browse files Browse the repository at this point in the history
Update to the v2 Linter API, allowing this provider to continue working 
with recent builds of linter.
  • Loading branch information
Arcanemagus committed Jan 17, 2019
1 parent 781f06e commit 9d31471
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
23 changes: 16 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let disableWhenNoHtmlhintConfig;

// Internal variables
const phpEmbeddedScope = 'text.html.php';
const validSeverities = ['info', 'warning', 'error'];

// Internal functions
const getConfig = async (filePath) => {
Expand Down Expand Up @@ -111,7 +112,7 @@ export default {
name: 'htmlhint',
grammarScopes: this.grammarScopes,
scope: 'file',
lintOnFly: true,
lintsOnChange: true,
lint: async (editor) => {
if (!atom.workspace.isTextEditor(editor)) {
return null;
Expand Down Expand Up @@ -146,12 +147,20 @@ export default {
return null;
}

return messages.map(message => ({
range: generateRange(editor, message.line - 1, message.col - 1),
type: message.type,
text: message.message,
filePath
}));
return messages.map((message) => {
let severity = message.type.toLowerCase();
if (!validSeverities.includes(severity)) {
severity = 'error';
}
return ({
severity,
excerpt: message.message,
location: {
file: filePath,
position: generateRange(editor, message.line - 1, message.col - 1)
}
});
});
}
};
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@
}
},
"package-deps": [
"linter"
"linter:2.0.0"
],
"providedServices": {
"linter": {
"versions": {
"1.0.0": "provideLinter"
"2.0.0": "provideLinter"
}
}
},
Expand Down
8 changes: 4 additions & 4 deletions spec/linter-htmlhint-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ describe('The htmlhint provider for Linter', () => {
const messages = await lint(editor);

expect(messages.length).toEqual(1);
expect(messages[0].type).toBe('error');
expect(messages[0].text).toBe('Doctype must be declared first.');
expect(messages[0].filePath).toBe(badFile);
expect(messages[0].range).toEqual([[0, 0], [0, 5]]);
expect(messages[0].severity).toBe('error');
expect(messages[0].excerpt).toBe('Doctype must be declared first.');
expect(messages[0].location.file).toBe(badFile);
expect(messages[0].location.position).toEqual([[0, 0], [0, 5]]);
});

it('finds nothing wrong with a valid file (good.html)', async () => {
Expand Down

0 comments on commit 9d31471

Please sign in to comment.