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

Commit d8737b7

Browse files
authored
Merge pull request #128 from richardbann/master
Linter v2 Update
2 parents 6b296e8 + 3cb6474 commit d8737b7

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

lib/main.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ const baseUrl = 'https://github.com/koalaman/shellcheck/wiki';
99
const errorCodeRegex = /SC\d{4}/;
1010
const regex = /.+?:(\d+):(\d+):\s(\w+?):\s(.+)/g;
1111

12-
const linkifyErrorCode = text =>
13-
text.replace(errorCodeRegex, `<a href="${baseUrl}/$&">$&</a>`);
12+
const createURL = (text) => {
13+
const match = errorCodeRegex.exec(text);
14+
if (match) {
15+
return `${baseUrl}/${match[0]}`;
16+
}
17+
return undefined;
18+
};
1419

1520
export default {
1621
activate() {
@@ -45,7 +50,7 @@ export default {
4550
name: 'ShellCheck',
4651
grammarScopes: ['source.shell'],
4752
scope: 'file',
48-
lintOnFly: true,
53+
lintsOnChange: true,
4954
lint: (textEditor) => {
5055
if (!atom.workspace.isTextEditor(textEditor)) {
5156
return null;
@@ -84,10 +89,13 @@ export default {
8489
const line = Number.parseInt(match[1], 10) - 1;
8590
const col = Number.parseInt(match[2], 10) - 1;
8691
messages.push({
87-
type,
88-
filePath,
89-
range: helpers.generateRange(textEditor, line, col),
90-
html: linkifyErrorCode(match[4]),
92+
severity: type,
93+
location: {
94+
file: filePath,
95+
position: helpers.generateRange(textEditor, line, col),
96+
},
97+
excerpt: match[4],
98+
url: createURL(match[4]),
9199
});
92100
}
93101
match = regex.exec(output);

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@
7171
}
7272
},
7373
"package-deps": [
74-
"linter"
74+
"linter:2.0.0"
7575
],
7676
"providedServices": {
7777
"linter": {
7878
"versions": {
79-
"1.0.0": "provideLinter"
79+
"2.0.0": "provideLinter"
8080
}
8181
}
8282
}

spec/linter-shellcheck-spec.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ describe('The ShellCheck provider for Linter', () => {
3434
});
3535

3636
it('handles messages from ShellCheck', async () => {
37-
const expectedMsg = 'Tips depend on target shell and yours is unknown. Add a shebang. ' +
38-
'[<a href="https://github.com/koalaman/shellcheck/wiki/SC2148">SC2148</a>]';
37+
const expectedExcerpt = 'Tips depend on target shell and yours is unknown. Add a shebang. [SC2148]';
38+
const expectedURL = 'https://github.com/koalaman/shellcheck/wiki/SC2148';
3939
const editor = await atom.workspace.open(badPath);
4040
const messages = await lint(editor);
4141

4242
expect(messages.length).toBe(1);
43-
expect(messages[0].type).toBe('error');
44-
expect(messages[0].text).not.toBeDefined();
45-
expect(messages[0].html).toBe(expectedMsg);
46-
expect(messages[0].filePath).toBe(badPath);
47-
expect(messages[0].range).toEqual([[0, 0], [0, 4]]);
43+
expect(messages[0].severity).toBe('error');
44+
expect(messages[0].excerpt).toBe(expectedExcerpt);
45+
expect(messages[0].url).toBe(expectedURL);
46+
expect(messages[0].location.file).toBe(badPath);
47+
expect(messages[0].location.position).toEqual([[0, 0], [0, 4]]);
4848
});
4949

5050
describe('implements useProjectCwd and', () => {
@@ -65,7 +65,7 @@ describe('The ShellCheck provider for Linter', () => {
6565
const editor = await atom.workspace.open(sourceFileRelativePath);
6666
const messages = await lint(editor);
6767
expect(messages.length).toBe(1);
68-
expect(messages[0].html).toMatch(/openBinaryFile: does not exist/);
68+
expect(messages[0].excerpt).toMatch(/openBinaryFile: does not exist/);
6969
});
7070

7171
it('uses project-relative source= directives via setting (based at fixtures/)', async () => {
@@ -80,7 +80,7 @@ describe('The ShellCheck provider for Linter', () => {
8080
const editor = await atom.workspace.open(sourceProjectRelativePath);
8181
const messages = await lint(editor);
8282
expect(messages.length).toBe(1);
83-
expect(messages[0].html).toMatch(/openBinaryFile: does not exist/);
83+
expect(messages[0].excerpt).toMatch(/openBinaryFile: does not exist/);
8484
});
8585
});
8686
});

0 commit comments

Comments
 (0)