Skip to content

Commit

Permalink
Add warning about enabling plugins in presets
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Nov 2, 2021
1 parent 5165ccb commit cb7e9be
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/svgo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,38 @@ test('allow to disable and customize plugins in preset', () => {
`);
});

test('warn when user tries enable plugins in preset', () => {
const svg = `
<svg viewBox="0 0 120 120"></svg>
`;
const warn = jest.spyOn(console, 'warn');
optimize(svg, {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
cleanupListOfValues: true,
},
},
},
],
js2svg: { pretty: true, indent: 2 },
});
expect(warn)
.toBeCalledWith(`You are trying to enable cleanupListOfValues which is not part of preset.
Try to put it before or after preset, for example
plugins: [
{
name: 'preset-default',
},
'cleanupListOfValues'
]
`);
warn.mockRestore();
});

describe('allow to configure EOL', () => {
test('should respect EOL set to LF', () => {
const svg = `
Expand Down
16 changes: 16 additions & 0 deletions lib/svgo/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ const createPreset = ({ name, plugins }) => {
if (floatPrecision != null) {
globalOverrides.floatPrecision = floatPrecision;
}
if (overrides) {
for (const [pluginName, override] of Object.entries(overrides)) {
if (override === true) {
console.warn(
`You are trying to enable ${pluginName} which is not part of preset.\n` +
`Try to put it before or after preset, for example\n\n` +
`plugins: [\n` +
` {\n` +
` name: 'preset-default',\n` +
` },\n` +
` 'cleanupListOfValues'\n` +
`]\n`
);
}
}
}
return invokePlugins(ast, info, plugins, overrides, globalOverrides);
},
};
Expand Down

0 comments on commit cb7e9be

Please sign in to comment.