Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: simplify formatting with deno, part 2: JSON #3118

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 1 addition & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ Leave the headings unless they don't apply to your PR, and remove the comment bl
NOTE: Please grant permission for repository maintainers to edit your PR. It is EXTREMELY common for PRs to be held up due to trivial changes being requested and the author being unavailable to make them.

CODE STYLE: please follow below guide.
JSON: https://github.com/cataclysmbnteam/Cataclysm-BN/blob/upload/doc/JSON_STYLE.md
C++ and Markdown: https://github.com/cataclysmbnteam/Cataclysm-BN/blob/upload/doc/CODE_STYLE.md
https://github.com/cataclysmbnteam/Cataclysm-BN/blob/upload/doc/CODE_STYLE.md

!!!!!!!!!! WARNING !!!!!!!!!!

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ on:
- "msvc-object_creator/**"
- "object_creator/**"
- "tools/**"
- "!tools/format/**"
- "utilities/**"

# We only care about the latest revision of a PR, so cancel previous instances.
Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,17 @@ jobs:
steps:
- uses: actions/checkout@v3

- run: sudo apt-get install astyle

- uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: format C++ files
run: make astyle

- name: format markdown files
- name: format markdown and JSON files
run: deno fmt

- name: json formatting
run: make style-all-json-parallel RELEASE=1
- run: sudo apt-get install astyle

- name: format C++ files
run: make astyle

- uses: autofix-ci/action@8caa572fd27b0019a65e4c695447089c8d3138b9
if: ${{ always() }}
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/json.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 1

- uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: JSON style check
run: make style-all-json-parallel COMPILER=g++-11 RELEASE=1
run: deno fmt --check

- name: Display Corrections
if: failure()
run: git diff
2 changes: 0 additions & 2 deletions .github/workflows/msvc-full-features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ on:
- 'msvc-object_creator/**'
- 'object_creator/**'
- 'tools/**'
- '!tools/format/**'
- 'utilities/**'
pull_request:
branches:
Expand All @@ -31,7 +30,6 @@ on:
- 'msvc-object_creator/**'
- 'object_creator/**'
- 'tools/**'
- '!tools/format/**'
- 'utilities/**'

# We only care about the latest revision of a PR, so cancel previous instances.
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/msys2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ on:
- 'gfx/**'
- 'lang/**'
- 'tools/**'
- '!tools/format/**'
- 'utilities/**'
pull_request:
branches:
Expand All @@ -25,7 +24,6 @@ on:
- 'gfx/**'
- 'lang/**'
- 'tools/**'
- '!tools/format/**'
- 'utilities/**'

