-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Package: todor | ||
Title: What the Package Does (one line, title case) | ||
Version: 0.0.0.9000 | ||
Authors@R: person("Dominik", "Krzemiński", | ||
email = "first.last@example.com", | ||
role = c("aut", "cre")) | ||
Description: What the package does (one paragraph). | ||
Depends: R (>= 3.3.3) | ||
Imports: stringr, | ||
rex | ||
License: What license is it under? | ||
Encoding: UTF-8 | ||
LazyData: true | ||
RoxygenNote: 6.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(todor) | ||
import(rstudioapi) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
find_package <- function(path = getwd()) { | ||
start_wd <- getwd() | ||
on.exit(setwd(start_wd)) | ||
setwd(path) | ||
|
||
prev_path <- "" | ||
while (!file.exists(file.path(prev_path, "DESCRIPTION"))) { | ||
if (prev_path == getwd()) { | ||
return(NULL) | ||
} | ||
prev_path <- getwd() | ||
setwd("..") | ||
} | ||
prev_path | ||
} | ||
|
||
process_file <- function(filepath, patterns) { | ||
con = file(filepath, "r") | ||
n <- 1 | ||
markers <- list() | ||
while (TRUE) { | ||
line = readLines(con, n = 1) | ||
if (length(line) == 0) { | ||
break | ||
} | ||
pattern_check <- find_pattern(line, patterns = patterns) | ||
if (!is.null(pattern_check)) | ||
markers[[length(markers) + 1]] <- list(nr = n, | ||
type = pattern_check, | ||
text = stringr::str_replace( | ||
line, pattern_check, "") | ||
) | ||
n <- n + 1 | ||
} | ||
close(con) | ||
markers | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
find_pattern <- function(text, patterns = c("TODO", "FIXIT")) { | ||
pattern <- paste(patterns, collapse="|") | ||
pattern <- sprintf("(%s)", pattern) | ||
extr <- stringr::str_extract(text, pattern) | ||
if (!is.na(extr)) { | ||
extr <- stringr::str_extract(extr, "[a-zA-Z]+") | ||
} | ||
else | ||
extr <- NULL | ||
extr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#' TODOR | ||
#' This package helps you to find all places in your code with places | ||
#' to be filled in the future. | ||
#' | ||
#' @name todor | ||
NULL | ||
|
||
create_markers <- function(todo.list) { | ||
markers <- list() | ||
for (name in names(todo.list)) { | ||
if (length(todo.list[[name]]) == 0) next | ||
for (i in 1:length(todo.list[[name]])) { | ||
x <- todo.list[[name]][[i]] | ||
markers[[length(markers) + 1]] <- list( | ||
type = "info", | ||
file = name, | ||
line = x$nr, | ||
column = 1, | ||
message = sprintf("[ %s ] %s", x$type, x$text) | ||
) | ||
} | ||
} | ||
markers | ||
} | ||
|
||
#' Build Rstudio Markers | ||
#' | ||
#' @param markers list of markers | ||
#' | ||
#' @import rstudioapi | ||
build_rstudio_markers <- function(markers){ | ||
rstudioapi::callFun("sourceMarkers", | ||
name = "todor", | ||
markers = markers, | ||
basePath = NULL, | ||
autoSelect = "first") | ||
} | ||
|
||
#' @export | ||
todor <- function(todo_types = NULL) { | ||
pkg_path <- find_package() | ||
files <- dir( | ||
path = file.path(pkg_path, | ||
c("R", "tests", "inst") | ||
), | ||
pattern = rex::rex(".", one_of("Rr"), end), | ||
recursive = TRUE, | ||
full.names = TRUE | ||
) | ||
# Default TODO types | ||
patterns <- c("FIXME", "TODO", "CHANGED", "IDEA", | ||
"HACK", "NOTE", "REVIEW", "BUG", | ||
"QUESTION", "COMBAK", "TEMP") | ||
if (is.null(todo_types)) | ||
todo_types <- patterns | ||
else { | ||
if (!all(todo_types %in% patterns)) | ||
stop(paste("One or more 'todo_types' were not recognized.", | ||
"See documentation of 'todor' for more information")) | ||
} | ||
processed <- sapply(files, function(x) process_file(x, todo_types)) | ||
markers <- create_markers(processed) | ||
build_rstudio_markers(markers) | ||
} | ||
|
||
todorAddin <- function() { | ||
todor() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Name: Find TODOs | ||
Description: Find all places in your package which require more work. | ||
Binding: todorAddin | ||
Interactive: false |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Version: 1.0 | ||
|
||
RestoreWorkspace: No | ||
SaveWorkspace: No | ||
AlwaysSaveHistory: Default | ||
|
||
EnableCodeIndexing: Yes | ||
UseSpacesForTab: Yes | ||
NumSpacesForTab: 2 | ||
Encoding: UTF-8 | ||
|
||
RnwWeave: Sweave | ||
LaTeX: pdfLaTeX | ||
|
||
AutoAppendNewline: Yes | ||
StripTrailingWhitespace: Yes | ||
|
||
BuildType: Package | ||
PackageUseDevtools: Yes | ||
PackageInstallArgs: --no-multiarch --with-keep.source | ||
PackageRoxygenize: rd,collate,namespace |