Skip to content
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

Open
kylebarron opened this issue Jan 21, 2020 · 8 comments
Open

Script to catch unnecessary style elements #76

kylebarron opened this issue Jan 21, 2020 · 8 comments

Comments

@kylebarron
Copy link
Contributor

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.

@orangemug
Copy link
Member

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)

export default function (style, styleSpec) {
    // pruning code...
    return newStyle;
}

@kylebarron
Copy link
Contributor Author

Oh good idea, I was thinking only of validating an existing style, but pruning it and returning the minimal style would be good too.

@kylebarron
Copy link
Contributor Author

kylebarron commented Jan 21, 2020

Ok I have a basic example here:
https://github.com/kylebarron/mapbox-gl-style-prune

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 paint and layout properties on the style against the default property on the style spec's object.

@kylebarron
Copy link
Contributor Author

Also I'd be happy to move it to @maputnik if you want

@orangemug
Copy link
Member

My JS isn't great yet

It looks good to me @kylebarron

Also I'd be happy to move it to @maputnik if you want

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.

@pathmapper
Copy link
Member

@kylebarron 👍

Regarding:

we could run it when opening a style in maputnik also (I guess we'd probably want to prompt the user also)

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:

  • Playing around with a style and trying different setting in Maputnik could add some default values to the style (see e.g. Add styling for landcover, class==ice #71 (comment)). So there should also be an option to run the script when exporting a style.
  • If the script runs when opening a style, we should prompt the user because the style could be modified (as @orangemug mentioned). I like how easy and fast it is currently to open a style in Maputnik. Such a prompt would need action from the user because there should be a choice, so the opening of the style would not be as easy and fast as before.

What about adding a checkbox "Prune style" to the export modal (which is checked by default) and do nothing when opening a style?

The current export modal:
grafik

@kylebarron
Copy link
Contributor Author

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.

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

No branches or pull requests

3 participants