Skip to content

Commit

Permalink
Merge pull request #224 from 0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q/dev/Lin…
Browse files Browse the repository at this point in the history
…ospace

add indentation autoformatter
  • Loading branch information
0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q authored Jan 27, 2025
2 parents ad2c365 + 0906db2 commit 829cdd0
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '10051000'
ValidationKey: '10258650'
AutocreateReadme: yes
AutocreateCITATION: yes
AcceptedWarnings:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ vignettes/*.pdf
.Rproj.user
inst/doc
.idea/
lucode2.Rproj
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ cff-version: 1.2.0
message: If you use this software, please cite it using the metadata from this file.
type: software
title: 'lucode2: Code Manipulation and Analysis Tools'
version: 0.50.0
date-released: '2025-01-14'
version: 0.51.0
date-released: '2025-01-27'
abstract: A collection of tools which allow to manipulate and analyze code.
authors:
- family-names: Dietrich
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: lucode2
Title: Code Manipulation and Analysis Tools
Version: 0.50.0
Date: 2025-01-14
Version: 0.51.0
Date: 2025-01-27
Authors@R: c(
person("Jan Philipp", "Dietrich", , "[email protected]", role = c("aut", "cre"),
comment = c(affiliation = "Potsdam Institute for Climate Impact Research", ORCID = "0000-0002-4309-6431")),
Expand Down
40 changes: 40 additions & 0 deletions R/autoFormat.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ autoFormat <- function(files = getFilesToLint(), ignoreLintFreeFiles = TRUE,
# fix T_and_F_symbol lint (will only touch files with that kind of lint)
theOneAndOnlyTandFsymbolFixer(files)

# fix indentation lint (will only touch files with that kind of lint)
theOneAndOnlyLinospace(files)

if (ignoreLintFreeFiles) {
# keep only files with linter warnings
files <- unique(names(lint(files)))
Expand Down Expand Up @@ -74,3 +77,40 @@ theOneAndOnlyTandFsymbolFixer <- function(files) {
}
}
}

# Fix all indentation to please the linter god
theOneAndOnlyLinospace <- function(files, iterMax = 10000L) {
for (f in files) {
t <- readLines(f)
i <- 1
while (0 < length(theLint <- lintr::lint(
filename = paste(t, collapse = "\n"),
linters = list(lintr::indentation_linter()),
parse_settings = FALSE))
&& i < iterMax
) {

for (j in seq_along(theLint)) {
line <- theLint[[j]][["line_number"]]
should <- as.integer(sub(".*be ([0-9]+) spaces but is.*", "\\1",
theLint[[j]][["message"]]))
is <- as.integer(sub(".*but is ([0-9]+) spaces.$", "\\1",
theLint[[j]][["message"]]))

t[[line]] <- if (is < should) {
paste(c(rep(" ", should - is), t[[line]]), collapse = "")
} else {
substr(t[[line]], is - should + 1, 1000000L)
}

i <- i + 1
}
}

if (i == iterMax) {
stop("Reached maximum number of iterations.")
}

writeLines(t, f)
}
}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Code Manipulation and Analysis Tools

R package **lucode2**, version **0.50.0**
R package **lucode2**, version **0.51.0**

[![CRAN status](https://www.r-pkg.org/badges/version/lucode2)](https://cran.r-project.org/package=lucode2) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4389418.svg)](https://doi.org/10.5281/zenodo.4389418) [![R build status](https://github.com/pik-piam/lucode2/workflows/check/badge.svg)](https://github.com/pik-piam/lucode2/actions) [![codecov](https://codecov.io/gh/pik-piam/lucode2/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/lucode2) [![r-universe](https://pik-piam.r-universe.dev/badges/lucode2)](https://pik-piam.r-universe.dev/builds)

Expand Down Expand Up @@ -39,7 +39,7 @@ In case of questions / problems please contact Jan Philipp Dietrich <dietrich@pi

To cite package **lucode2** in publications use:

Dietrich J, Sauer P, Klein D, Giannousakis A, Bonsch M, Bodirsky B, Baumstark L, Richters O, Pflüger M (2025). "lucode2: Code Manipulation and Analysis Tools." doi:10.5281/zenodo.4389418 <https://doi.org/10.5281/zenodo.4389418>, Version: 0.50.0, <https://github.com/pik-piam/lucode2>.
Dietrich J, Sauer P, Klein D, Giannousakis A, Bonsch M, Bodirsky B, Baumstark L, Richters O, Pflüger M (2025). "lucode2: Code Manipulation and Analysis Tools." doi:10.5281/zenodo.4389418 <https://doi.org/10.5281/zenodo.4389418>, Version: 0.51.0, <https://github.com/pik-piam/lucode2>.

A BibTeX entry for LaTeX users is

Expand All @@ -48,9 +48,9 @@ A BibTeX entry for LaTeX users is
title = {lucode2: Code Manipulation and Analysis Tools},
author = {Jan Philipp Dietrich and Pascal Sauer and David Klein and Anastasis Giannousakis and Markus Bonsch and Benjamin Leon Bodirsky and Lavinia Baumstark and Oliver Richters and Mika Pflüger},
doi = {10.5281/zenodo.4389418},
date = {2025-01-14},
date = {2025-01-27},
year = {2025},
url = {https://github.com/pik-piam/lucode2},
note = {Version: 0.50.0},
note = {Version: 0.51.0},
}
```
21 changes: 0 additions & 21 deletions lucode2.Rproj

This file was deleted.

0 comments on commit 829cdd0

Please sign in to comment.