svg/svgo

cleanupAttrs in 'preset-default' overrides is not respected

sriramrudraraju opened this issue · 0 comments

Describe the bug
cleanupAttrs to ignore spacing from svgs

The below config isnt working

export default {
  plugins: [
    {
      name: 'preset-default',
      params: {
        overrides: {
          // disable a default plugin
          removeViewBox: false,
          cleanupAttrs: false, // added this to base config

          // customize the params of a default plugin
          inlineStyles: {
            onlyMatchedOnce: false,
          },
         // tried the below config too
         //  also tried switching cleanupAttrs: false and this
         cleanupAttrs: {
            spaces: false
          }
        },
      },
    },
  ],
};

To Reproduce
Steps to reproduce the behavior:

I tried the below code in the svgo playground as well

const svg = `
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox=" 0 0      150 100 " width="150">
  <!-- Created with love! -->
  <defs>
    <ellipse cx="50" cy="50.0" rx="50.00" ry="auto" fill="black" id="circle"/>
  </defs>
  <g>
    <use href="#circle" transform="skewX(16)"/>
    <rect id="useless" width="0" height="0" fill="#ff0000"/>
  </g>
</svg>
`;

const svgoConfig = {
  js2svg: { indent: 2, pretty: true },
  plugins: [
    {
      name: 'preset-default',
      params: {
        overrides: {
          // disable a default plugin
          removeViewBox: false,

          // customize the params of a default plugin
          inlineStyles: {
            onlyMatchedOnce: false,
          },
          cleanupAttrs: {
            spaces: false
          }
        },
      },
    }
  ]
}

render(<SvgoPreview svg={svg} svgoConfig={svgoConfig}/>);
// rendered output
<svg xmlns="http://www.w3.org/2000/svg" width="150" viewBox="0 0 150 100">
  <defs>
    <circle id="a" cx="50" cy="50" r="50" fill="#000"/>
  </defs>
  <use href="#a" transform="skewX(16)"/>
</svg>
// desired output (spacing in viewbox)
<svg xmlns="http://www.w3.org/2000/svg" width="150" viewBox=" 0 0      150 100 ">
  <defs>
    <circle id="a" cx="50" cy="50" r="50" fill="#000"/>
  </defs>
  <use href="#a" transform="skewX(16)"/>
</svg>

If I remove preset-default and use as base plugin, it works as expected.

// with this config, spacing is fixed
const svgoConfig = {
  js2svg: { indent: 2, pretty: true },
  plugins: [
    {
      name: 'cleanupAttrs',
      params: {
        spaces: false
      }
    }
  ]
}

Expected behavior
'preset-default' should be configurable as mentioned

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • SVGO Version 3.2.0
  • NodeJs Version 18.14.0
  • OS: Mac OS m1

Additional context

  • I did play in the documentation demo playground as well to test it. Still same issue.
  • I havent tested for other plugins.