Skip to content

Commit d2bd9f0

Browse files
Max Ehlersjwilsson
authored andcommitted
Add a global config setting (#19)
1 parent 2fddc05 commit d2bd9f0

File tree

6 files changed

+102
-1
lines changed

6 files changed

+102
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ This plugin for linter provides an interface to [lesshint](https://github.com/le
88
```bash
99
$ apm install linter-lesshint
1010
```
11+
12+
## Config
13+
When you activate the globalConfig option you can add the config file inside the folder specified in the input field and it will be used for every less file.

index.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import path from 'path';
44
import configLoader from 'lesshint/lib/config-loader';
5+
import os from 'os';
56

67
export default class LinterLesshint {
78
static config = {
@@ -10,12 +11,30 @@ export default class LinterLesshint {
1011
title: 'Disable linter when no `.lesshintrc` is found in project.',
1112
type: 'boolean',
1213
},
14+
globalConfig: {
15+
default: false,
16+
title: 'Use a global configuration file?',
17+
type: 'boolean',
18+
},
19+
globalConfigDir: {
20+
default: os.homedir(),
21+
title: 'Path to directory of global configuration file',
22+
type: 'string',
23+
}
1324
}
1425

1526
static get onlyWithRc () {
1627
return atom.config.get('linter-lesshint.onlyWithRc');
1728
}
1829

30+
static get globalConfigDir () {
31+
return atom.config.get('linter-lesshint.globalConfigDir');
32+
}
33+
34+
static get globalConfig () {
35+
return atom.config.get('linter-lesshint.globalConfig');
36+
}
37+
1938
static activate () {
2039
require('atom-package-deps').install('linter-lesshint');
2140
}
@@ -33,7 +52,11 @@ export default class LinterLesshint {
3352
const lesshint = new Lesshint();
3453
const text = editor.getText();
3554
const filePath = editor.getPath();
36-
const configFile = await Helpers.findCachedAsync(path.dirname(filePath), '.lesshintrc');
55+
let configFile = await Helpers.findCachedAsync(path.dirname(filePath), '.lesshintrc');
56+
57+
if (!configFile && this.globalConfig) {
58+
configFile = await Helpers.findCachedAsync(this.globalConfigDir, '.lesshintrc');
59+
}
3760

3861
if (!configFile && this.onlyWithRc) {
3962
return [];

spec/fixtures/invalid-global.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.foo {
2+
color: red;
3+
}

spec/fixtures/lesshintrc/.lesshintrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"spaceAfterPropertyColon": {
3+
"enabled": true,
4+
"style": "no_space"
5+
}
6+
}

spec/fixtures/valid-global.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.foo {
2+
color:red;
3+
}

spec/linter-lesshint-spec.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,67 @@ describe('The lesshint provider for Linter', () => {
112112
});
113113
});
114114
});
115+
116+
describe('globalConfig setting', () => {
117+
let editor;
118+
119+
beforeEach(() => {
120+
atom.config.set('linter-lesshint.globalConfigDir', `${__dirname}/fixtures/lesshintrc`);
121+
});
122+
123+
describe('valid file', () => {
124+
beforeEach(() => {
125+
waitsForPromise(() => {
126+
return atom.workspace.open(`${__dirname}/fixtures/valid-global.less`).then((openEditor) => {
127+
editor = openEditor;
128+
});
129+
});
130+
});
131+
it('checks with global config when enabled', () => {
132+
atom.config.set('linter-lesshint.globalConfig', true);
133+
waitsForPromise(() => {
134+
return lint(editor).then((messages) => {
135+
expect(messages.length).toEqual(0);
136+
});
137+
});
138+
});
139+
it('does not check with global config when disabled', () => {
140+
atom.config.set('linter-lesshint.globalConfig', false);
141+
142+
waitsForPromise(() => {
143+
return lint(editor).then((messages) => {
144+
expect(messages.length).toEqual(1);
145+
});
146+
});
147+
});
148+
});
149+
150+
151+
describe('valid file', () => {
152+
beforeEach(() => {
153+
waitsForPromise(() => {
154+
return atom.workspace.open(`${__dirname}/fixtures/invalid-global.less`).then((openEditor) => {
155+
editor = openEditor;
156+
});
157+
});
158+
});
159+
160+
it('checks with global config when enabled', () => {
161+
atom.config.set('linter-lesshint.globalConfig', true);
162+
waitsForPromise(() => {
163+
return lint(editor).then((messages) => {
164+
expect(messages.length).toEqual(1);
165+
});
166+
});
167+
});
168+
it('does not check with global config when disabled', () => {
169+
atom.config.set('linter-lesshint.globalConfig', false);
170+
waitsForPromise(() => {
171+
return lint(editor).then((messages) => {
172+
expect(messages.length).toEqual(0);
173+
});
174+
});
175+
});
176+
});
177+
});
115178
});

0 commit comments

Comments
 (0)