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

Commit

Permalink
Add .yaspellerrc.js and .yaspellerrc.json for project config
Browse files Browse the repository at this point in the history
  • Loading branch information
hcodes committed Apr 4, 2020
1 parent 95cea29 commit 1a9dbb8
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 23 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -160,6 +160,8 @@ To run the linter:<br/>
`yaspeller` is configured using JSON file at the root of the project:

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

Expand Down
2 changes: 2 additions & 0 deletions README.ru.md
Expand Up @@ -151,6 +151,8 @@ JSON-файл собственного словаря.
`yaspeller` настраивается, используя JSON-файл, расположенный в корне проекта:

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

Expand Down
4 changes: 3 additions & 1 deletion lib/config/index.js
Expand Up @@ -37,8 +37,10 @@ function getConfig(file) {
},
searchPlaces: [
'package.json',
'.yaspeller.json',
'.yaspellerrc',
'.yaspeller.json'
'.yaspellerrc.js',
'.yaspellerrc.json',
]
});

Expand Down
51 changes: 31 additions & 20 deletions test/config.test.js
Expand Up @@ -16,49 +16,60 @@ afterEach(function() {
});

describe('Config', function() {
it('get, custom config', function() {
assert.deepEqual(getConfig('./test/json/no_comment.json'), {
relativePath: 'test/json/no_comment.json',
data: ['1']
});
});

it('get, custom config with comments', function() {
assert.deepEqual(getConfig('./test/json/comment.json'), {
relativePath: 'test/json/comment.json',
data: ['1']
it('getConfig, custom config with comments', function() {
assert.deepEqual(getConfig('./test/configs/comment.json'), {
relativePath: 'test/configs/comment.json',
data: { report: ['console'] }
});
});

it('get, default config', function() {
it('getConfig, default config', function() {
const result = getConfig(null);
assert.equal(result.relativePath, '.yaspellerrc');
assert.ok(Object.keys(result.data).length);
});

it('get, throw', function() {
getConfig('test/json/error_parsing.json');
it('getConfig, throw', function() {
getConfig('test/configs/error_parsing.json');

assert.equal(process.exit.args[0], exitCodes.ERROR_CONFIG);
});

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

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

it('get, wrong property type', function() {
getConfig('test/json/wrong_prop_type.json');
it('getConfig, wrong property type', function() {
getConfig('test/configs/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');
it('getConfig from package.json', function() {
process.chdir('./test/configs');
assert.deepEqual(getConfig(null).data, { lang: 'en,ru' });
process.chdir('../../');
});

it('getConfig from yaspellerrc.js', function() {
process.chdir('./test/configs/rc.js');
assert.deepEqual(getConfig(null).data, { report: ['rc.js'] });
process.chdir('../../../');
});

it('getConfig from yaspellerrc.json', function() {
process.chdir('./test/configs/json');
assert.deepEqual(getConfig(null).data, { report: ['json'] });
process.chdir('../../../');
});

it('getConfig from yaspellerrc', function() {
process.chdir('./test/configs/rc');
assert.deepEqual(getConfig(null).data, { report: ['rc'] });
process.chdir('../../../');
});
});
3 changes: 3 additions & 0 deletions test/configs/comment.json
@@ -0,0 +1,3 @@
{
"report": ["console"] // comment
}
3 changes: 3 additions & 0 deletions test/configs/error_parsing.json
@@ -0,0 +1,3 @@
{
"report": ["console" // comment
}
3 changes: 3 additions & 0 deletions test/configs/json/.yaspellerrc.json
@@ -0,0 +1,3 @@
{
"report": ["json"]
}
File renamed without changes.
3 changes: 3 additions & 0 deletions test/configs/rc.js/.yaspellerrc.js
@@ -0,0 +1,3 @@
module.exports = {
report: ['rc.js'],
};
3 changes: 3 additions & 0 deletions test/configs/rc/.yaspellerrc
@@ -0,0 +1,3 @@
{
"report": ["rc"]
}
Expand Up @@ -17,4 +17,3 @@
"lang": "en,ru",
"report": ["console"]
}

Expand Up @@ -16,4 +16,3 @@
"lang": "en,ru",
"report": ["console"]
}

0 comments on commit 1a9dbb8

Please sign in to comment.