2.7.1 • Published 29 days ago

svglint v2.7.1

Weekly downloads
1,278
License
MIT
Repository
github
Last release
29 days ago

SVGLint

Lints SVG files. Can be run as a commandline utility, or as a NodeJS library.

Usage

The tool can be used as a commandline tool by executing the CLI. If installed as a dependency by NPM this will be found at ./node_modules/.bin/svglint. If installed globally by NPM it can be executed directly as svglint.

$ svglint --help

  Linter for SVGs

  Usage:
      svglint [--config config.js] [--ci] [--debug] file1.svg file2.svg
      svglint --stdin [--config config.js] [--ci] [--debug] < file1.svg

  Options:
      --help        Display this help text
      --version     Show the current SVGLint version
      --config, -c  Specify the config file. Defaults to '.svglintrc.js'
      --debug,  -d  Show debug logs
      --ci, -C      Only output to stdout once, when linting is finished
      --stdin       Read an SVG from stdin

The tool can also be used through the JS API.

import SVGLint from "svglint";

const linting = await SVGLint.lintSource("<svg>...</svg>", {
    // ... config goes here
});
linting.on("done", () => {
    if (!linting.valid) {
        console.log("You've been a naughty boy!");
    }
});

Config

In order to specify what should be linted SVGLint must be given a configuration object. If you are using the CLI, this configuration object is read from the file specified by --config. This defaults to .svglintrc.js, which will be searched for up through the directory tree, or in the user's home directory (e.g. ~/.svglintrc.js on Unix-like systems) - this is similar to tools such as ESLint.

This configuration file should export a single object, of the format:

export default {
    // additional configuration may go here in the future
    // for now, "rules" is the only useful key
    rules: {
        elm: [{
            // config 1 for the "elm" rule
        }, {
            // config 2 for the "elm" rule
        }],
        attr: {
            // config 1 for the "attr" rule
        },
        custom: [
            function() { // config 1 for the "custom" rule }
        ]
    }
}

For specifics on how the config for each rule should be formatted, see their specific rule files.

If you are using the JS API, this configuration object is passed as the second parameter.

If no configuration is found or provided, a default configuration object is used. This default configuration may be changed such that previously valid SVGs become invalid in minor releases and patches.

2.7.1

29 days ago

2.7.0

2 months ago

2.5.0

6 months ago

2.6.0

6 months ago

2.4.0

11 months ago

2.3.0

1 year ago

2.3.1

1 year ago

2.2.0

2 years ago

2.1.1

2 years ago

1.3.0

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.2.0

2 years ago

1.1.0

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

4 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.9.1-RC

6 years ago

0.9.0-RC

6 years ago

0.0.0-alpha.4

6 years ago

0.0.0-alpha.3

6 years ago

0.0.0-alpha.2

6 years ago

0.0.0-alpha.1

6 years ago