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

Fix: Summary formatter always used #1290

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 10 additions & 0 deletions packages/hint/docs/user-guide/concepts/configurations.md
Original file line number Diff line number Diff line change
@@ -45,3 +45,13 @@ the `summary` formatter:
"formatters": ["summary"]
}
```

Notes:

* If you define the property `formatters` when extending
a configuration, the formatters in the configuration will be
replaced with the value you have defined.

* If you define the property `parsers` when extending a
configuration, the parsers in the configuration will be appended
to the values you have defined.
18 changes: 12 additions & 6 deletions packages/hint/src/lib/config.ts
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ import * as os from 'os';
import * as path from 'path';

import * as browserslist from 'browserslist';
import { merge } from 'lodash';
import { mergeWith } from 'lodash';

import { UserConfig, IgnoredUrl, CLIOptions, ConnectorConfig, HintsConfigObject } from './types';
import { debug as d } from './utils/debug';
@@ -88,13 +88,19 @@ const composeConfig = (userConfig: UserConfig) => {
return composeConfig(loadedConfiguration);
});

const finalConfig: UserConfig = merge({}, ...configurations, userConfig);
const finalConfig: UserConfig = mergeWith({}, ...configurations, userConfig, (objValue, srcValue) => {
// Arrays need to be concatented, not merged.
if (Array.isArray(objValue) && Array.isArray(srcValue)) {
return objValue.concat(srcValue);
}

// Otherwise the output could be double or we could trigger double events
if (finalConfig.formatters) {
finalConfig.formatters = Array.from(new Set(finalConfig.formatters));
}
return void 0;
});

// The formatters defined by the user has to overwritte the one in the extends.
finalConfig.formatters = userConfig.formatters ? userConfig.formatters : finalConfig.formatters;

// Otherwise the output could be double or we could trigger double events
if (finalConfig.parsers) {
finalConfig.parsers = Array.from(new Set(finalConfig.parsers));
}
1 change: 1 addition & 0 deletions packages/hint/tests/lib/config.ts
Original file line number Diff line number Diff line change
@@ -217,6 +217,7 @@ test.serial(`if the configuration file contains an extends property, it should c
t.is((configuration.connector as ConnectorConfig).name, 'chrome');
t.is(configuration.hints['disallowed-headers'], 'error');
t.is(configuration.formatters.length, 1);
t.is(configuration.parsers.length, 2);
});


3 changes: 3 additions & 0 deletions packages/hint/tests/lib/fixtures/valid/package.json
Original file line number Diff line number Diff line change
@@ -10,6 +10,9 @@
"formatters": [
"json"
],
"parsers": [
"javascript"
],
"hints": {
"disallowed-headers": ["warning", {}],
"manifest-exists": "warning",
3 changes: 3 additions & 0 deletions packages/hint/tests/lib/fixtures/valid/withextends.json
Original file line number Diff line number Diff line change
@@ -11,6 +11,9 @@
"formatters": [
"json"
],
"parsers": [
"typescript"
],
"hints": {
"disallowed-headers": "error"
}