Skip to content

Commit 90ea8d0

Browse files
committed
add remove_duplicated_comments option
1 parent 8dbb1f1 commit 90ea8d0

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ Imports:
2121
tidyr,
2222
glue,
2323
assertthat,
24-
stringr
24+
stringr,
25+
stringdist

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ importFrom(dplyr,everything)
1313
importFrom(dplyr,filter)
1414
importFrom(dplyr,full_join)
1515
importFrom(dplyr,group_by)
16+
importFrom(dplyr,lag)
1617
importFrom(dplyr,lead)
1718
importFrom(dplyr,left_join)
1819
importFrom(dplyr,mutate)
@@ -28,6 +29,7 @@ importFrom(purrr,map2)
2829
importFrom(purrr,map_chr)
2930
importFrom(rlang,"%||%")
3031
importFrom(rlang,is_missing)
32+
importFrom(stringdist,stringdist)
3133
importFrom(stringr,str_count)
3234
importFrom(stringr,str_replace_all)
3335
importFrom(tibble,as_tibble)

R/dockerile.R

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@
3131
#'
3232
#' @importFrom R6 R6Class
3333
#' @importFrom tibble tibble rownames_to_column
34-
#' @importFrom dplyr bind_rows pull filter lead mutate n
34+
#' @importFrom dplyr bind_rows pull filter lead mutate n lag lead
3535
#' @importFrom glue glue glue_collapse
3636
#' @importFrom rlang is_missing
3737
#' @importFrom stringr str_count str_replace_all
3838
#' @importFrom purrr map
39+
#' @importFrom stringdist stringdist
3940
#' @importFrom assertthat assert_that
4041
#' @export
4142
#'
@@ -248,8 +249,20 @@ Dockerfile <- R6Class(
248249
write = function(as = "Dockerfile"){
249250
return(self$string)
250251
},
251-
merge = function(Dockerfile) {
252+
merge = function(Dockerfile, remove_duplicated_comments = TRUE) {
252253
self$commands <- merge_dockerfiles(self$commands, Dockerfile$commands)
254+
255+
if(remove_duplicated_comments) {
256+
self$commands %>%
257+
mutate(
258+
dist_lag = stringdist(raw, lag(raw)),
259+
dist_lead = stringdist(raw, lead(raw))
260+
) %>%
261+
filter(name == "COMMENT", (dist_lead <= 2 | dist_lag <= 2)) %>%
262+
pull(lineno) %>%
263+
map(private$..remove_line)
264+
}
265+
253266
invisible(self)
254267
},
255268
remove_cmd = function(cmd, lineno){

man/Dockerfile.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)