Skip to content

Instantly share code, notes, and snippets.

@harto
Last active April 12, 2023 12:01
Show Gist options
  • Save harto/cd6e9719011cfe1a5d26cd961b3dca85 to your computer and use it in GitHub Desktop.
Save harto/cd6e9719011cfe1a5d26cd961b3dca85 to your computer and use it in GitHub Desktop.
Validate a partial Mapbox style expression
#!/usr/bin/env bash
set -euo pipefail
# Check a partial Mapbox style expression using gl-style-validate
# (https://github.com/mapbox/mapbox-gl-js/tree/master/src/style-spec).
#
# To install gl-style-validate:
# $ npm install @mapbox/mapbox-gl-style-spec --global
#
# Usage:
# $ validate-mapbox-expression '{"type": "line", "paint": {"line-width": "whoops"}}'
# /dev/stdin:16: layers[0].paint.line-width: number expected, string found
EXPR="$1"
jq -s '{
"version": 8,
"sources": {
"dummy": {
"type": "vector",
"url": "http://example.com/tiles.json"
}
},
"layers": [
{
"id": "dummy",
"source": "dummy",
"source-layer": "dummy"
} * .[0]
]
}' <<< "$EXPR" | gl-style-validate
@harto
Copy link
Author

harto commented Apr 12, 2023

how to run this?

@satya-auti do something like this:

  1. Install the Mapbox dependency as in the inline comments
  2. Save this gist to a file somewhere on your computer, e.g. /usr/bin/validate-mapbox-expression
  3. Give your user account permission to execute it: chmod +x /usr/bin/validate-mapbox-expression
  4. Run it as in the inline comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment