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

fix(no-raw-keys): do not report constants from other packages #67

Merged

Conversation

Jacobbrewer1
Copy link
Contributor

@Jacobbrewer1 Jacobbrewer1 commented Feb 5, 2025

Closes #66

This pull request includes changes to improve the handling of raw keys in the sloglint package. The most important changes include enhancing the key checking logic, adding new constant definitions, and modifying test cases to use the new constants.

Improvements to key checking logic:

  • sloglint.go: Enhanced the logic in the visit function to handle package selectors and ensure that keys are constants defined within any package.

Additions to constant definitions:

Updates to test cases:

Testing

The new test case does not trigger the error

image

@Jacobbrewer1 Jacobbrewer1 changed the title fix(no_raw_keys): Updating check to correctly include all constants from any package fix(no_raw_keys): Updating check to correctly include package constants Feb 5, 2025
@tmzane tmzane self-requested a review February 6, 2025 15:41
@Jacobbrewer1
Copy link
Contributor Author

Jacobbrewer1 commented Feb 6, 2025

@tmzane I see the problem with the checks, GitHub is looking for a location that doesn't exist on the runner.

/home/runner/work/sloglint/sloglint/testdata/src/go-simpler.org/sloglint/testdata/src/no_raw_keys/keys (from $GOPATH)

Just taking a look at a solution now

@Jacobbrewer1
Copy link
Contributor Author

@Jacobbrewer1
Copy link
Contributor Author

Jacobbrewer1 commented Feb 6, 2025

@tmzane as this would be a CICD change most likely, I will remove the test case for now.

@tmzane
Copy link
Member

tmzane commented Feb 6, 2025

I might have an idea how to fix it, let me check.

@tmzane tmzane changed the title fix(no_raw_keys): Updating check to correctly include package constants fix(no-raw-keys): do not report constants from other packages Feb 6, 2025
@tmzane
Copy link
Member

tmzane commented Feb 6, 2025

Looks like the tests are passing now, good.

May I ask why you updated the check to use pass.TypesInfo.ObjectOf? It seems more complex now.

@tmzane
Copy link
Member

tmzane commented Feb 6, 2025

Nevermind, I see now that *ast.Ident.Obj is deprecated and won't work for constants in other packages.

@tmzane tmzane merged commit 72654a4 into go-simpler:main Feb 6, 2025
8 checks passed
@tmzane
Copy link
Member

tmzane commented Feb 6, 2025

@Jacobbrewer1 Thanks!

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

Successfully merging this pull request may close these issues.

False positives for logging constant keys in another package?
2 participants