Skip to content

Conversation

@vituri
Copy link
Contributor

@vituri vituri commented Feb 17, 2025

Have you read the Contributing Guidelines?

Issue #134

Description

The problem was in find_source_lines_to_retain, which that calculates which lines are before and after the box::use calls:

find_source_lines_to_retain <- function(source_file_lines, box_lines) {
  source_lines <- seq(1, length(source_file_lines))
  empty_source_lines <- which(grepl(pattern = "^[[:space:]]*$", source_file_lines))
  non_box_lines <- source_lines[!source_lines %in% box_lines$all]
  end_of_box_calls <- ifelse(
      empty_source_lines[empty_source_lines > box_lines$max][1] == box_lines$max + 1,
    box_lines$max + 1,
    box_lines$max
  )
  lines_before_box <- non_box_lines[
    !non_box_lines %in% empty_source_lines &
      non_box_lines < box_lines$max
  ]
  lines_after_box <- non_box_lines[non_box_lines > end_of_box_calls]

  list(
    "before" = lines_before_box,
    "after" = lines_after_box
  )
}

This line will be integer(0) when there are no empty lines:

  empty_source_lines <- which(grepl(pattern = "^[[:space:]]*$", source_file_lines))

so I changed end_of_box_calls to this:

  end_of_box_calls <- ifelse(
    !rlang::is_empty(empty_source_lines) &&
      empty_source_lines[empty_source_lines > box_lines$max][1] == box_lines$max + 1,
    box_lines$max + 1,
    box_lines$max
  )

and add 2 tests to cover this case.

Definition of Done

  • The change is thoroughly documented.
  • The CI passes (R CMD check, linter, unit tests, spelling).
  • Any generated files have been updated (e.g. .Rd files with roxygen2::roxygenise())

@vituri vituri changed the title [lintr] fix spacing and implicit return calls Fix [STYLE_bug] When styling does not find a box::use, all lines are converted into NA #134 Feb 17, 2025
@codecov
Copy link

codecov bot commented Feb 17, 2025

Codecov Report

Attention: Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 96.93%. Comparing base (320452b) to head (f65d34f).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
R/namespaced_function_calls.R 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #155   +/-   ##
=======================================
  Coverage   96.92%   96.93%           
=======================================
  Files          24       24           
  Lines        1172     1173    +1     
=======================================
+ Hits         1136     1137    +1     
  Misses         36       36           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vituri vituri self-assigned this Feb 17, 2025
find_source_lines_to_retain <- function(source_file_lines, box_lines) {
source_lines <- seq(1, length(source_file_lines))
empty_source_lines <- which(grepl(pattern = "^[:space:]*$", source_file_lines))
empty_source_lines <- which(grepl(pattern = "^[[:space:]]*$", source_file_lines))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch! @vituri

non_box_lines <- source_lines[!source_lines %in% box_lines$all]
end_of_box_calls <- ifelse(
empty_source_lines[empty_source_lines > box_lines$max][1] == box_lines$max + 1,
!rlang::is_empty(empty_source_lines) &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch! @vituri

@radbasa radbasa merged commit 3731542 into main Jun 19, 2025
6 of 7 checks passed
@radbasa radbasa deleted the 134-style_bug-when-styling-does-not-find-a-boxuse-all-lines-are-converted-into-na branch June 19, 2025 08:57
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.

[STYLE_bug] When styling does not find a box::use, all lines are converted into NA

3 participants