Lint Mapbox GL styles.
Yes, the Mapbox style spec has gl-style-validate, but this module solves two issues:
- The style spec tool uses an older version of Node, so it can be difficult to execute in projects that use newer versions.
- The style spec tool does not find every error you might want to find. For example, the style spec tool does not raise errors for
paintorlayoutproperty ids at the top level of a layer.
This tool takes the same inputs and creates compatible outputs to the style spec's gl-style-validate tool.
- Install.
- Execute on one or more styles:
map-gl-style-lint styles/*.json
By default, the linter uses Mapbox GL's style spec to validate a style. If you are using Maplibre GL, set the --renderer flag to maplibre-gl as shown below:
map-gl-style-lint styles/*.json --renderer=maplibre-glconst { lint } = require('map-gl-style-linter');
const errors = lint(styleJson);As above, the default spec used is Mapbox GL. To use Maplibre GL from the module:
const { lint } = require('map-gl-style-linter');
const errors = lint(styleJson, { renderer: 'maplibre-gl' });- Clone this repo.
- Install dependencies (
yarn install). - Start build tool (
yarn watch). - Start the test suite (
yarn test). - Make changes in
src.