druid icon indicating copy to clipboard operation
druid copied to clipboard

Local variable names shouldn't start with capital

Open leventov opened this issue 7 years ago • 9 comments

Should be possible to catch violations with a Structural Search pattern.

leventov avatar May 07 '19 13:05 leventov

@leventov, I would like to work on this. Let me know how to begin with as I'm new to making contributions. Please share any document for beginner contributors to Druid. Thanks in advance.

sashidhar avatar May 14 '19 17:05 sashidhar

Hi @sashidhar, welcome to the community!

You can add LocalVariableName and LocalFinalVariableName patterns to this file: https://github.com/apache/incubator-druid/blob/master/codestyle/checkstyle.xml. Then trying to mvn install -DskipTests from the root of the project, Checkstyle will show you all violations.

leventov avatar May 14 '19 18:05 leventov

@sashidhar , have you started working on this yet?

lml2468 avatar May 17 '19 06:05 lml2468

Yes, I've started working on this. I'll update once I've made code changes.

On Fri, May 17, 2019 at 11:45 AM lml2468 [email protected] wrote:

@sashidhar https://github.com/sashidhar , have you started working on this yet?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/apache/incubator-druid/issues/7609?email_source=notifications&email_token=AACGIELEUVUH57TDB74HG23PVZEQHA5CNFSM4HLJBCT2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODVT25RQ#issuecomment-493334214, or mute the thread https://github.com/notifications/unsubscribe-auth/AACGIENOJCS26HFPJCSGB2LPVZEQHANCNFSM4HLJBCTQ .

sashidhar avatar May 17 '19 08:05 sashidhar

@leventov

  1. This is the match pattern I'm currently using for Local Variable names '^[a-z_](_?[a-zA-Z0-9_]+)*$'considering variables starting with and ending with underscores as well. Let me know if this is fine.

  2. There are several occurrences of variables which are not constants (non final) and have variables all capitalized for instance, Pattern DOT_OR_WHITESPACE = Pattern.compile("[\s]+|[.]+"); etc. I'm changing these to lower case. Is that fine ?

sashidhar avatar May 22 '19 16:05 sashidhar

@leventov,

  1. For local final variables example here http://checkstyle.sourceforge.net/config_naming.html#LocalFinalVariableName suggests names that are only upper case letters and digits "^[A-Z][A-Z0-9]*$".

As per this pattern, following variable should be changed from final ObjectMapper mapper = new ObjectMapper(); to final ObjectMapper MAPPER = new ObjectMapper();

I'm not sure if this makes sense changing non static variable names to all caps !!

sashidhar avatar May 22 '19 17:05 sashidhar

There are several occurrences of variables which are not constants (i.e non static fields) which have variables all capitalized for instance, Pattern DOT_OR_WHITESPACE = Pattern.compile("[\s]+|[.]+"); etc. I'm changing these to lower case. Is that fine ?

For some of these, it might be an indication that the variable was intended to be a static constant, but the original developer just forgot to include the static keyword. So I would approach these with an open mind to fixing bugs like that too, not necessarily just fixing the names to match the current state.

For local final variables example here http://checkstyle.sourceforge.net/config_naming.html#LocalFinalVariableName suggests names that are only upper case letters and digits "^[A-Z][A-Z0-9]*$".

IMO, this is silly, I don't see a reason to require this pattern. In fact, I'd be more inclined to require the opposite (local final variables should start with lowercase letters).

gianm avatar May 22 '19 22:05 gianm

How do I create a pull request ? I've made changes in a local branch and unable to commit the local branch to remote. I was thinking to push local branch to remote and then raise a pull request.

sashidhar avatar May 23 '19 14:05 sashidhar

@sashidhar it looks like there is a collision and @lml2468 has already solved this problem. In general, please consult to Github Help and web search to resolve such questions: https://help.github.com/en/articles/creating-a-pull-request

leventov avatar May 23 '19 16:05 leventov