@@ -44,26 +44,34 @@ use_lintr <- function(path = ".", type = c("tidyverse", "full")) {
44
44
)
45
45
write.dcf(the_config , config_file , width = Inf )
46
46
47
- # Some OS can only normalize a path if the associated file or folder exists, so the path needs to be re-normalized
48
- config_file <- normalizePath(file.path(path , lintr_option(" linter_file" )), mustWork = TRUE , winslash = " /" )
49
- pkg_path <- normalizePath(path , mustWork = TRUE , winslash = " /" )
50
- # Check if config_file is in package i.e. lintr_option("linter_file") != "../.lintr"
51
- if (file.exists(file.path(path , " DESCRIPTION" )) && startsWith(config_file , prefix = pkg_path )) {
52
- # Skip a extra character for the leading `/`
53
- rel_path <- substring(config_file , first = nchar(pkg_path ) + 2L , last = nchar(config_file ))
54
- ignore_path <- file.path(pkg_path , " .Rbuildignore" )
55
- if (! file.exists(ignore_path )) file.create(ignore_path )
56
- # Follow the same procedure as base R to see if the file is already ignored
57
- ignore <- tryCatch({
58
- trimws(readLines(ignore_path ))
59
- }, warning = function (e ) {
60
- cat(file = ignore_path , " \n " , append = TRUE )
61
- trimws(readLines(ignore_path ))
47
+ if (file.exists(file.path(path , " DESCRIPTION" ))) {
48
+ # Some OS can only normalize a path if the associated file or folder exists, so the path needs to be re-normalized
49
+ tryCatch({
50
+ pkg_path <- normalizePath(path , mustWork = TRUE , winslash = " /" )
51
+ config_file <- normalizePath(file.path(path , lintr_option(" linter_file" )), mustWork = TRUE , winslash = " /" )
52
+ }, error = function (e ) {
53
+ stop(" No entry could be added to the .Rbuildignore." , call. = FALSE )
62
54
})
63
- ignore <- ignore [nzchar(ignore )]
64
- if (! any(vapply(ignore , function (x ) grepl(rel_path , pattern = x , perl = TRUE , ignore.case = TRUE ), logical (1L )))) {
65
- cat(file = ignore_path , rex :: rex(start , rel_path , end ), sep = " \n " , append = TRUE )
66
- message(" Adding " , rel_path , " to .Rbuildignore" )
55
+ # Check if config_file is in package i.e. lintr_option("linter_file") != "../.lintr"
56
+ if (startsWith(config_file , prefix = pkg_path )) {
57
+ # Skip a extra character for the leading `/`
58
+ rel_path <- substring(config_file , first = nchar(pkg_path ) + 2L , last = nchar(config_file ))
59
+ ignore_path <- file.path(pkg_path , " .Rbuildignore" )
60
+ if (! file.exists(ignore_path )) file.create(ignore_path )
61
+ # Follow the same procedure as base R to see if the file is already ignored
62
+ ignore <- tryCatch({
63
+ trimws(readLines(ignore_path ))
64
+ }, warning = function (e ) {
65
+ cat(file = ignore_path , " \n " , append = TRUE )
66
+ trimws(readLines(ignore_path ))
67
+ })
68
+ ignore <- ignore [nzchar(ignore )]
69
+ already_ignored <-
70
+ any(vapply(ignore , FUN = grepl , x = rel_path , perl = TRUE , ignore.case = TRUE , FUN.VALUE = logical (1L )))
71
+ if (! already_ignored ) {
72
+ cat(file = ignore_path , rex :: rex(start , rel_path , end ), sep = " \n " , append = TRUE )
73
+ message(" Adding " , rel_path , " to .Rbuildignore" )
74
+ }
67
75
}
68
76
}
69
77
0 commit comments