npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

eslint-plugin-svgo

v0.12.0

Published

Optimize SVG files with SVGO via ESLint.

Readme

eslint-plugin-svgo

CI NPM VERSION NPM DOWNLOADS CODECOV LICENSE

An ESLint plugin that brings the power of SVGO to your SVG optimization workflow.

Optimize SVG files with SVGO via ESLint rules, enabling seamless integration into your development and CI/CD pipelines.

✨ Features

  • 🚀 Full integration with SVGO v4+
  • 📋 Lint SVG files with ESLint
  • ⚙️ Highly configurable SVGO plugins
  • 🔧 Support for external SVGO config files
  • 📦 Works with ESLint's flat config format
  • 🎯 TypeScript support

Compatibility

| Package | Version | | ------- | -------- | | SVGO | v4.0.0+ | | ESLint | v9.5.0+ | | Node.js | v20.0.0+ |

📦 Installation

Choose your package manager:

npm i eslint-plugin-svgo -D
yarn add eslint-plugin-svgo -D
pnpm add eslint-plugin-svgo -D

🚀 Quick Start

The quickest way to get started - use the recommended configuration:

// eslint.config.js
import { defineConfig } from 'eslint/config'
import pluginSVGO from 'eslint-plugin-svgo'

export default defineConfig([
  // Your other configs...
  pluginSVGO.configs.recommended,
])

This will automatically:

  • Target all **/*.svg files
  • Enable the svgo/svgo rule with sensible defaults
  • Use the preset-default SVGO plugin configuration

🎯 Advanced Usage

For more control over the SVGO optimization process, configure the plugin manually:

// eslint.config.js
import { defineConfig } from 'eslint/config'
import { parserPlain, plugin as pluginSVGO } from 'eslint-plugin-svgo'

export default defineConfig([
  {
    name: 'svgo',
    files: ['**/*.svg'],
    ignores: ['icons/foo.svg', 'images/**/*.svg'],
    plugins: {
      svgo: pluginSVGO,
    },
    languageOptions: {
      parser: parserPlain,
    },
    rules: {
      'svgo/svgo': [
        'error',
        {
          floatPrecision: 2,
          js2svg: {
            pretty: true,
          },
          plugins: [
            'preset-default',
            {
              name: 'cleanupIds',
              params: {
                minify: false,
              },
            },
          ],
        },
      ],
    },
  },
])

Plugin Configuration Options

You can configure SVGO plugins in two ways:

1. By plugin name (using defaults):

import { defineConfig } from 'eslint/config'
import pluginSVGO from 'eslint-plugin-svgo'

export default defineConfig([
  // Your other configs...
  {
    ...pluginSVGO.configs.recommended,
    rules: {
      'svgo/svgo': [
        'error',
        {
          plugins: ['cleanupIds', 'convertColors'],
        },
      ],
    },
  },
])

2. With custom parameters:

import { defineConfig } from 'eslint/config'
import pluginSVGO from 'eslint-plugin-svgo'

export default defineConfig([
  // Your other configs...
  {
    ...pluginSVGO.configs.recommended,
    rules: {
      'svgo/svgo': [
        'error',
        {
          plugins: [
            {
              name: 'cleanupIds',
              params: {
                minify: false,
              },
            },
          ],
        },
      ],
    },
  },
])

3. Override preset defaults:

import { defineConfig } from 'eslint/config'
import pluginSVGO from 'eslint-plugin-svgo'

export default defineConfig([
  // Your other configs...
  {
    ...pluginSVGO.configs.recommended,
    rules: {
      'svgo/svgo': [
        'error',
        {
          plugins: [
            {
              name: 'preset-default',
              params: {
                overrides: {
                  cleanupAttrs: false,
                  cleanupIds: {
                    minify: false,
                  },
                },
              },
            },
          ],
        },
      ],
    },
  },
])

🔌 Integration Guides

VSCode

Enable ESLint validation for SVG files by adding to your .vscode/settings.json:

{
  "eslint.validate": ["xml", "svg"]
}

Prettier

Add SVG files to your .prettierignore to prevent conflicts with ESLint:

**/*.svg

Or configure in package.json:

{
  "prettier": {
    "ignorePatterns": ["**/*.svg"]
  }
}

📚 Rule Reference

svgo/svgo

Optimize SVG files using SVGO.

Options

svgoConfig
  • Type: boolean | string
  • Default: undefined
  • Example: true or './svgo.config.js'

Use an external SVGO config file. This is useful when you need to use features that aren't JSON-schema compatible (like function-based configuration).

  • true — Auto-load svgo.config.mjs or svgo.config.js from your project root
  • 'path/to/config' — Use a specific config file path

Note: When svgoConfig is used, all other rule options (except path) are ignored. Make sure your config file exists, or it will be treated as false.

path
  • Type: string
  • Default: context.filename

Override the file path. Some plugins (like prefixIds) use this for context.

multipass
  • Type: boolean
  • Default: false

Enable multiple optimization passes to ensure all optimizations are fully applied.

floatPrecision
  • Type: number
  • Default: 3

Set precision for floating-point numbers in the output (e.g., 2 converts 1.234 to 1.23). This is passed to plugins that support it.

