Code inspection to tell you to add this. or super. qualifications to member references

Issue #1186 resolved
Eric Kintzer created an issue

This is clearly an optional item to add to the Inspector

By convention, our org uses this.foo whenever referring to an object instance variable and super.bar when referring to a super class variable. Of course, Apex doesn't care but the PR reviewers (sometimes) do care when the developer is inconsistent - this.foo sometimes but elsewhere in the same class simply foo.

It would be nice to have a new inspector that would tell you when you forgot to add this. or super. to the variable reference - this would be a warning (ochre highlight)

To generalize this, one might have an object variable convention property. In our org's case, this is this. but in fflib, it is m_

Comments (4)

  1. Scott Wells repo owner

    Eric, this is such a specialized request that I don't feel it's one I'll implement. However, you might be able to implement it as a PMD XPath-based rule for Apex. Might be tricky to determine exactly which references are for members, but I'd recommend investigating that route if this is important to you.

  2. Log in to comment