r-lib / lintr

Static Code Analysis for R
https://lintr.r-lib.org
Other
1.19k stars 184 forks source link

Linting Google Style variable and function naming #295

Open xiamaz opened 6 years ago

xiamaz commented 6 years ago

I have just started looking into R linting and am unsure, whether I am configuring the plugins correctly. I am coding based on the Google R Style guide, which recommends using lowerCamelCase or dot.naming for variables and UpperCamelCase for function names. As far as I have read in the documentation it seems to be possible to enforce either lowerCamelCase or snake_case, but I could not find settings to allow UpperCamelCase for functions.

Is it possible to configure it for this usecase? I would like to keep name linting to spot mistakes in my naming easier.

batpigandme commented 6 years ago

Hi @xiamaz, Based on the code, it looks like the available cases for object name linting are: https://github.com/jimhester/lintr/blob/e926089a0187aac01ce6981a798c5dc22e3a4273/R/object_name_linters.R#L151-L158

(The docs just give lowerCamelCase and snake_case as examples.)

xiamaz commented 6 years ago

Thanks for the answer @batpigandme. I did not know of the other options. This way I can keep rough linting of variables on! Is it possible to somehow only use UpperCamelCase for function assignments? What I would like to achieve is to only allow UpperCamelCase for function names and only lowerCamelCase and dotted.case for all other use cases.

batpigandme commented 6 years ago

I'm sure it's possible. You could probably adapt the logic/regex from the function/parentheses spacing linter and then apply names conditionally… https://github.com/jimhester/lintr/blob/e926089a0187aac01ce6981a798c5dc22e3a4273/R/function_left_parentheses.R#L17-L18

AshesITR commented 2 years ago

1104 will enable this