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

add lint for duplicate feature under a statement #2573

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

v1bh475u
Copy link

@v1bh475u v1bh475u commented Jan 24, 2025

closes #2250

Checklist

  • No CHANGELOG update needed
  • No new tests needed
  • No documentation update needed

Copy link
Collaborator

@williballenthin williballenthin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start @v1bh475u

From the tracking issue:

We cannot use rule passed as argument for detecting duplicate features as the Rule class when retrieves features from the yaml file, it simply ignores the redundancies. Hence, we have to rely on definition which contains the entire unparsed yaml file as string.

With this background, it makes sense why you parsed the raw string, rather than using the structured data we already have. At the very least, this information should be provided as a comment to explain why the code appears so complex.

Given what it does, the code isn't too hard to follow. In fact, I like your code style quite a bit! Still, it takes some effort to follow along. I'd like either: simpler logic or tests that demonstrate the code working as expected.

For simpler logic, could you use a yaml parser to convert the raw text into a structured representation and avoid all the string splitting and searching?

If you want to stick with the current algorithm, please add some test cases that show the linter working as expected. Since the linter is found in ./scripts and not in the Python module, I don't think we can easily integrate with pytest, so I'd recommend some "self check" code that runs at the start of main everytime the linter is started. Its not very efficient, but the linter isn't run often and the tests shouldn't take long anyways.

Thoughts?

  • Also, please update the changelog and acknowledge yourself

scripts/lint.py Outdated Show resolved Hide resolved
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add bug fixes, new features, breaking changes and anything else you think is worthwhile mentioning to the master (unreleased) section of CHANGELOG.md. If no CHANGELOG update is needed add the following to the PR description: [x] No CHANGELOG update needed

@github-actions github-actions bot dismissed their stale review January 29, 2025 14:19

CHANGELOG updated or no update needed, thanks! 😄

@v1bh475u
Copy link
Author

@williballenthin I used one of the function load of already imported ruamel.yaml which does not discard duplicate features so we can use it and rewritten the entire code. Please review.

@v1bh475u
Copy link
Author

Also, please explain how I should handle conflicts in CHANGELOG

@williballenthin
Copy link
Collaborator

Also, please explain how I should handle conflicts in CHANGELOG

use your best judgement to merge the changes. order doesn't really matter, just that the content go into the right sections.

@williballenthin
Copy link
Collaborator

I used one of the function load of already imported ruamel.yaml which does not discard duplicate features so we can use it and rewritten the entire code.

The new code is so much cleaner! Great work.

@v1bh475u
Copy link
Author

Done with changes.

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.

add lint to avoid duplicate features
2 participants