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

Support simple patterns for codemod include/exclude #458

Merged
merged 2 commits into from
Apr 11, 2024
Merged

Conversation

drdavella
Copy link
Member

@drdavella drdavella commented Apr 10, 2024

Overview

Support simple patterns for codemod include/exclude CLI flags

Description

  • The spec was updated to enable simple pattern matching for codemod include/exclude
  • In order to support this I simplified the exclusion logic a bit
  • I took the liberty of removing the warning for non-existing codemods given to exclude; I'm not sure it's necessary
  • I'm still a little unsure about the need for sast_only but I left it as-is for this PR

Closes #316

Copy link
Contributor

@clavedeluna clavedeluna left a comment

Choose a reason for hiding this comment

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

FYI the request to log bad excluded was yours and you see the lengths I had to go to get it there so it's kinda nice that this code is simpler without it. I do actually think the logging was useful but up to you.

Approving but I think small change is needed.

base_codemods.pop(codemod.id, None)
if bool(sast_only) != bool(codemod.origin == "pixee"):
base_codemods[codemod.id] = codemod

# Remove duplicates and preserve order
return list(dict.fromkeys(base_codemods.values()))
Copy link
Contributor

Choose a reason for hiding this comment

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

The logic is so subtly changed so I'm going off passing unit tests but I think you can remove this list(dict.from_keys...) since that was necessary when base_codemods did this:

                    base_codemods[codemod.id] = codemod
                    base_codemods[codemod.name] = codemod

but since that was only necessary to log an excluded codemod and that's been removed, you can remove this duplication removal.

not sast_only and codemod.origin == "pixee"
if (
codemod.id in names
or (codemod.origin == "pixee" and codemod.name in names)
Copy link
Contributor

Choose a reason for hiding this comment

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

does this line accomplish this issue for excluded?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I think it does for the exclude case but I think we'd want to add more tests so we can keep it as a separate issue.

Copy link

sonarcloud bot commented Apr 11, 2024

Quality Gate Passed Quality Gate passed

Issues
1 New issue
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@drdavella
Copy link
Member Author

FYI the request to log bad excluded was yours and you see the lengths I had to go to get it there so it's kinda nice that this code is simpler without it. I do actually think the logging was useful but up to you.

Yes sorry I see that this was complicated and I'm just not sure it's necessary so I was able to simplify it.

@drdavella drdavella added this pull request to the merge queue Apr 11, 2024
Merged via the queue into main with commit 1ccb8cf Apr 11, 2024
12 checks passed
@drdavella drdavella deleted the glob-codemod-ids branch April 11, 2024 13:35
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.

Codemodder include and exclude flags should understand patterns
2 participants