Skip to content

Commit

Permalink
fix lints with flint (#475)
Browse files Browse the repository at this point in the history
* fix paste0 lints with flint

* add flint setup files
  • Loading branch information
rempsyc authored Dec 16, 2024
1 parent 39409c8 commit 8b102bb
Show file tree
Hide file tree
Showing 67 changed files with 2,097 additions and 21 deletions.
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ tests\^spelling
^WIP/.
\.code-workspace$
^CRAN-SUBMISSION$


# flint files
^flint$
8 changes: 4 additions & 4 deletions R/cite_easystats.R
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,9 @@ cite_easystats <- function(packages = "easystats",
ref_packages[length(ref_packages)]
)
ref_packages[[2]] <- split(ref_packages[[2]], cumsum(ref_packages[[2]] == ""))

Check warning on line 348 in R/cite_easystats.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/cite_easystats.R,line=348,col=58,[nzchar_linter] Use !nzchar(x) instead of x == "". Note that unlike nzchar(), EQ coerces to character, so you'll have to use as.character() if x is a factor. Whenever missing data is possible, please take care to use nzchar(., keepNA = TRUE); nzchar(NA) is TRUE by default.
ref_packages.index <- grep(paste0("id: ((", paste0(packages, collapse = ")|("), "))"), ref_packages[[2]])
ref_packages.index <- grep(paste0("id: ((", paste(packages, collapse = ")|("), "))"), ref_packages[[2]])
ref_packages[[2]] <- unlist(ref_packages[[2]][ref_packages.index], use.names = FALSE)
ref_packages <- paste0(unlist(ref_packages, use.names = FALSE), collapse = "\n")
ref_packages <- paste(unlist(ref_packages, use.names = FALSE), collapse = "\n")
} else {
ref_packages <- readLines(system.file("easystats_bib.bib", package = "report"))
ref_packages[ref_packages == " version = {%s}"] <- sprintf(
Expand All @@ -365,10 +365,10 @@ cite_easystats <- function(packages = "easystats",
ref_packages <- split(ref_packages, cumsum(ref_packages == ""))

Check warning on line 365 in R/cite_easystats.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/cite_easystats.R,line=365,col=48,[nzchar_linter] Use !nzchar(x) instead of x == "". Note that unlike nzchar(), EQ coerces to character, so you'll have to use as.character() if x is a factor. Whenever missing data is possible, please take care to use nzchar(., keepNA = TRUE); nzchar(NA) is TRUE by default.
ref_packages.index <- grep(paste0(
"((article)|(software))\\{((",
paste0(packages, collapse = ")|("), "))"
paste(packages, collapse = ")|("), "))"
), ref_packages)
ref_packages <- unlist(ref_packages[ref_packages.index], use.names = FALSE)
ref_packages <- paste0(unlist(ref_packages, use.names = FALSE), collapse = "\n")
ref_packages <- paste(unlist(ref_packages, use.names = FALSE), collapse = "\n")
}


Expand Down
2 changes: 1 addition & 1 deletion R/format_formula.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
#' @export
format_formula <- function(x, what = "conditional") {
f <- insight::safe_deparse(insight::find_formula(x, verbose = FALSE)[[what]])
paste0("formula: ", paste0(f, collapse = " + "))
paste0("formula: ", paste(f, collapse = " + "))
}
4 changes: 2 additions & 2 deletions R/report.bayesfactor_models.R
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ report_text.bayesfactor_inclusion <- function(x,
bf_text <- paste0(
"Bayesian model averaging (BMA) was used to obtain the average evidence ",
"for each predictor. We found ",
paste0(
paste(
paste0(bf_results$evidence, " including ", bf_results$Term),
collapse = "; "
), "."
Expand Down Expand Up @@ -349,7 +349,7 @@ report_text.bayesfactor_inclusion <- function(x,
bf_explain,
paste0(
"We found ",
paste0(
paste(
paste0(
bf_results$evidence, " including ", bf_results$Term,
", with models including ", bf_results$Term,
Expand Down
4 changes: 2 additions & 2 deletions R/report.character.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ report_text.character <- function(x,
...
)

text <- paste0(summary(params), collapse = "; ")
text <- paste(summary(params), collapse = "; ")
if (nrow(entries) > 1) {
text <- paste0(name, ": ", nrow(entries), " entries, such as ", text)
} else {
Expand Down Expand Up @@ -198,5 +198,5 @@ report_statistics.character <- function(x,
text <- paste0(entries$Entry, ", n = ", entries$n_Entry)
}

as.report_statistics(paste0(text, collapse = "; "), summary = paste0(text[1:n_entries], collapse = "; "))
as.report_statistics(paste(text, collapse = "; "), summary = paste(text[1:n_entries], collapse = "; "))
}
2 changes: 1 addition & 1 deletion R/report.estimate_contrasts.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ report_text.estimate_contrasts <- function(x, table = NULL, ...) {
collapse = ". "
)

text <- paste("The marginal contrasts analysis suggests the following.", paste0(text, collapse = ""))
text <- paste("The marginal contrasts analysis suggests the following.", paste(text, collapse = ""))

as.report_text(text)
}
2 changes: 1 addition & 1 deletion R/report.factor.R
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ report_statistics.factor <- function(x, table = NULL, levels_percentage = "auto"
)
}

as.report_statistics(paste0(text_full, collapse = "; "), summary = paste0(text, collapse = "; "))
as.report_statistics(paste(text_full, collapse = "; "), summary = paste(text, collapse = "; "))
}

#' @export
Expand Down
2 changes: 1 addition & 1 deletion R/report.stanreg.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ report_priors.stanreg <- function(x, ...) {
)
)

values <- paste0(values, collapse = "; ")
values <- paste(values, collapse = "; ")
values <- paste0(params$Prior_Distribution, " (", values, ")")

if (length(unique(values)) == 1 && nrow(params) > 1) {
Expand Down
2 changes: 1 addition & 1 deletion R/report_effectsize.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ print.report_effectsize <- function(x, ...) {
cat(attributes(x)$rules, "\n\n")
}

cat(paste0(x, collapse = "\n"))
cat(paste(x, collapse = "\n"))
}


Expand Down
2 changes: 1 addition & 1 deletion R/report_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ summary.report_info <- function(object, ...) {

#' @export
print.report_info <- function(x, ...) {
cat(paste0(x, collapse = "\n"))
cat(paste(x, collapse = "\n"))
}


Expand Down
2 changes: 1 addition & 1 deletion R/report_intercept.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ summary.report_intercept <- function(object, ...) {

#' @export
print.report_intercept <- function(x, ...) {
cat(paste0(x, collapse = "\n"))
cat(paste(x, collapse = "\n"))
}


Expand Down
2 changes: 1 addition & 1 deletion R/report_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ summary.report_model <- function(object, ...) {

#' @export
print.report_model <- function(x, ...) {
cat(paste0(x, collapse = "\n"))
cat(paste(x, collapse = "\n"))
}
4 changes: 2 additions & 2 deletions R/report_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ as.character.report_parameters <- function(x, prefix = NULL, ...) {

# Concatenate
text <- paste0(prefix, x)
text <- paste0(text, collapse = "\n")
text <- paste(text, collapse = "\n")
text
}

Expand Down Expand Up @@ -125,7 +125,7 @@ print.report_parameters <- function(x, ...) {
# Interaction
if (grepl(" * ", names[i], fixed = TRUE)) {
parts <- unlist(strsplit(names[i], " * ", fixed = TRUE))
basis <- paste0(utils::head(parts, -1), collapse = " * ")
basis <- paste(utils::head(parts, -1), collapse = " * ")
names[i] <- paste0("The interaction effect of ", utils::tail(parts, 1), " on ", basis)

# Intercept
Expand Down
2 changes: 1 addition & 1 deletion R/report_priors.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ summary.report_priors <- function(object, ...) {

#' @export
print.report_priors <- function(x, ...) {
cat(paste0(x, collapse = "\n"))
cat(paste(x, collapse = "\n"))
}
2 changes: 1 addition & 1 deletion R/report_random.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ summary.report_random <- function(object, ...) {

#' @export
print.report_random <- function(x, ...) {
cat(paste0(x, collapse = "\n"))
cat(paste(x, collapse = "\n"))
}
2 changes: 1 addition & 1 deletion R/report_statistics.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ summary.report_statistics <- summary.report_parameters

#' @export
print.report_statistics <- function(x, ...) {
cat(paste0(x, collapse = "\n"))
cat(paste(x, collapse = "\n"))
}
Binary file added flint/cache_file_state.rds
Binary file not shown.
49 changes: 49 additions & 0 deletions flint/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
keep:
- any_duplicated
- any_is_na
- class_equals
- condition_message
- double_assignment
- duplicate_argument
- empty_assignment
- equal_assignment
- equals_na
- expect_comparison
- expect_identical
- expect_length
- expect_named
- expect_not
- expect_null
- expect_true_false
- expect_type
- for_loop_index
- function_return
- implicit_assignment
- is_numeric
- length_levels
- length_test
- lengths
- library_call
- literal_coercion
- matrix_apply
- missing_argument
- nested_ifelse
- numeric_leading_zero
- outer_negation
- package_hooks
- paste
- redundant_equals
- redundant_ifelse
- rep_len
- right_assignment
- sample_int
- semicolon
- seq
- sort
- T_and_F_symbol
- todo_comment
- undesirable_function
- undesirable_operator
- unnecessary_nesting
- unreachable_code
- which_grepl
97 changes: 97 additions & 0 deletions flint/rules/builtin/T_and_F_symbol.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
id: true_false_symbol
language: r
severity: warning
rule:
pattern: T
kind: identifier
not:
any:
- precedes:
any:
- pattern: <-
- pattern: =
- regex: ^~$
- follows:
any:
- pattern: $
- regex: ^~$
- inside:
any:
- kind: parameter
- kind: call
- kind: binary_operator
follows:
regex: ^~$
stopBy: end
stopBy:
kind:
argument
fix: TRUE
message: Use TRUE instead of the symbol T.

---

id: true_false_symbol-2
language: r
severity: warning
rule:
pattern: F
kind: identifier
not:
any:
- precedes:
any:
- pattern: <-
- pattern: =
- regex: ^~$
- follows:
any:
- pattern: $
- regex: ^~$
- inside:
any:
- kind: parameter
- kind: call
- kind: binary_operator
follows:
regex: ^~$
stopBy: end
stopBy:
kind:
argument
fix: FALSE
message: Use FALSE instead of the symbol F.

---

id: true_false_symbol-3
language: r
severity: warning
rule:
pattern: T
kind: identifier
precedes:
any:
- pattern: <-
- pattern: =
not:
inside:
kind: argument
message: Don't use T as a variable name, as it can break code relying on T being TRUE.

---

id: true_false_symbol-4
language: r
severity: warning
rule:
pattern: F
kind: identifier
precedes:
any:
- pattern: <-
- pattern: =
not:
inside:
kind: argument
message: Don't use F as a variable name, as it can break code relying on F being FALSE.
13 changes: 13 additions & 0 deletions flint/rules/builtin/absolute_path.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# id: absolute_path-1
# language: r
# severity: warning
# rule:
# kind: string_content
# any:
# - regex: '^~[[:alpha:]]'
# - regex: '^~/[[:alpha:]]'
# - regex: '^[[:alpha:]]:'
# - regex: '^(/|~)$'
# - regex: '^/[[:alpha:]]'
# - regex: '^\\'
# message: Do not use absolute paths.
Loading

0 comments on commit 8b102bb

Please sign in to comment.