-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Script to catch unnecessary style elements #76
Comments
The style defaults should all be available here: e.g. https://github.com/mapbox/mapbox-gl-js/blob/master/src/style-spec/reference/v8.json#L673 |
If it was built as a standalone lib, and exports the following definition, we could run it when opening a style in maputnik also (I guess we'd probably want to prompt the user also)
|
Oh good idea, I was thinking only of validating an existing style, but pruning it and returning the minimal style would be good too. |
Ok I have a basic example here: My JS isn't great yet, so it can absolutely be improved, but it's a start that works on my osm-liberty-topo style, which is included in the repo for testing. It checks all |
Also I'd be happy to move it to @maputnik if you want |
It looks good to me @kylebarron
Thanks, I think that would be good, however let's hold off on that until we have it as a part of the Maputnik codebase somewhere. My preference to adding repos to the Maputnik org is, hold off adding them until they become a little more mature/used/tested. I think it'll keep the organisation tidy in the long run. |
Regarding:
I also think it would be good to integrate this in Maputnik somehow, but I'm not sure if this should run when opening a style:
What about adding a checkbox "Prune style" to the export modal (which is checked by default) and do nothing when opening a style? |
I need to figure out how to expose it as a CLI, and also need to figure out what framework to use for basic tests. I like @pathmapper's suggestions of it not running it when opening a style but with the option of running it when exporting it. |
There are several style elements, like
visibility: visible
that are unnecessary because those are the same as the defaults. It seems advantageous and not very difficult to write a short JS script to test PRs for these elements. (It could also be added to the pre-commit hook).My thinking is to simply traverse the JSON and check each element of each style rule against that rule's default value. So the first step I suppose is to construct a list of the style defaults.
The text was updated successfully, but these errors were encountered: