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

Commit e21748a

Browse files
authored
Merge pull request #148 from AtomLinter/es2015-rewrite
Rewrite in ES2015
2 parents 1f6573c + 8386f95 commit e21748a

File tree

4 files changed

+108
-103
lines changed

4 files changed

+108
-103
lines changed

lib/main.coffee

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

lib/main.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
'use babel';
2+
3+
/* eslint-disable import/extensions, import/no-extraneous-dependencies */
4+
import { CompositeDisposable } from 'atom';
5+
/* eslint-enable import/extensions, import/no-extraneous-dependencies */
6+
7+
let helpers = null;
8+
let path = null;
9+
10+
export default {
11+
activate() {
12+
require('atom-package-deps').install('linter-csslint');
13+
14+
this.subscriptions = new CompositeDisposable();
15+
this.subscriptions.add(
16+
atom.config.observe('linter-csslint.disableTimeout', (value) => {
17+
this.disableTimeout = value;
18+
})
19+
);
20+
},
21+
22+
deactivate() {
23+
this.subscriptions.dispose();
24+
},
25+
26+
provideLinter() {
27+
return {
28+
name: 'CSSLint',
29+
grammarScopes: ['source.css', 'source.html'],
30+
scope: 'file',
31+
lintOnFly: true,
32+
lint(textEditor) {
33+
if (!helpers) {
34+
helpers = require('atom-linter');
35+
}
36+
if (!path) {
37+
path = require('path');
38+
}
39+
const filePath = textEditor.getPath();
40+
const text = textEditor.getText();
41+
if (text.length === 0) {
42+
return Promise.resolve([]);
43+
}
44+
const parameters = ['--format=json', '-'];
45+
const exec = path.join(__dirname, '..', 'node_modules', 'atomlinter-csslint', 'cli.js');
46+
const projectPath = atom.project.relativizePath(filePath)[0];
47+
let cwd = projectPath;
48+
if (!(cwd)) {
49+
cwd = path.dirname(filePath);
50+
}
51+
const options = { stdin: text, cwd };
52+
if (this.disableTimeout) {
53+
options.timeout = Infinity;
54+
}
55+
return helpers.execNode(exec, parameters, options).then((output) => {
56+
if (textEditor.getText() !== text) {
57+
// The editor contents have changed, tell Linter not to update
58+
return null;
59+
}
60+
61+
const toReturn = [];
62+
if (output.length < 1) {
63+
// No output, no errors
64+
return toReturn;
65+
}
66+
67+
const lintResult = JSON.parse(output);
68+
69+
if (lintResult.messages.length < 1) {
70+
// Output, but no errors found
71+
return toReturn;
72+
}
73+
74+
lintResult.messages.forEach((data) => {
75+
let line;
76+
let col;
77+
if (!(data.line && data.col)) {
78+
// Use the file start if a location wasn't defined
79+
[line, col] = [0, 0];
80+
} else {
81+
[line, col] = [data.line - 1, data.col - 1];
82+
}
83+
84+
const msg = {
85+
type: data.type.charAt(0).toUpperCase() + data.type.slice(1),
86+
text: data.message,
87+
filePath,
88+
range: helpers.rangeFromLineNumber(textEditor, line, col),
89+
};
90+
91+
if (data.rule.id && data.rule.desc) {
92+
msg.trace = [{
93+
type: 'Trace',
94+
text: `[${data.rule.id}] ${data.rule.desc}`,
95+
}];
96+
}
97+
toReturn.push(msg);
98+
});
99+
return toReturn;
100+
});
101+
},
102+
};
103+
},
104+
};

package.json

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"description": "Lint CSS on the fly, using csslint",
1212
"repository": "https://github.com/AtomLinter/linter-csslint",
1313
"license": "MIT",
14+
"private": true,
1415
"configSchema": {
1516
"disableTimeout": {
1617
"type": "boolean",
@@ -24,7 +25,6 @@
2425
"atom-package-deps": "^4.0.1"
2526
},
2627
"devDependencies": {
27-
"coffeelint": "^1.15.0",
2828
"eslint": "^3.6.1",
2929
"eslint-config-airbnb-base": "^8.0.0",
3030
"eslint-plugin-import": "^1.16.0"
@@ -57,44 +57,6 @@
5757
"node": true
5858
}
5959
},
60-
"coffeelintConfig": {
61-
"max_line_length": {
62-
"value": 120,
63-
"level": "warn"
64-
},
65-
"no_empty_param_list": {
66-
"level": "error"
67-
},
68-
"arrow_spacing": {
69-
"level": "error"
70-
},
71-
"no_interpolation_in_single_quotes": {
72-
"level": "error"
73-
},
74-
"no_debugger": {
75-
"level": "error"
76-
},
77-
"prefer_english_operator": {
78-
"level": "error"
79-
},
80-
"colon_assignment_spacing": {
81-
"spacing": {
82-
"left": 0,
83-
"right": 1
84-
},
85-
"level": "error"
86-
},
87-
"braces_spacing": {
88-
"spaces": 0,
89-
"level": "error"
90-
},
91-
"spacing_after_comma": {
92-
"level": "error"
93-
},
94-
"no_stand_alone_at": {
95-
"level": "error"
96-
}
97-
},
9860
"providedServices": {
9961
"linter": {
10062
"versions": {

spec/linter-csslint-spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const projectPath = path.join(__dirname, 'fixtures', 'project');
1010
const projectBadPath = path.join(projectPath, 'files', 'badWC.css');
1111

1212
describe('The csslint provider for Linter', () => {
13-
const lint = require('../lib/main.coffee').provideLinter().lint;
13+
const lint = require('../lib/main.js').provideLinter().lint;
1414

1515
beforeEach(() => {
1616
atom.workspace.destroyActivePaneItem();
@@ -44,7 +44,7 @@ describe('The csslint provider for Linter', () => {
4444
expect(messages[0].type).toBe('Warning');
4545
expect(messages[0].text).toBe('Rule is empty.');
4646
expect(messages[0].filePath).toBe(badPath);
47-
expect(messages[0].range).toEqual([[0, 0], [0, 0]]);
47+
expect(messages[0].range).toEqual([[0, 0], [0, 4]]);
4848
})
4949
)
5050
);
@@ -72,7 +72,7 @@ describe('The csslint provider for Linter', () => {
7272
expect(messages[0].type).toBe('Error');
7373
expect(messages[0].text).toBe('Unexpected token \'}\' at line 1, col 1.');
7474
expect(messages[0].filePath).toBe(invalidPath);
75-
expect(messages[0].range).toEqual([[0, 0], [0, 0]]);
75+
expect(messages[0].range).toEqual([[0, 0], [0, 1]]);
7676
})
7777
)
7878
);

0 commit comments

Comments
 (0)