Skip to content

Commit

Permalink
fix(transformers): fix filter transformer when used with diff
Browse files Browse the repository at this point in the history
enables configuration of default transformer to persist when used
with a non-"terminal format" transformer, e.g., `diff -t filter` now
works by retaining the table's default configuration (since `filter` is
not a valid output format).
  • Loading branch information
boneskull committed Jan 28, 2020
1 parent bbc9ceb commit 077ce49
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
5 changes: 4 additions & 1 deletion packages/cli/src/commands/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ export const handler = argv => {

fromTransformerChain(argv.transform, config)
.pipe(
transform(source, {beginWith: 'object'}),
transform(source, {
beginWith: 'object',
defaultTransformerConfig: config.transformer.table
}),
toOutput(argv.output, {color: argv.color})
)
.subscribe();
Expand Down
8 changes: 7 additions & 1 deletion packages/cli/src/commands/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ export const handler = argv => {
});

fromTransformerChain(transformer, config)
.pipe(transform(source, {beginWith: 'object'}), toOutput(output, {color}))
.pipe(
transform(source, {
beginWith: 'object',
defaultTransformerConfig: config.transformer.table
}),
toOutput(output, {color})
)
.subscribe();
};
14 changes: 9 additions & 5 deletions packages/cli/src/commands/list-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ export const handler = argv => {
})),
share()
);
fromTransformerChain(
argv.transform,
mergeCommandConfig('list-rules', argv, DEFAULT_LIST_RULES_CONFIG)
)

const config = mergeCommandConfig(
'list-rules',
argv,
DEFAULT_LIST_RULES_CONFIG
);
fromTransformerChain(argv.transform, config)
.pipe(
transform(source, {
beginWith: 'object'
beginWith: 'object',
defaultTransformerConfig: config.transform.table
}),
toOutput(argv.output, {color: argv.color})
)
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/observable.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ export function isPluginRegistered(pluginId) {
* @property {string} beginWith - Begin transformer chain with this type
* @property {string} endWith - End transformer chain with this type
* @property {string} defaultTransformer - Default transformer
* @property {object} defaultTransformerConfig - Default transformer config
*/

/**
Expand Down
21 changes: 15 additions & 6 deletions packages/transformers/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,14 @@ export const toTransformer = () => observable =>

/**
*
* @param {Object} [opts] - Options
* @param {string} [opts.beginWith=report] - Begin transform pipe with this type
* @param {string} [opts.endWith=string] - End transform pipe with this type
* @param {string} [opts.defaultTransformer] - Default transformer
* @param {Partial<TransformOptions>} [opts]
* @returns {OperatorFunction<Transformer,Transformer>}
*/
export const validateTransformerChain = ({
beginWith = 'report',
endWith = 'string',
defaultTransformer = DEFAULT_TRANSFORMER
defaultTransformer = DEFAULT_TRANSFORMER,
defaultTransformerConfig = {}
} = {}) => observable =>
observable.pipe(
toArray(),
Expand All @@ -125,7 +123,9 @@ export const validateTransformerChain = ({
}

if (!transformers[transformers.length - 1].canEndWith(endWith)) {
transformers.push(loadTransformer(defaultTransformer));
transformers.push(
loadTransformer(defaultTransformer, defaultTransformerConfig)
);
}

let nextTransformer = transformers[++idx];
Expand Down Expand Up @@ -197,3 +197,12 @@ export const compatibleTransforms = sourceType =>
/**
* @typedef {{id: string, config: object}} TransformerConfig
*/

/**
* for {@link validateTransformerChain}
* @typedef {object} TransformOptions
* @property {string} beginWith - Begin transformer chain with this type
* @property {string} endWith - End transformer chain with this type
* @property {string} defaultTransformer - Default transformer
* @property {object} defaultTransformerConfig - Default transformer config
*/

0 comments on commit 077ce49

Please sign in to comment.