Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assignment_linter() gains operator= argument to allow, e.g. '=' assignments #2711

Merged
merged 23 commits into from
Feb 9, 2025

Conversation

MichaelChirico
Copy link
Collaborator

Supersedes #2698 and #2521. h/t again @J-Moravec for getting the ball rolling here.

Closes #2441.

This also un-couples the linted operator from the allow_trailing behavior; lints generated by the operator used are now independent of lints generated by line-trailing assignment operators:

## current 'main'
lint("a <-
1", assignment_linter(allow_trailing=FALSE))
# <text>:1:3: style: [assignment_linter] Assignment <- should not be trailing at the end of a line.
# a <-
#   ^~
lint("a =
1", assignment_linter(allow_trailing=FALSE))
# <text>:1:3: style: [assignment_linter] Use <-, not =, for assignment.
# a =
#   ^

## current branch (assignment-operator)
lint("a <-
1", assignment_linter(allow_trailing=FALSE))
# <text>:1:3: style: [assignment_linter] Assignment <- should not be trailing at the end of a line.
# a <-
#   ^~
lint("a =
1", assignment_linter(allow_trailing=FALSE))
# <text>:1:3: style: [assignment_linter] Use one of <-, <<- for assignment, not =.
# a =
#   ^
# <text>:1:3: style: [assignment_linter] Assignment = should not be trailing at the end of a line.
# a =
#   ^

Having <<- allowed by default is back-compatible, but does strike me as odd -- should we also plan to remove this from the defaults?

@MichaelChirico MichaelChirico changed the title Assignment operator assignment_linter() gains operator= argument to allow, e.g. '=' assignments Jan 28, 2025
IndrajeetPatil
IndrajeetPatil previously approved these changes Jan 31, 2025
@MichaelChirico
Copy link
Collaborator Author

Thanks @IndrajeetPatil! I'd also like to get feedback from @AshesITR in this case since he commented a lot on the earlier PRs & this will be released soon afterwards.

@IndrajeetPatil
Copy link
Collaborator

Having <<- allowed by default is back-compatible, but does strike me as odd -- should we also plan to remove this from the defaults?

Yeah, I think it'll be good to remove it from the defaults.

Copy link
Collaborator

@AshesITR AshesITR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff, just a few kinks that could be ironed out.

Copy link
Collaborator

@AshesITR AshesITR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically GTG. Nice work, thanks!

@AshesITR
Copy link
Collaborator

AshesITR commented Feb 7, 2025

Having <<- allowed by default is back-compatible, but does strike me as odd -- should we also plan to remove this from the defaults?

Yeah, I think it'll be good to remove it from the defaults.

Is there advice in the style guide that motivates this change? If so, I'd be fine with shipping another breaking change related to this linter, given that we do impact analysis first.
Otherwise I see no clear cause to change our default behavior.

@MichaelChirico
Copy link
Collaborator Author

Having <<- allowed by default is back-compatible, but does strike me as odd -- should we also plan to remove this from the defaults?

Yeah, I think it'll be good to remove it from the defaults.

Is there advice in the style guide that motivates this change? If so, I'd be fine with shipping another breaking change related to this linter, given that we do impact analysis first. Otherwise I see no clear cause to change our default behavior.

Ah, I always assumed there was such advice, but there's not. I think there should be:

tidyverse/style#239

But you're right we shouldn't introduce a breaking change at this late hour if it doesn't contradict the style guide.

On the other hand, {lintr}'s own defaults already do discourage <<-: <<- is a default undesirable operator.

So at a minimum, we have some internal contradiction in our defaults.

I filed #2717 as a follow-up -- we should at least resolve the conflict in the next release regardless of if there's movement in the upstream style guide report.

@MichaelChirico MichaelChirico merged commit fe958e4 into main Feb 9, 2025
19 checks passed
@MichaelChirico MichaelChirico deleted the assignment-operator branch February 9, 2025 14:48
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.

Extend assignment_linter() to enforce '=' by default for assignment
3 participants