Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add settings and parser options #142

Merged
merged 2 commits into from
Oct 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function normalizeOpts(opts) {
'ignore',
'plugin',
'rule',
'setting',
'extend',
'extension'
].forEach(singular => {
Expand All @@ -62,7 +63,7 @@ function normalizeOpts(opts) {
return;
}

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

Expand All @@ -82,6 +83,7 @@ function mergeWithPkgConf(opts) {
function emptyOptions() {
return {
rules: {},
settings: {},
globals: [],
envs: [],
plugins: [],
Expand Down Expand Up @@ -120,10 +122,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