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

[apex] Prevent classes from shadowing System Namespace #3184

Open
noerremark opened this issue Mar 30, 2021 · 5 comments
Open

[apex] Prevent classes from shadowing System Namespace #3184

noerremark opened this issue Mar 30, 2021 · 5 comments
Labels
a:new-rule Proposal to add a new built-in rule

Comments

@noerremark
Copy link

noerremark commented Mar 30, 2021

We brainstormed about this rule in #2322. Believe it or not, I had the issue the other day, in a real environment. Salesforce Developers Blog has a 2012 post about it, so it's an official "feature", but pretty bad design.

Proposed Rule Name: ClassShadowsSystemNamespace

Proposed Category: Code Style

Description:

Code Sample:

public class Database {
    public static String query() {
        return 'wherefore art thou namespace?';
    }
}

Since Database is also in System this is a violation.

@noerremark noerremark added the a:new-rule Proposal to add a new built-in rule label Mar 30, 2021
@noerremark
Copy link
Author

@rsoesemann / @daveespo - I'll see if I can provide a PR for this.

@rsoesemann
Copy link
Member

@noerremark please think about your implementation options. This could be a super lean XPath rule just checking a few classes against the class name. The footprint of a real Java rule is only of use when you make it work with previously unknown System classes.

@noerremark
Copy link
Author

@rsoesemann - I agree, XPath is the best option here.

@noerremark
Copy link
Author

@rsoesemann - I started looking into this, and there is a LOT of classes. I know XPath is the easy route, but what about doing a Java-rule that uses reflections to generate a list of bad names to test against? @adangel - I see you have been doing the stuff on jorle, would it be possible?

@rsoesemann
Copy link
Member

@noerremark I absolutely agree that a Java rule is smart if AND ONLY if it really not only enumerates such classes but actually finds them out magically. Meaning if Salesforce adds a NEW system class this rule should auto-detect it.
If it is just a Java rule enumerating all classes I think XPath is better.

Can we reference a separate file in XPath?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:new-rule Proposal to add a new built-in rule
Projects
None yet
Development

No branches or pull requests

2 participants