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

Converted remaining remediators to new API and bugfixes #462

Merged
merged 13 commits into from
Nov 1, 2024

Conversation

andrecsilva
Copy link
Contributor

No description provided.

@andrecsilva andrecsilva changed the title Converted remaining remediators to new API Converted remaining remediators to new API and bugfixes Oct 24, 2024
@andrecsilva andrecsilva marked this pull request as ready for review October 25, 2024 11:17
Copy link
Contributor

@nahsra nahsra left a comment

Choose a reason for hiding this comment

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

Very cool! We're on the way. Before submitting a PR, make sure the easy stuff (final, public) etc. is right.

I think there is a little more to the architecture to consider here, given the exposure of so many public static methods. Ideally we'd have no static methods that aren't generic utilities. Let's see if we can't iterate and make a solution that doesn't require them?

import com.github.javaparser.Position;
import com.github.javaparser.Range;
import com.github.javaparser.ast.Node;

Copy link
Contributor

Choose a reason for hiding this comment

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

final

Copy link
Contributor Author

Choose a reason for hiding this comment

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

WithoutScopePositionMatcher extends it.

@@ -16,7 +16,7 @@ public interface FixCandidateSearcher<T> {
* @param cu
* @param path
* @param rule
* @param issuesForFile
Copy link
Contributor

Choose a reason for hiding this comment

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

It is a very cool idea to make this a mutable List. I wrestle with whether is a good idea, because pure functions are easier to test and reason about. I am not inclined to stand in the way, just registering a concern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is admittedly, a bit of a hack since I've failed to accommodate for the problem multiple searchers reporting the same issues as unfixed before working on converting the XXE Remediators, where the problem became very apparent.

I don't think this is that much of a problem wince you shouldn't be using the FixCandidateSearcher outside of SearcherStrategyRemediator now. But I see your point.

I'll think about a solution for this.

/** Removes the range of the node's scope before matching it against a position. */
public final class WithoutScopePositionMatcher extends DefaultNodePositionMatcher {

@Override
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this type should be package-private, right? Does it need to be public? If it does, why is getRange not public?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

XXERemediator uses it as parameter. And thus, some codemods (Sonar based ones, mostly) make use of it. Also some tests.

getRange is there mostly to reuse code from DefaultNodePositionMatcher and shouldn't be accessed as it is an implementation detail. I've made it protected.

* @param node
* @return
*/
public static boolean match(final Node node) {
Copy link
Contributor

Choose a reason for hiding this comment

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

All of these sister types expose this static method -- this is a smell we may need a different architecture?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Each of those match methods should be their own FixCandidateSearcher, but it gets very verbose.

I'll think on an abstraction to make this easier.

Copy link

sonarcloud bot commented Oct 30, 2024

Quality Gate Passed Quality Gate passed

Issues
6 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

@andrecsilva andrecsilva merged commit d1bfcc9 into main Nov 1, 2024
6 checks passed
@andrecsilva andrecsilva deleted the ISS-2215/convert-more-remediators branch November 1, 2024 09:57
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.

2 participants