Skip to content

Commit

Permalink
Pretty-format JSON files (cookiecutter#1864)
Browse files Browse the repository at this point in the history
* Add a pre-commit hook to standardize JSON file formatting

* Enforce JSON formatting standards

* Feedback: Indent JSON files with 2 spaces
  • Loading branch information
kurtmckee authored Jun 16, 2023
1 parent bc493bf commit 6761ffd
Show file tree
Hide file tree
Showing 26 changed files with 164 additions and 130 deletions.
7 changes: 6 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ repos:
- id: check-symlinks
- id: check-case-conflict
- id: check-docstring-first
- id: check-json
- id: pretty-format-json
args:
- "--autofix"
- "--indent=2"
- "--no-sort-keys"
- "--no-ensure-ascii"
exclude: "invalid-syntax.json|tests/fake-repo-bad-json/cookiecutter.json|tests/fake-repo/cookiecutter.json"
- id: check-toml
- id: check-xml
Expand Down
8 changes: 4 additions & 4 deletions tests/fake-nested-templates/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"template": [
"fake-project (fake-project)"
]
}
"template": [
"fake-project (fake-project)"
]
}
2 changes: 1 addition & 1 deletion tests/fake-nested-templates/fake-project/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{}
34 changes: 17 additions & 17 deletions tests/fake-repo-dict/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"project_slug": "fake-project-dict",
"file_types": {
"png": {
"name": "Portable Network Graphic",
"library": "libpng",
"apps": [
"GIMP"
]
},
"bmp": {
"name": "Bitmap",
"library": "libbmp",
"apps": [
"Paint",
"GIMP"
]
}
"project_slug": "fake-project-dict",
"file_types": {
"png": {
"name": "Portable Network Graphic",
"library": "libpng",
"apps": [
"GIMP"
]
},
"bmp": {
"name": "Bitmap",
"library": "libbmp",
"apps": [
"Paint",
"GIMP"
]
}
}
}
20 changes: 10 additions & 10 deletions tests/fake-repo-dir/my-dir/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"full_name": "Audrey Roy",
"email": "audreyr@gmail.com",
"github_username": "audreyr",
"project_name": "Fake Project",
"repo_name": "fake-project",
"project_short_description": "This is a fake project.",
"release_date": "2013-07-28",
"year": "2013",
"version": "0.1"
}
"full_name": "Audrey Roy",
"email": "audreyr@gmail.com",
"github_username": "audreyr",
"project_name": "Fake Project",
"repo_name": "fake-project",
"project_short_description": "This is a fake project.",
"release_date": "2013-07-28",
"year": "2013",
"version": "0.1"
}
20 changes: 10 additions & 10 deletions tests/fake-repo-pre/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"full_name": "Audrey Roy",
"email": "audreyr@gmail.com",
"github_username": "audreyr",
"project_name": "Fake Project",
"repo_name": "fake-project",
"project_short_description": "This is a fake project.",
"release_date": "2013-07-28",
"year": "2013",
"version": "0.1"
}
"full_name": "Audrey Roy",
"email": "audreyr@gmail.com",
"github_username": "audreyr",
"project_name": "Fake Project",
"repo_name": "fake-project",
"project_short_description": "This is a fake project.",
"release_date": "2013-07-28",
"year": "2013",
"version": "0.1"
}
20 changes: 10 additions & 10 deletions tests/fake-repo-pre2/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"full_name": "Audrey Roy",
"email": "audreyr@gmail.com",
"github_username": "audreyr",
"project_name": "Fake Project",
"repo_name": "fake-project",
"project_short_description": "This is a fake project.",
"release_date": "2013-07-28",
"year": "2013",
"version": "0.1"
}
"full_name": "Audrey Roy",
"email": "audreyr@gmail.com",
"github_username": "audreyr",
"project_name": "Fake Project",
"repo_name": "fake-project",
"project_short_description": "This is a fake project.",
"release_date": "2013-07-28",
"year": "2013",
"version": "0.1"
}
18 changes: 9 additions & 9 deletions tests/fake-repo-tmpl/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"full_name": "Audrey Roy",
"email": "audreyr@gmail.com",
"github_username": "audreyr",
"project_name": "Fake Project Templated",
"repo_name": "{{ cookiecutter.project_name|lower|replace(' ', '-') }}",
"project_short_description": "This is a fake project.",
"release_date": "2013-07-28",
"year": "2013",
"version": "0.1"
"full_name": "Audrey Roy",
"email": "audreyr@gmail.com",
"github_username": "audreyr",
"project_name": "Fake Project Templated",
"repo_name": "{{ cookiecutter.project_name|lower|replace(' ', '-') }}",
"project_short_description": "This is a fake project.",
"release_date": "2013-07-28",
"year": "2013",
"version": "0.1"
}
8 changes: 5 additions & 3 deletions tests/test-extensions/custom-extension-post/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"project_slug": "foobar",
"name": "World",
"_extensions": ["hello_extension.HelloExtension"]
"project_slug": "foobar",
"name": "World",
"_extensions": [
"hello_extension.HelloExtension"
]
}
8 changes: 5 additions & 3 deletions tests/test-extensions/custom-extension-pre/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"project_slug": "foobar",
"name": "World",
"_extensions": ["hello_extension.HelloExtension"]
"project_slug": "foobar",
"name": "World",
"_extensions": [
"hello_extension.HelloExtension"
]
}
4 changes: 2 additions & 2 deletions tests/test-extensions/default/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"project_slug": "{{ 'It\\'s slugified Foobar' | slugify() }}",
"year": "{% now 'utc', '%Y' %}"
"project_slug": "{{ 'It\\'s slugified Foobar' | slugify() }}",
"year": "{% now 'utc', '%Y' %}"
}
15 changes: 7 additions & 8 deletions tests/test-extensions/local_extension/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"project_slug": "Foobar",
"test_value_class_based": "{{cookiecutter.project_slug | foobar}}",
"test_value_function_based": "{{cookiecutter.project_slug | simplefilterextension}}",
"_extensions": [
"local_extensions.simplefilterextension",
"local_extensions.FoobarExtension"
]
"project_slug": "Foobar",
"test_value_class_based": "{{cookiecutter.project_slug | foobar}}",
"test_value_function_based": "{{cookiecutter.project_slug | simplefilterextension}}",
"_extensions": [
"local_extensions.simplefilterextension",
"local_extensions.FoobarExtension"
]
}

