Java rule - boolean variables should be prefixed with is or has

Similar to the existing rule we have

java:S2047

The names of methods with boolean return values should start with “is” or “has”

Have a rule for variables which is a good best practise and applicable in most cases ie few false positives

Thanks

1 Like

Hello @mattadamson,

Thanks for reaching out; if I understood correctly, you are proposing a new rule to enforce that boolean variables are prefixed by is or has. Is it correct?

Cheers

yes exactly sorry for the delay in replying

Hello @mattadamson, thanks for clarifying. It seems that, officially, there is no convention for naming boolean variables and fields, but only a lot of rumors and discussions going on.

There is no correct way to name boolean variables and having a generic rule for such a controversial topic will result in more troubles than benefits for the users. For example, false positives can happen in cases where flags are named using verbs: “canX”, “doesX”, “supportsX”, etc…