Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Merge 15fc64e into 0d98b63
Browse files Browse the repository at this point in the history
  • Loading branch information
shashkovdanil committed Jul 9, 2018
2 parents 0d98b63 + 15fc64e commit 093bb72
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 22 deletions.
7 changes: 6 additions & 1 deletion README.md
Expand Up @@ -144,7 +144,12 @@ Add the text in `package.json` / `scripts`:<br/>
To run the linter:<br/>
`npm run yaspeller`

Yaspeller is configured using `.yaspellerrc` JSON file at the root of the project.
`yaspeller` is configured using JSON file at the root of the project:

- `.yaspellerrc`
- `.yaspeller.json`
- `package.json`, field `yaspeller`

```JSON
{
"excludeFiles": [
Expand Down
7 changes: 6 additions & 1 deletion README.ru.md
Expand Up @@ -137,7 +137,12 @@ JSON-файл собственного словаря.
Для запуска в качестве линтера:<br/>
`npm run yaspeller`

`yaspeller` настраивается, используя `.yaspellerrc` или `.yaspeller.json`, расположенный в корне проекта.
`yaspeller` настраивается, используя JSON-файл, расположенный в корне проекта:

- `.yaspellerrc`
- `.yaspeller.json`
- `package.json`, поле `yaspeller`

```JSON
{
"excludeFiles": [
Expand Down
20 changes: 12 additions & 8 deletions lib/config.js
@@ -1,11 +1,11 @@
'use strict';

const chalk = require('chalk');
const cosmiconfig = require('cosmiconfig');
const debug = require('./debug');
const printDebug = debug.print;
const exitCodes = require('./exit-codes');
const knownProps = require('./config-properties');
const utils = require('./utils');

module.exports = {
/**
Expand All @@ -15,20 +15,24 @@ module.exports = {
* @returns {Object}
*/
get(file) {
const explorer = cosmiconfig('yaspeller', {
searchPlaces: [
'package.json',
'.yaspellerrc',
'.yaspeller.json'
]
});
let data;

printDebug('Get/check config.');

try {
if (file) {
data = utils.loadFileAsJson(file);
data = explorer.loadSync(file).config;
} else {
file = './.yaspellerrc';
data = utils.loadFileAsJson(file);
if (!data) {
file = './.yaspeller.json';
data = utils.loadFileAsJson(file);
}
const { config, filepath } = explorer.searchSync();
file = filepath;
data = config;
}

printDebug(`Using config: ${file}`);
Expand Down
50 changes: 44 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -35,6 +35,7 @@
"async": "^2.6.1",
"chalk": "^2.4.1",
"commander": "^2.15.1",
"cosmiconfig": "^5.0.5",
"entities": "^1.1.1",
"escape-html": "^1.0.3",
"eyo-kernel": "^2.3.1",
Expand Down Expand Up @@ -70,4 +71,4 @@
".yaspellerrc.default.json",
"LICENSE.md"
]
}
}
2 changes: 1 addition & 1 deletion test/json/no_comment.json
@@ -1,3 +1,3 @@
[
"1" // hello
"1"
]
5 changes: 5 additions & 0 deletions test/json/package.json
@@ -0,0 +1,5 @@
{
"yaspeller": {
"lang": "en,ru"
}
}
2 changes: 1 addition & 1 deletion test/json/unknown_properties.json
Expand Up @@ -16,5 +16,5 @@
"maxRequests": 2,
"lang": "en,ru",
"report": ["console"]
}
}

2 changes: 1 addition & 1 deletion test/json/wrong_prop_type.json
Expand Up @@ -15,5 +15,5 @@
"maxRequests": 2,
"lang": "en,ru",
"report": ["console"]
}
}

10 changes: 8 additions & 2 deletions test/test.config.js
Expand Up @@ -31,15 +31,21 @@ describe('Config', function() {

it('get, unknown properties', function() {
config.get('test/json/unknown_properties.json');

const count = console.error.args.length;
assert.equal(count, 2);
});

it('get, wrong property type', function() {
it('get, wrong property type', function() {
config.get('test/json/wrong_prop_type.json');

const count = console.error.args.length;
assert.equal(count, 2);
});

it('get, config from package.json', function() {
process.chdir('./test/json');
assert.deepEqual(config.get(null), { lang: 'en,ru' });
process.chdir('../../');
});
});

0 comments on commit 093bb72

Please sign in to comment.