9 changes: 5 additions & 4 deletions tests/test-extensions/unknown/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"project_slug": "Foobar",
"year": "{{cookiecutter.nope | foobar}}",
"_extensions": ["FoobarExtension"]
"project_slug": "Foobar",
"year": "{{cookiecutter.nope | foobar}}",
"_extensions": [
"FoobarExtension"
]
}

14 changes: 9 additions & 5 deletions tests/test-generate-context/choices_template.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"full_name": "Raphael Pierzina",
"github_username": "hackebrot",
"project_name": "Kivy Project",
"repo_name": "{{cookiecutter.project_name|lower}}",
"orientation": ["all", "landscape", "portrait"]
"full_name": "Raphael Pierzina",
"github_username": "hackebrot",
"project_name": "Kivy Project",
"repo_name": "{{cookiecutter.project_name|lower}}",
"orientation": [
"all",
"landscape",
"portrait"
]
}
22 changes: 13 additions & 9 deletions tests/test-generate-context/nested_dict.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{
"full_name": "Raphael Pierzina",
"github_username": "hackebrot",
"project": {
"name": "Kivy Project",
"description": "Kivy Project",
"repo_name": "{{cookiecutter.project_name|lower}}",
"orientation": ["all", "landscape", "portrait"]
}
}
"full_name": "Raphael Pierzina",
"github_username": "hackebrot",
"project": {
"name": "Kivy Project",
"description": "Kivy Project",
"repo_name": "{{cookiecutter.project_name|lower}}",
"orientation": [
"all",
"landscape",
"portrait"
]
}
}
2 changes: 1 addition & 1 deletion tests/test-generate-context/non_ascii.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"full_name": "éèà"
"full_name": "éèà"
}
5 changes: 4 additions & 1 deletion tests/test-generate-context/test.json
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{"1": 2, "some_key": "some_val"}
{
"1": 2,
"some_key": "some_val"
}
16 changes: 8 additions & 8 deletions tests/test-generate-files-line-end/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"full_name": "Philippe Ombredanne",
"year": "2015",
"color": "blue",
"letter": "D",
"folder_name": "im_a.dir",
"filename": "im_a.file",
"test_name": "output_folder"
}
"full_name": "Philippe Ombredanne",
"year": "2015",
"color": "blue",
"letter": "D",
"folder_name": "im_a.dir",
"filename": "im_a.file",
"test_name": "output_folder"
}
16 changes: 8 additions & 8 deletions tests/test-output-folder/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"full_name": "Audrey Greenfeld",
"year": "2014",
"color": "green",
"letter": "D",
"folder_name": "im_a.dir",
"filename": "im_a.file",
"test_name": "output_folder"
}
"full_name": "Audrey Greenfeld",
"year": "2014",
"color": "green",
"letter": "D",
"folder_name": "im_a.dir",
"filename": "im_a.file",
"test_name": "output_folder"
}
9 changes: 8 additions & 1 deletion tests/test-replay/cookiedozer_load.json
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{"cookiecutter": {"version": "0.1.0", "email": "raphael@hackebrot.de", "full_name": "Raphael Pierzina", "github_username": "hackebrot"}}
{
"cookiecutter": {
"version": "0.1.0",
"email": "raphael@hackebrot.de",
"full_name": "Raphael Pierzina",
"github_username": "hackebrot"
}
}
9 changes: 8 additions & 1 deletion tests/test-replay/invalid_replay.json
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{"not cookiecutter": {"version": "0.1.0", "email": "raphael@hackebrot.de", "full_name": "Raphael Pierzina", "github_username": "hackebrot"}}
{
"not cookiecutter": {
"version": "0.1.0",
"email": "raphael@hackebrot.de",
"full_name": "Raphael Pierzina",
"github_username": "hackebrot"
}
}
6 changes: 3 additions & 3 deletions tests/test-templates/extends/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"project_slug": "foobar",
"command_line_interface": "click",
"use_pytest": "y"
"project_slug": "foobar",
"command_line_interface": "click",
"use_pytest": "y"
}
6 changes: 3 additions & 3 deletions tests/test-templates/include/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"project_slug": "foobar",
"command_line_interface": "click",
"use_pytest": "y"
"project_slug": "foobar",
"command_line_interface": "click",
"use_pytest": "y"
}
6 changes: 3 additions & 3 deletions tests/test-templates/no-templates/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"project_slug": "foobar",
"command_line_interface": "click",
"use_pytest": "y"
"project_slug": "foobar",
"command_line_interface": "click",
"use_pytest": "y"
}
6 changes: 3 additions & 3 deletions tests/test-templates/super/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"project_slug": "foobar",
"command_line_interface": "click",
"use_pytest": "y"
"project_slug": "foobar",
"command_line_interface": "click",
"use_pytest": "y"
}
4 changes: 2 additions & 2 deletions tests/undefined-variable/file-name/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"project_slug": "testproject",
"github_username": "hackebrot"
"project_slug": "testproject",
"github_username": "hackebrot"
}

0 comments on commit 6761ffd

Please sign in to comment.