Skip to content

Commit

Permalink
Change the default indentation from 2 to 4
Browse files Browse the repository at this point in the history
This is the default in the Julia ecosystem, both in the official
guidelines and on various styles.

The Julia files in the template have been changed to use 4 spaces. The
other files in the template are still using 2 spaces. This should be
changed to 4 when pre-commit is run for the first time.

Update the consistency tests that verifies Copier's API to run the
pre-commit before the comparison, to ensure that formatting changes
don't influence the tests.

Closes #403
  • Loading branch information
abelsiqueira committed Aug 22, 2024
1 parent 90b3862 commit 50a3d1a
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 15 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ReusableTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ jobs:
arch: ${{ inputs.arch }}
- name: Use Julia cache
uses: julia-actions/cache@v2
- name: Setup Python
uses: actions/setup-python@v5
with:
cache: "pip"
- name: Cache pre-commit
uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: ${{ runner.os }}-pre-commit-${{ hashFiles('**/.pre-commit-config.yaml') }}
- name: Install pre-commit
run: pip install pre-commit
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
env:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning].

- Update pre-commit hook versions
- JuliaFormatter 1.0.58 -> 1.0.59
- Default Indentation changed from 2 to 4 (#403)

## [0.9.1] - 2024-07-24

Expand Down
2 changes: 1 addition & 1 deletion copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Indentation:
type: int
help: Indentation length (Used in .JuliaFormatter and other configuration files of formatters and linters if you add them)
validator: "{% if Indentation <= 0 %}Indentation must be positive{% endif %}"
default: 2
default: 4

# Optional
AnswerStrategy:
Expand Down
2 changes: 1 addition & 1 deletion src/debug/Data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const strategy_minimum = merge(
Dict(
"JuliaMinVersion" => "1.6",
"License" => "MIT",
"Indentation" => "2",
"Indentation" => "4",
"AnswerStrategy" => "minimum",
),
)
Expand Down
24 changes: 12 additions & 12 deletions template/docs/make.jl.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ DocMeta.setdocmeta!({{ PackageName }}, :DocTestSetup, :(using {{ PackageName }})
const page_rename = Dict("developer.md" => "Developer docs") # Without the numbers

makedocs(;
modules = [{{ PackageName }}],
authors = "{{ AuthorName }} <{{ AuthorEmail }}> and contributors",
repo = "https://github.com/{{ PackageOwner }}/{{ PackageName }}.jl/blob/{commit}{path}#{line}",
sitename = "{{ PackageName }}.jl",
format = Documenter.HTML(; canonical = "https://{{ PackageOwner }}.github.io/{{ PackageName }}.jl"),
pages = [
"index.md"
[
file for
file in readdir(joinpath(@__DIR__, "src")) if file != "index.md" && splitext(file)[2] == ".md"
]
],
modules = [{{ PackageName }}],
authors = "{{ AuthorName }} <{{ AuthorEmail }}> and contributors",
repo = "https://github.com/{{ PackageOwner }}/{{ PackageName }}.jl/blob/{commit}{path}#{line}",
sitename = "{{ PackageName }}.jl",
format = Documenter.HTML(; canonical = "https://{{ PackageOwner }}.github.io/{{ PackageName }}.jl"),
pages = [
"index.md"
[
file for file in readdir(joinpath(@__DIR__, "src")) if
file != "index.md" && splitext(file)[2] == ".md"
]
],
)

deploydocs(; repo = "github.com/{{ PackageOwner }}/{{ PackageName }}.jl")
2 changes: 1 addition & 1 deletion template/test/runtests.jl.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ using {{ PackageName }}
using Test

@testset "{{ PackageName }}.jl" begin
@test {{ PackageName }}.hello_world() == "Hello, World!"
@test {{ PackageName }}.hello_world() == "Hello, World!"
end
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[deps]
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
8 changes: 8 additions & 0 deletions test/test-consistency-with-copier-cli.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
@testset "Testing copy, recopy and rebase" begin
_with_tmp_dir() do dir_copier
run(`copier copy --vcs-ref HEAD --quiet $(C.args.copier.ask) $(C.template_path) .`)
_git_setup()
_full_precommit()

@testset "Compare copied project vs copier CLI baseline" begin
_with_tmp_dir() do dir_bestie
BestieTemplate.Copier.copy(dir_bestie, C.args.bestie.ask; quiet = true, vcs_ref = "HEAD")
_git_setup()
_full_precommit()
_test_diff_dir(dir_bestie, dir_copier)
end
end
Expand All @@ -21,6 +25,8 @@
overwrite = true,
vcs_ref = "HEAD",
)
_git_setup()
_full_precommit()
_test_diff_dir(dir_bestie, dir_copier)
end
end
Expand All @@ -36,6 +42,8 @@
quiet = true,
vcs_ref = "HEAD",
)
_git_setup()
_full_precommit()
_test_diff_dir(dir_bestie, dir_copier)
end
end
Expand Down
20 changes: 20 additions & 0 deletions test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ function _git_setup()
run(`git commit -q -m "First commit"`)
end

function _precommit()
try
read(`pre-commit run -a`) # run and ignore output
catch
nothing
end
end

function _full_precommit()
run(`git add .`)
_precommit()
run(`git add .`)
run(`git commit -q -m "git add . and pre-commit run -a"`)
end

function _with_tmp_dir(f, args...; kwargs...)
# Can't use mktempdir on GitHub actions willy nilly (at least on Mac)
tmpdir = get(ENV, "TMPDIR", mktempdir())
Expand Down Expand Up @@ -34,11 +49,16 @@ function _test_diff_dir(dir1, dir2)
ignore(line) = startswith("_commit")(line) || startswith("_src_path")(line)
@testset "$(basename(dir1)) vs $(basename(dir2))" begin
for (root, _, files) in walkdir(dir1)
if contains("node_modules")(root)
continue
end

nice_dir(file) =
replace(root, dir1 => "") |> out -> replace(out, r"^/" => "") |> out -> joinpath(out, file)
if nice_dir("") |> x -> occursin(r"[\\/]?git[\\/]+", x)
continue
end

@testset "File $(nice_dir(file))" for file in files
file1 = joinpath(root, file)
file2 = replace(file1, dir1 => dir2)
Expand Down

0 comments on commit 50a3d1a

Please sign in to comment.