eslint-plugin-svgo
v0.2.0
Published
Optimize SVG files with SVGO using ESLint.
Downloads
755
Readme
eslint-plugin-svgo
Optimize SVG files with SVGO using ESLint.
Install
npm install eslint-plugin-svgo -D
yarn add eslint-plugin-svgo -D
pnpm add eslint-plugin-svgo -D
Basic Usage
// eslint.config.js
import pluginSvgo from 'eslint-plugin-svgo'
/**
* @type import('eslint').Linter.Config[]
*/
export default [
// ...other flat configs
pluginSvgo.configs.recommended,
]
Advanced Usage
// eslint.config.js
import { config } from 'eslint-plugin-svgo'
/**
* @type import('eslint').Linter.Config[]
*/
export default [
// ...other flat configs
config({
files: ['**/*.svg'],
rules: {
'svgo/svgo': [
'error',
{
// svgo config
floatPrecision: 2,
js2svg: {
pretty: true,
},
plugins: [],
},
],
},
}),
]
Rules
svgo/svgo
Use svgo to optimize SVG files.
Options
Default options:
{
"js2svg": {
"indent": 2,
"pretty": true
},
"plugins": ["preset-default"]
}
svgoConfig
- type:
boolean | string
- default:
undefined
Use an external config file, e.g: svgo.config.mjs.
Set to true
, svgo will auto load config.
Set to path/to/your/svgo.config
to custom config file path.
path
- type:
string
- default:
context.filename
Can be used by plugins, for example prefixids.
multipass
- type:
boolean
- default:
false
Pass over SVGs multiple times to ensure all optimizations are applied.
floatPrecision
- type:
number
- default:
3
Precision of floating point numbers. Will be passed to each plugin that supports this param.
datauri
- type:
'base64' | 'enc' | 'unenc'
- default:
undefined
Output as Data URI string.
js2svg
- type:
object
- default:
{ indent: 2, pretty: true }
Options for rendering optimized SVG from AST. Check svgo/lib/types.d.ts for details.
Options bellow are not supported:
regEntities
regValEntities
encodeEntity
plugins
- type:
array
- default:
['preset-default']
Plugins configuration. Check Plugins | SVGO Documentation for details.
Types
config
Helper function to create ESLint config.
parameters
All parameters of ESLint flat config are supported.
name
- type:
string
- default:
svgo/recommended
files
- type:
string[]
- default:
[**/*.svg]
rules
- type:
Linter.RulesRecord
- default:
{ 'svgo/svgo': 'error' }