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

Implement implicit_assignment_linter() #1814

Merged
merged 18 commits into from
Dec 8, 2022

Conversation

IndrajeetPatil
Copy link
Collaborator

Closes #1777


library(lintr)

# will produce lints
lint(
  text = "if (x <- 1L) TRUE",
  linters = implicit_assignment_linter()
)
#> <text>:1:7: warning: [implicit_assignment_linter] Avoid implicit assignments in function calls. For example, instead of `if (x <- 1L) { ... }`, write `x <- 1L; if (x) { ... }`.
#> if (x <- 1L) TRUE
#>       ^~

lint(
  text = "mean(x <- 1:4)",
  linters = implicit_assignment_linter()
)
#> <text>:1:8: warning: [implicit_assignment_linter] Avoid implicit assignments in function calls. For example, instead of `if (x <- 1L) { ... }`, write `x <- 1L; if (x) { ... }`.
#> mean(x <- 1:4)
#>        ^~

# okay
writeLines("x <- 1L\nif (x) TRUE")
#> x <- 1L
#> if (x) TRUE
lint(
  text = "x <- 1L\nif (x) TRUE",
  linters = implicit_assignment_linter()
)

writeLines("x <- 1:4\nmean(x)")
#> x <- 1:4
#> mean(x)
lint(
  text = "x <- 1:4\nmean(x)",
  linters = implicit_assignment_linter()
)

Created on 2022-12-08 with reprex v2.0.2

@codecov-commenter
Copy link

codecov-commenter commented Dec 8, 2022

Codecov Report

Merging #1814 (2cc6460) into main (77baa3e) will decrease coverage by 0.04%.
The diff coverage is 89.89%.

❗ Current head 2cc6460 differs from pull request most recent head 3469d9d. Consider uploading reports for the commit 3469d9d to get more accurate results

@@            Coverage Diff             @@
##             main    #1814      +/-   ##
==========================================
- Coverage   98.89%   98.85%   -0.05%     
==========================================
  Files         111      112       +1     
  Lines        4713     4796      +83     
==========================================
+ Hits         4661     4741      +80     
- Misses         52       55       +3     
Impacted Files Coverage Δ
R/get_source_expressions.R 93.93% <50.00%> (-0.46%) ⬇️
R/lint.R 96.72% <95.83%> (-0.07%) ⬇️
R/implicit_assignment_linter.R 100.00% <100.00%> (ø)
R/indentation_linter.R 100.00% <100.00%> (ø)
R/linter_tags.R 97.43% <100.00%> (+0.06%) ⬆️
R/xml_nodes_to_lints.R 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@IndrajeetPatil IndrajeetPatil marked this pull request as ready for review December 8, 2022 15:10
@IndrajeetPatil IndrajeetPatil changed the title WIP: Implement implicit_assignment_linter() Implement implicit_assignment_linter() Dec 8, 2022
@IndrajeetPatil IndrajeetPatil marked this pull request as draft December 8, 2022 15:38
@IndrajeetPatil IndrajeetPatil marked this pull request as draft December 8, 2022 15:38
@IndrajeetPatil IndrajeetPatil changed the title Implement implicit_assignment_linter() WIP: Implement implicit_assignment_linter() Dec 8, 2022
@IndrajeetPatil
Copy link
Collaborator Author

Converting back to draft because found a bunch of false positives.

@AshesITR
Copy link
Collaborator

AshesITR commented Dec 8, 2022

I feel like you need following-sibling everywhere you use following.

axis description
following Selects everything in the document after the closing tag of the current node
following-sibling Selects all siblings after the current node

@IndrajeetPatil
Copy link
Collaborator Author

I feel like you need following-sibling everywhere you use following.

Thanks! Yes, that was indeed the problem.
In my mind, I was thinking about sibling, but somehow wrote down just following.

@IndrajeetPatil IndrajeetPatil marked this pull request as ready for review December 8, 2022 20:27
@IndrajeetPatil IndrajeetPatil changed the title WIP: Implement implicit_assignment_linter() Implement implicit_assignment_linter() Dec 8, 2022
@IndrajeetPatil IndrajeetPatil merged commit 3119968 into main Dec 8, 2022
@IndrajeetPatil IndrajeetPatil deleted the 1777_implicit_assignment_linter branch December 8, 2022 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New linter for assignments within conditional expressions
4 participants