-
Notifications
You must be signed in to change notification settings - Fork 72
Description
Background
I want to enforce consistent styling of a bioconductor package by running styler via github actions - after long long debugging I noticed that for certain files styler using the biocthis::bioc_style transformer transforms files back-and-forth between representations.
I don't know enough to understand if this behaviour is rather an issue with the bioc_style or styler.
Description
I run into the issue that some transforms can be unstable, i.e. running the style command multiple times keeps switching the file between two states:
styler::cache_deactivate()
styler::style_file('varia.R', transformers=biocthis::bioc_style())
With varia.R being one of these two representations that are constantly switched by above command:
get_qc_measurements <- function(
measurement_name,
qc_pattern = "(blank)|(QCpool)|(QCmix)|(blank)"
) {
grepl(qc_pattern, measurement_name)
}
and
get_qc_measurements <- function(
measurement_name,
qc_pattern = "(blank)|(QCpool)|(QCmix)|(blank)"
) {
grepl(qc_pattern, measurement_name)
}
Environment
R: 4.5.2
Packages: biocthis_1.17.4 styler_1.11.0
if (!requireNamespace("BiocManager", quietly = TRUE)) {
install.packages("BiocManager")
}
BiocManager::install("biocthis")
Thanks so much for this useful package!
Dirty workaround
I found by running styler twice, it is possible to detect oscillating files - added this as a temporary workaround for cicd.
Code here
- name: Check Bioconductor code style
run: |
library(styler)
library(biocthis)
# Disable caching to ensure consistent behavior
styler::cache_deactivate()
# Run styling twice to detect oscillations vs genuine issues
cat("First styling pass...\n")
styled1 <- styler::style_pkg(
transformers = biocthis::bioc_style(),
dry = "off"
)
cat("Second styling pass...\n")
styled2 <- styler::style_pkg(
transformers = biocthis::bioc_style(),
dry = "off"
)
# Check for different outcomes between passes
if (any(styled1$changed) != any(styled2$changed)) {
cat("❌ Mixed results detected - genuine style issues found!\n")
cat("First pass changed files:", any(styled1$changed), "\n")
cat("Second pass changed files:", any(styled2$changed), "\n")
if (any(styled1$changed)) {
changed_files1 <- names(styled1$changed)[styled1$changed]
cat("Files changed in first pass:\n")
cat(paste(" 📝", changed_files1), sep = "\n")
}
if (any(styled2$changed)) {
changed_files2 <- names(styled2$changed)[styled2$changed]
cat("Files changed in second pass:\n")
cat(paste(" 📝", changed_files2), sep = "\n")
}
quit(status = 1)
} else if (any(styled1$changed) && any(styled2$changed)) {
cat("⚠️ Styler oscillation detected - this is a known issue\n")
cat("Files affected by oscillation:\n")
oscillating_files <- names(styled1$changed)[styled1$changed]
cat(paste(" 🔄", oscillating_files), sep = "\n")
cat("Accepting current state as valid due to oscillation bug.\n")
} else if (any(styled1$changed)) {
cat("❌ Bioconductor style issues found (stable after second pass)\n")
changed_files <- names(styled1$changed)[styled1$changed]
cat(paste(" 📝", changed_files), sep = "\n")
cat("\n\n💡 To fix style issues locally, run:\n")
cat("Rscript scripts/style-bioc.R\n")
quit(status = 1)
} else {
cat("✅ All R code follows Bioconductor style guidelines!\n")
}