Skip to content

added assignment_spaces lintr - #538

Merged
AshesITR merged 4 commits into
r-lib:masterfrom
f-ritter:master
Oct 26, 2020
Merged

AshesITR merged 4 commits into
r-lib:masterfrom
f-ritter:master

Conversation

@f-ritter

Copy link
Copy Markdown
Contributor

We have a former SPS programmer in our team, who likes to define variables like this:
image
He doesn't notice all the time so I created this check. I didn't add it to the default_linters.
Let me know if I can improve anything.

@AshesITR

Copy link
Copy Markdown
Collaborator

Thanks for taking the time to make a Pull Request :)
Could you add a negative test case (i.e. "x <- 1" doesn't throw a lint)?

@f-ritter

Copy link
Copy Markdown
Contributor Author

I added all negative test cases and simplified the regex. Couldn't think of a case where it would be a false positive, is there?

@AshesITR

AshesITR commented Oct 22, 2020 •

Copy link
Copy Markdown
Collaborator

The simplified regex looks like there will be a false positive for indented code.
Can you try adding

if (0 < 1) {
  x <- 42L
}

as a test case (no lints expected, if I understand your intentions)

Also, bad variable names might confuse the linter, such as

"my = bad = variable = name" <- 2.0
(actually two spaces in each gap - trimmed by github)

By the way: Your teammates code is okay with the tidyverse style guide

@f-ritter

Copy link
Copy Markdown
Contributor Author

Thanks for that edge case, you're right. What do you think about my new check?

Yeah, thats why I didn't add it to the default cases, but we want everyone in the team to use the same style.

@AshesITR

Copy link
Copy Markdown
Collaborator

I was thinking more like

expect_lint("\"my  =  variable\" <- 42.0", NULL, assignment_spaces)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants