Skip to content

Commit

Permalink
Add settings and parser options (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
wmertens authored and sindresorhus committed Oct 11, 2016
1 parent fa99f36 commit 85c6094
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
12 changes: 11 additions & 1 deletion options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function normalizeOpts(opts) {
'ignore',
'plugin',
'rule',
'setting',
'extend',
'extension'
].forEach(singular => {
Expand All @@ -64,7 +65,7 @@ function normalizeOpts(opts) {
return;
}

if (singular !== 'rule') {
if (singular !== 'rule' && singular !== 'setting') {
value = arrify(value);
}

Expand All @@ -84,6 +85,7 @@ function mergeWithPkgConf(opts) {
function emptyOptions() {
return {
rules: {},
settings: {},
globals: [],
envs: [],
plugins: [],
Expand Down Expand Up @@ -122,10 +124,18 @@ function buildConfig(opts) {
config.baseConfig.extends = ['xo/esnext', path.join(__dirname, 'config/plugins.js')];
}

if (opts.parser) {
config.baseConfig.parser = opts.parser;
}

if (opts.rules) {
Object.assign(config.rules, opts.rules);
}

if (opts.settings) {
config.baseConfig.settings = opts.settings;
}

if (opts.extends && opts.extends.length > 0) {
// TODO: this logic needs to be improved, preferably use the same code as ESLint
// user's configs must be resolved to their absolute paths
Expand Down
11 changes: 11 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ Override any of the [default rules](https://github.com/sindresorhus/eslint-confi

Please take a moment to consider if you really need to use this option.

### settings

Type: `object`

Anything you put here gets passed to `settings` in the ESLint configuration; some of the ESLint plugins use this. For example, to configure the `import` ruleset to use the webpack configuration for determining search paths, you can put `{'import/resolver': 'webpack'}` here.

### semicolon

Type: `boolean`<br>
Expand All @@ -205,6 +211,11 @@ Type: `Array`

Allow more extensions to be linted besides `.js` and `.jsx`. Make sure they're supported by ESLint or an ESLint plugin.

### parser

Type: `string`

Tell ESLint what parser to use, e.g. `"babel-eslint"` if you are using language features that ESLint doesn't support yet.

## Config Overrides

Expand Down
14 changes: 14 additions & 0 deletions test/options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ test('normalizeOpts: makes all the opts plural and arrays', t => {
ignore: 'test.js',
plugin: 'my-plugin',
rule: {'my-rule': 'foo'},
setting: {'my-rule': 'bar'},
extend: 'foo',
extension: 'html'
});
Expand All @@ -25,6 +26,7 @@ test('normalizeOpts: makes all the opts plural and arrays', t => {
ignores: ['test.js'],
plugins: ['my-plugin'],
rules: {'my-rule': 'foo'},
settings: {'my-rule': 'bar'},
extends: ['foo'],
extensions: ['html']
});
Expand Down Expand Up @@ -74,6 +76,18 @@ test('buildConfig: rules', t => {
t.deepEqual(config.rules, rules);
});

test('buildConfig: parser', t => {
const parser = 'babel-eslint';
const config = manager.buildConfig({parser});
t.deepEqual(config.baseConfig.parser, parser);
});

test('buildConfig: settings', t => {
const settings = {'import/resolver': 'webpack'};
const config = manager.buildConfig({settings});
t.deepEqual(config.baseConfig.settings, settings);
});

test('findApplicableOverrides', t => {
const result = manager.findApplicableOverrides('/user/dir/foo.js', [
{files: '**/f*.js'},
Expand Down

0 comments on commit 85c6094

Please sign in to comment.