Skip to content

Commit

Permalink
Add a global config setting (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Ehlers authored and jwilsson committed Nov 23, 2016
1 parent 2fddc05 commit d2bd9f0
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ This plugin for linter provides an interface to [lesshint](https://github.com/le
```bash
$ apm install linter-lesshint
```

## Config
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.
25 changes: 24 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import path from 'path';
import configLoader from 'lesshint/lib/config-loader';
import os from 'os';

export default class LinterLesshint {
static config = {
Expand All @@ -10,12 +11,30 @@ export default class LinterLesshint {
title: 'Disable linter when no `.lesshintrc` is found in project.',
type: 'boolean',
},
globalConfig: {
default: false,
title: 'Use a global configuration file?',
type: 'boolean',
},
globalConfigDir: {
default: os.homedir(),
title: 'Path to directory of global configuration file',
type: 'string',
}
}

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

static get globalConfigDir () {
return atom.config.get('linter-lesshint.globalConfigDir');
}

static get globalConfig () {
return atom.config.get('linter-lesshint.globalConfig');
}

static activate () {
require('atom-package-deps').install('linter-lesshint');
}
Expand All @@ -33,7 +52,11 @@ export default class LinterLesshint {
const lesshint = new Lesshint();
const text = editor.getText();
const filePath = editor.getPath();
const configFile = await Helpers.findCachedAsync(path.dirname(filePath), '.lesshintrc');
let configFile = await Helpers.findCachedAsync(path.dirname(filePath), '.lesshintrc');

if (!configFile && this.globalConfig) {
configFile = await Helpers.findCachedAsync(this.globalConfigDir, '.lesshintrc');
}

if (!configFile && this.onlyWithRc) {
return [];
Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/invalid-global.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.foo {
color: red;
}
6 changes: 6 additions & 0 deletions spec/fixtures/lesshintrc/.lesshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"spaceAfterPropertyColon": {
"enabled": true,
"style": "no_space"
}
}
3 changes: 3 additions & 0 deletions spec/fixtures/valid-global.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.foo {
color:red;
}
63 changes: 63 additions & 0 deletions spec/linter-lesshint-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,67 @@ describe('The lesshint provider for Linter', () => {
});
});
});

describe('globalConfig setting', () => {
let editor;

beforeEach(() => {
atom.config.set('linter-lesshint.globalConfigDir', `${__dirname}/fixtures/lesshintrc`);
});

describe('valid file', () => {
beforeEach(() => {
waitsForPromise(() => {
return atom.workspace.open(`${__dirname}/fixtures/valid-global.less`).then((openEditor) => {
editor = openEditor;
});
});
});
it('checks with global config when enabled', () => {
atom.config.set('linter-lesshint.globalConfig', true);
waitsForPromise(() => {
return lint(editor).then((messages) => {
expect(messages.length).toEqual(0);
});
});
});
it('does not check with global config when disabled', () => {
atom.config.set('linter-lesshint.globalConfig', false);

waitsForPromise(() => {
return lint(editor).then((messages) => {
expect(messages.length).toEqual(1);
});
});
});
});


describe('valid file', () => {
beforeEach(() => {
waitsForPromise(() => {
return atom.workspace.open(`${__dirname}/fixtures/invalid-global.less`).then((openEditor) => {
editor = openEditor;
});
});
});

it('checks with global config when enabled', () => {
atom.config.set('linter-lesshint.globalConfig', true);
waitsForPromise(() => {
return lint(editor).then((messages) => {
expect(messages.length).toEqual(1);
});
});
});
it('does not check with global config when disabled', () => {
atom.config.set('linter-lesshint.globalConfig', false);
waitsForPromise(() => {
return lint(editor).then((messages) => {
expect(messages.length).toEqual(0);
});
});
});
});
});
});

0 comments on commit d2bd9f0

Please sign in to comment.