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

Commit cd8f19b

Browse files
authored
Merge pull request #78 from AtomLinter/es6-rewrite
Rewrite in ES2015
2 parents fe1d933 + 923369e commit cd8f19b

File tree

4 files changed

+106
-78
lines changed

4 files changed

+106
-78
lines changed

lib/main.coffee

Lines changed: 0 additions & 73 deletions
This file was deleted.

lib/main.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
'use babel';
2+
3+
/* eslint-disable import/no-extraneous-dependencies, import/extensions */
4+
import { CompositeDisposable } from 'atom';
5+
/* eslint-enable import/no-extraneous-dependencies, import/extensions */
6+
7+
// Some internal variables
8+
const baseUrl = 'https://github.com/koalaman/shellcheck/wiki';
9+
const errorCodeRegex = /SC\d{4}/;
10+
const regex = /.+?:(\d+):(\d+):\s(\w+?):\s(.+)/g;
11+
12+
const linkifyErrorCode = text =>
13+
text.replace(errorCodeRegex, `<a href="${baseUrl}/$&">$&</a>`);
14+
15+
export default {
16+
activate() {
17+
require('atom-package-deps').install('linter-shellcheck');
18+
19+
this.subscriptions = new CompositeDisposable();
20+
this.subscriptions.add(
21+
atom.config.observe('linter-shellcheck.shellcheckExecutablePath', (value) => {
22+
this.executablePath = value;
23+
})
24+
);
25+
this.subscriptions.add(
26+
atom.config.observe('linter-shellcheck.enableNotice', (value) => {
27+
this.enableNotice = value;
28+
})
29+
);
30+
this.subscriptions.add(
31+
atom.config.observe('linter-shellcheck.userParameters', (value) => {
32+
this.userParameters = value.trim().split(' ').filter(Boolean);
33+
})
34+
);
35+
},
36+
37+
deactivate() {
38+
this.subscriptions.dispose();
39+
},
40+
41+
provideLinter() {
42+
const helpers = require('atom-linter');
43+
const path = require('path');
44+
45+
return {
46+
name: 'ShellCheck',
47+
grammarScopes: ['source.shell'],
48+
scope: 'file',
49+
lintOnFly: true,
50+
lint: (textEditor) => {
51+
const filePath = textEditor.getPath();
52+
const text = textEditor.getText();
53+
const cwd = path.dirname(filePath);
54+
const showAll = this.enableNotice;
55+
// The first -f parameter overrides any others
56+
const parameters = [].concat(['-f', 'gcc'], this.userParameters, ['-']);
57+
const options = { stdin: text, cwd, ignoreExitCode: true };
58+
return helpers.exec(this.executablePath, parameters, options).then((output) => {
59+
if (textEditor.getText() !== text) {
60+
// The text has changed since the lint was triggered, tell Linter not to update
61+
return null;
62+
}
63+
const messages = [];
64+
let match = regex.exec(output);
65+
while (match !== null) {
66+
const type = match[3];
67+
if (showAll || type === 'warning' || type === 'error') {
68+
const line = Number.parseInt(match[1], 10) - 1;
69+
const col = Number.parseInt(match[2], 10) - 1;
70+
messages.push({
71+
type,
72+
filePath,
73+
range: helpers.rangeFromLineNumber(textEditor, line, col),
74+
html: linkifyErrorCode(match[4]),
75+
});
76+
}
77+
match = regex.exec(output);
78+
}
79+
return messages;
80+
});
81+
},
82+
};
83+
},
84+
};

package.json

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
11
{
22
"name": "linter-shellcheck",
3-
"linter-package": true,
4-
"main": "./lib/main",
3+
"main": "./lib/main.js",
54
"version": "1.4.0",
65
"description": "Lint Bash on the fly, using shellcheck",
76
"repository": "https://github.com/AtomLinter/linter-shellcheck",
87
"license": "MIT",
98
"engines": {
10-
"atom": ">=1.0.0 <2.0.0"
9+
"atom": ">=1.4.0 <2.0.0"
1110
},
1211
"scripts": {
1312
"test": "apm test",
14-
"lint": "coffeelint lib && eslint spec"
13+
"lint": "eslint ."
14+
},
15+
"configSchema": {
16+
"shellcheckExecutablePath": {
17+
"type": "string",
18+
"title": "Shellcheck Executable Path",
19+
"default": "shellcheck"
20+
},
21+
"userParameters": {
22+
"type": "string",
23+
"title": "Additional Executable Parameters",
24+
"description": "Additional shellcheck parameters, for example `-x -e SC1090`.",
25+
"default": ""
26+
},
27+
"enableNotice": {
28+
"type": "boolean",
29+
"title": "Enable Notice Messages",
30+
"default": false
31+
}
1532
},
1633
"dependencies": {
1734
"atom-linter": "^8.0.0",

spec/linter-shellcheck-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const cleanPath = path.join(__dirname, 'fixtures', 'clean.sh');
66
const badPath = path.join(__dirname, 'fixtures', 'bad.sh');
77

88
describe('The ShellCheck provider for Linter', () => {
9-
const lint = require('../lib/main.coffee').provideLinter().lint;
9+
const lint = require('../lib/main.js').provideLinter().lint;
1010

1111
beforeEach(() => {
1212
atom.workspace.destroyActivePaneItem();

0 commit comments

Comments
 (0)