# We only care about the latest revision of a PR, so cancel previous instances.
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
/src/version.h
/sound/
/templates/
/tools/format/json_formatter.cgi
CataclysmWin.cscope_file_list
CataclysmWin.depend
CataclysmWin.layout
Expand Down
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ set(LANGUAGES "" CACHE STRING "Compile localization files for specified language
option(DYNAMIC_LINKING "Use dynamic linking. Or use static to remove MinGW dependency instead." "ON")
option(USE_UNITY_BUILD "Use unity build." "OFF")
option(USE_PCH_HEADER "Use precompiled PCH header." "OFF")
option(JSON_FORMAT "Build JSON formatter" "OFF")
option(CATA_CCACHE "Try to find and build with ccache" "ON")
option(CATA_CLANG_TIDY_PLUGIN "Build Cata's custom clang-tidy plugin" "OFF")
set(CATA_CLANG_TIDY_INCLUDE_DIR "" CACHE STRING "Path to internal clang-tidy headers required for plugin (e.g. ClangTidy.h)")
Expand Down Expand Up @@ -362,9 +361,6 @@ if (NOT MSVC)
add_subdirectory(src/chkjson)
endif()
add_subdirectory(tests)
if (JSON_FORMAT)
add_subdirectory(tools/format)
endif()
if (CATA_CLANG_TIDY_PLUGIN)
add_subdirectory(tools/clang-tidy-plugin)
endif()
Expand Down
2 changes: 0 additions & 2 deletions LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ CATCH unit-test framework (tests/catch/catch.hpp) is licensed under the Boost So

PLF List and PLF Colony (src/list.h, src/colony.h) are licensed under the zLib license (https://www.zlib.net/zlib_license.html).

getpost (tools/json_tools/format/getpost.h) is licensed under the MIT license, see file for text of license.

Lua (src/lua/*) is licensed under the MIT license, see src_lua/LICENSE.md for text of license.

sol2 (src/sol/*) is licensed under the MIT license, see src/sol/sol.hpp for text of license.
Expand Down
56 changes: 2 additions & 54 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,8 @@
# make astyle
# Check if source files are styled properly.
# make astyle-check
# Style the whitelisted json files (maintain the current level of styling).
# make style-json
# Style all json files using the current rules (don't PR this, it's too many changes at once).
# make style-all-json
# Style all json files in parallel using all available CPU cores (don't make -jX on this, just make)
# make style-all-json-parallel
# Disable astyle of source files.
# make ASTYLE=0
# Disable format check of whitelisted json files.
# make LINTJSON=0
# Disable building and running tests.
# make RUNTESTS=0
# Make compiling object file and linking show full command.
Expand Down Expand Up @@ -177,11 +169,6 @@ ifndef ASTYLE
ASTYLE = 1
endif

# Enable json format check by default
ifndef LINTJSON
LINTJSON = 1
endif

# Enable running tests by default
ifndef RUNTESTS
RUNTESTS = 1
Expand Down Expand Up @@ -232,15 +219,6 @@ else
CLANG = 0
endif

# Determine JSON formatter binary name
JSON_FORMATTER_BIN=tools/format/json_formatter.cgi
ifeq ($(MSYS2), 1)
JSON_FORMATTER_BIN=tools/format/json_formatter.exe
endif
ifneq (,$(findstring mingw32,$(CROSS)))
JSON_FORMATTER_BIN=tools/format/json_formatter.exe
endif

# Enable backtrace by default
ifndef BACKTRACE
# ...except not on native Windows builds, because the relevant headers are
Expand Down Expand Up @@ -406,13 +384,10 @@ ifeq ($(RELEASE), 1)
endif
endif
DEFINES += -DRELEASE
# Check for astyle or JSON regressions on release builds.
# Check for astyle regressions on release builds.
ifeq ($(ASTYLE), 1)
CHECKS += astyle-check
endif
ifeq ($(LINTJSON), 1)
CHECKS += style-json
endif
endif

ifndef RELEASE
Expand Down Expand Up @@ -474,7 +449,7 @@ endif
CXXFLAGS += $(WARNINGS) $(DEBUG) $(DEBUGSYMS) $(PROFILE) $(OTHERS) -MMD -MP
TOOL_CXXFLAGS = -DCATA_IN_TOOL

BINDIST_EXTRAS += README.md data doc LICENSE.txt LICENSE-OFL-Terminus-Font.txt $(JSON_FORMATTER_BIN)
BINDIST_EXTRAS += README.md data doc LICENSE.txt LICENSE-OFL-Terminus-Font.txt
BINDIST = $(BUILD_PREFIX)cataclysmbn-$(VERSION).tar.gz
W32BINDIST = $(BUILD_PREFIX)cataclysmbn-$(VERSION).zip
BINDIST_CMD = tar --transform=s@^$(BINDIST_DIR)@cataclysmbn-$(VERSION)@ -czvf $(BINDIST) $(BINDIST_DIR)
Expand Down Expand Up @@ -801,7 +776,6 @@ SOURCES := $(wildcard $(SRC_DIR)/*.cpp)
HEADERS := $(wildcard $(SRC_DIR)/*.h)
TESTSRC := $(wildcard tests/*.cpp)
TESTHDR := $(wildcard tests/*.h)
JSON_FORMATTER_SOURCES := tools/format/format.cpp src/json.cpp
CHKJSON_SOURCES := src/chkjson/chkjson.cpp src/json.cpp
LUA_SOURCES := $(wildcard $(LUA_SRC_DIR)/*.c)
CLANG_TIDY_PLUGIN_SOURCES := \
Expand All @@ -813,7 +787,6 @@ ASTYLE_SOURCES := $(sort \
$(HEADERS) \
$(TESTSRC) \
$(TESTHDR) \
$(JSON_FORMATTER_SOURCES) \
$(CHKJSON_SOURCES) \
$(CLANG_TIDY_PLUGIN_SOURCES) \
$(TOOLHDR))
Expand Down Expand Up @@ -1177,31 +1150,6 @@ else
@echo Cannot run an astyle check, your system either does not have astyle, or it is too old.
endif

style-json: json_blacklist $(JSON_FORMATTER_BIN)
ifndef CROSS
find data -name "*.json" -print0 | grep -v -z -F -f json_blacklist | \
xargs -0 -L 1 $(JSON_FORMATTER_BIN)
else
@echo Cannot run json formatter in cross compiles.
endif

ifeq ($(NATIVE), osx)
NUM_STYLE_JOBS = $$(sysctl -n hw.logicalcpu)
else
NUM_STYLE_JOBS = $$(nproc)
endif

# /data/names work really terribly with the formatter, so we skip them
style-all-json: $(JSON_FORMATTER_BIN)
find data -name "*.json" -print0 | grep -z -v '^data/names/' | xargs -0 -L 1 $(JSON_FORMATTER_BIN)

style-all-json-parallel: $(JSON_FORMATTER_BIN)
find data -name "*.json" -print0 | grep -z -v '^data/names/' | xargs -0 -L 1 -P $(NUM_STYLE_JOBS) $(JSON_FORMATTER_BIN)

$(JSON_FORMATTER_BIN): $(JSON_FORMATTER_SOURCES)
$(CXX) $(CXXFLAGS) $(TOOL_CXXFLAGS) -Itools/format -Isrc \
$(JSON_FORMATTER_SOURCES) -o $(JSON_FORMATTER_BIN)

tests: version $(BUILD_PREFIX)cataclysm.a
$(MAKE) -C tests

Expand Down
1 change: 0 additions & 1 deletion build-scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ then
elif [ -n "$TEST_STAGE" ]
then
build-scripts/lint-json.sh
make style-all-json-parallel RELEASE=1

tools/dialogue_validator.py data/json/npcs/* data/json/npcs/*/* data/json/npcs/*/*/*
# Also build chkjson (even though we're not using it), to catch any
Expand Down
1 change: 0 additions & 1 deletion build-scripts/windist.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ if (Test-path bindist) {

mkdir bindist
cp cataclysm-tiles.exe bindist/cataclysm-tiles.exe
cp tools/format/json_formatter.exe bindist/json_formatter.exe

mkdir bindist/lang
cp -r lang/mo bindist/lang
Expand Down
2 changes: 1 addition & 1 deletion changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
"tag_resolver": {
"method": "sort"
}
}
}
Loading
Loading