datauri
  • Type: 'base64' | 'enc' | 'unenc'
  • Default: undefined

Output format for Data URIs:

  • 'base64' — Base64 encoded
  • 'enc' — URL-encoded
  • 'unenc' — Unencoded
js2svg
  • Type: object
  • Default: undefined

Options for rendering the optimized SVG from the AST. See SVGO's js2svg documentation for all available options.

Common options:

import { defineConfig } from 'eslint/config'
import pluginSVGO from 'eslint-plugin-svgo'

export default defineConfig([
  // Your other configs...
  {
    ...pluginSVGO.configs.recommended,
    rules: {
      'svgo/svgo': [
        'error',
        {
          js2svg: {
            pretty: true, // Add newlines and indentation
            indent: 2, // Indentation size
            eol: 'lf', // Line ending style
            final: true, // Add final newline
          },
        },
      ],
    },
  },
])

Unsupported options: regEntities, regValEntities, encodeEntity (require functions)

plugins
  • Type: array
  • Default: ['preset-default']

List of SVGO plugins to apply. See SVGO's plugin documentation for available plugins and their parameters.

Example configuration:

import { defineConfig } from 'eslint/config'
import pluginSVGO from 'eslint-plugin-svgo'

export default defineConfig([
  // Your other configs...
  {
    ...pluginSVGO.configs.recommended,
    rules: {
      'svgo/svgo': [
        'error',
        {
          plugins: [
            'preset-default',
            'removeDoctype',
            {
              name: 'cleanupIds',
              params: {
                minify: false,
                prefix: 'icon-',
              },
            },
          ],
        },
      ],
    },
  },
])

⚠️ JSON Schema Limitations

ESLint rule options must be JSON schema compatible, which means functions and regular expressions cannot be used directly in rule options. However, you can work around this using external config files.

Unsupported Features in Rule Options

js2svg:

  • regEntities — function
  • regValEntities — function
  • encodeEntity — function

plugins:

  • prefixIds.prefix — function (use boolean or string instead)
  • addClassesToSVGElement.className — function (use string instead)
  • convertColors.currentColor — regexp (use boolean or string instead)
  • removeComments.preservePatterns — regexp (use boolean or string instead)

Solution: Use External Config

For advanced configurations requiring functions or regexes, create an external config file:

// svgo.config.mjs
export default {
  plugins: [
    'preset-default',
    {
      name: 'prefixIds',
      params: {
        prefix: node => `svg-${node.attributes.id}`,
      },
    },
  ],
}

Then reference it in your ESLint config:

import { defineConfig } from 'eslint/config'
import pluginSVGO from 'eslint-plugin-svgo'

export default defineConfig([
  // Your other configs...
  {
    ...pluginSVGO.configs.recommended,
    rules: {
      'svgo/svgo': ['error', { svgoConfig: './svgo.config.mjs' }],
    },
  },
])

Tip: External config files are the most flexible way to configure SVGO with all its advanced features.

💡 Common Examples

Basic SVG Optimization

import { defineConfig } from 'eslint/config'
import pluginSVGO from 'eslint-plugin-svgo'

export default defineConfig([
  // Your other configs...
  {
    ...pluginSVGO.configs.recommended,
    rules: {
      'svgo/svgo': 'error',
    },
  },
])

With Custom Float Precision

import { defineConfig } from 'eslint/config'
import pluginSVGO from 'eslint-plugin-svgo'

export default defineConfig([
  // Your other configs...
  {
    ...pluginSVGO.configs.recommended,
    rules: {
      'svgo/svgo': [
        'error',
        {
          floatPrecision: 2,
        },
      ],
    },
  },
])

Pretty-Printed SVG Output

import { defineConfig } from 'eslint/config'
import pluginSVGO from 'eslint-plugin-svgo'

export default defineConfig([
  // Your other configs...
  {
    ...pluginSVGO.configs.recommended,
    rules: {
      'svgo/svgo': [
        'error',
        {
          js2svg: {
            pretty: true,
            indent: 2,
          },
        },
      ],
    },
  },
])

Disable Specific Plugins

import { defineConfig } from 'eslint/config'
import pluginSVGO from 'eslint-plugin-svgo'

export default defineConfig([
  // Your other configs...
  {
    ...pluginSVGO.configs.recommended,
    rules: {
      'svgo/svgo': [
        'error',
        {
          plugins: [
            {
              name: 'preset-default',
              params: {
                overrides: {
                  removeDoctype: false,
                  removeComments: false,
                },
              },
            },
          ],
        },
      ],
    },
  },
])

Using External Config

import { defineConfig } from 'eslint/config'
import pluginSVGO from 'eslint-plugin-svgo'

export default defineConfig([
  // Your other configs...
  {
    ...pluginSVGO.configs.recommended,
    rules: {
      'svgo/svgo': ['error', { svgoConfig: true }],
    },
  },
])

With svgo.config.mjs:

export default {
  multipass: true,
  floatPrecision: 2,
  plugins: [
    'preset-default',
    'removeDoctype',
    {
      name: 'cleanupIds',
      params: { minify: false },
    },
  ],
}

💖 Acknowledgments

📄 License

MIT License © 2024-PRESENT ntnyq