Skip to content

Commit

Permalink
Fix: Issue with summary formatter always being used
Browse files Browse the repository at this point in the history
Fix #1273
Close #1290
  • Loading branch information
sarvaje authored and alrra committed Sep 5, 2018
1 parent 5cbcb70 commit 43a06a9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
10 changes: 10 additions & 0 deletions packages/hint/docs/user-guide/concepts/configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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';
Expand Down Expand Up @@ -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));
}
Expand Down
1 change: 1 addition & 0 deletions packages/hint/tests/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});


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

0 comments on commit 43a06a9

Please sign in to comment.