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

Feature Request: Identify unused imports #51

Open
myii opened this issue Oct 12, 2019 · 4 comments
Open

Feature Request: Identify unused imports #51

myii opened this issue Oct 12, 2019 · 4 comments
Labels

Comments

@myii
Copy link
Contributor

myii commented Oct 12, 2019

Taking this example:

{% from "zabbix/macros.jinja" import files_switch with context -%}
  • files_switch isn't actually used anywhere in the file, so should be removed.

I've actually come across many of these examples throughout SaltStack Formulas. Would be great if salt-lint could catch these.

@myii
Copy link
Contributor Author

myii commented Oct 12, 2019

Note, this may not be that simple due to uses of import as.

kubernetes-formula/kubernetes/kubectl/config/environ/install.sls:

{%- from tplroot ~ "/map.jinja" import kubernetes as k8s with context %}

prometheus-formula/prometheus/archive/install.sls:

{%- from tplroot ~ "/map.jinja" import prometheus as p with context %}
  • This is one is particularly tricky; personally, I'd prefer preventing single-character uses like this as well -- but that's not important right now.

@myii
Copy link
Contributor Author

myii commented Oct 13, 2019

A similar issue is unused Jinja variables.

lighttpd-formula/lighttpd/config.sls@4fca60f

{% set file = lighttpd.get('config', ['lighttpd.conf']) %}

file is no longer being used anywhere after being set. It used to be, in an earlier version of the file:

lighttpd-formula/lighttpd/config.sls@e69c9a0

    - source: {{ files_switch('lighttpd', ['/etc/lighttpd/' ~ file,
                                           '/etc/lighttpd/' ~ file ~ '.jinja']) }}

It would be great if salt-lint could catch these as well.

@roaldnefs
Copy link
Member

Thanks @myii for the feature request!

This requires salt-lint on (partially) rendering the state, or some logic that can tokenize the Jinja part. The last might actually be easier, but requires writing a tokenizer. Because this only related to the Jinja part, I'm first going to try to fix #19 and #48.

@myii
Copy link
Contributor Author

myii commented Oct 13, 2019

... I'm first going to try to fix #19 and #48.

@roaldnefs Great, thanks for all of your hard work.

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

No branches or pull requests

2 participants