From abb3a6bd81fb8c549e39aa575ce25f01e4e84e8c Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Sat, 19 Sep 2026 00:55:02 -0300 Subject: [PATCH 1/2] [CONFIG] [Github Actions]: JSON format/check in verbose mode [CONFIG] Makefile: JSON format/check in verbose mode [CONFIG] [Github Actions] lint JSON files at Docker workflow --- .github/workflows/docker-image.yml | 10 +++++++++ .github/workflows/prettier-json.yml | 34 +++++++++++++++++++++++++++++ .prettierignore | 1 + .prettierrc.yaml | 7 ++++++ Makefile | 20 ++++++++++++++--- compose.yaml | 19 +++++++++++----- 6 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/prettier-json.yml create mode 100644 .prettierignore create mode 100644 .prettierrc.yaml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 502085f..510edda 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -105,6 +105,16 @@ jobs: run: > make compose/lint/yaml + run-lint-json: + name: "Run in docker: JSON LINT" + runs-on: ubuntu-26.04 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + + - name: Run JSON lint + run: > + make compose/lint/json + run-lint: name: "Run in docker: LINT" runs-on: ubuntu-26.04 diff --git a/.github/workflows/prettier-json.yml b/.github/workflows/prettier-json.yml new file mode 100644 index 0000000..ae39f1e --- /dev/null +++ b/.github/workflows/prettier-json.yml @@ -0,0 +1,34 @@ +--- +name: Prettier JSON Lint + +on: # yamllint disable-line rule:truthy + push: + branches: ["main"] + pull_request: + # The branches below must be a subset of the branches above + branches: ["main"] + workflow_dispatch: + +jobs: + json-lint: + name: "Prettier JSON Lint" + runs-on: ["ubuntu-26.04"] + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + + - name: Set up Node.js + uses: actions/setup-node@v7 + with: + node-version: 26.x + + - name: Install Prettier + run: | + npm install -g --ignore-scripts prettier@3.9.8 + + - name: Tool check + run: | + prettier --version + + - name: Prettier LINT / Style JSON + run: > + prettier --check ./**/*.json diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..6830205 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +/*.json diff --git a/.prettierrc.yaml b/.prettierrc.yaml new file mode 100644 index 0000000..ccee703 --- /dev/null +++ b/.prettierrc.yaml @@ -0,0 +1,7 @@ +--- +singleQuote: true +quoteProps: preserve +useTabs: false +printWidth: 80 +tabWidth: 2 +trailingComma: none diff --git a/Makefile b/Makefile index fe2af3b..22dda79 100644 --- a/Makefile +++ b/Makefile @@ -84,10 +84,13 @@ lint/markdown: lint/yaml: yamllint --strict . && echo '✔ Your code looks good.' +lint/json: + prettier --check ./src/**/*.json + lint: test/styling test/static lint-no-deps: test/styling test/static-no-deps -lint/all: lint/markdown lint/yaml test/styling test/static +lint/all: lint/markdown lint/yaml lint/json test/styling test/static test/static-no-deps: cppcheck \ @@ -107,9 +110,14 @@ test/static: prebuild test/static-no-deps test/styling: clang-format --dry-run --Werror $(FILES) -format: +format/sources: clang-format -i --verbose $(FILES) +format/json: + prettier --write ./src/**/*.json + +format: format/sources format/json + test: env dependencies build clean/test cd build && make test @@ -152,7 +160,6 @@ compose/lint/markdown: markdownlint --config /workspace/.markdownlint.json '/workspace/**/*.md' \ && echo '✔ Your code looks good.' - compose/lint/yaml: ${DOCKER_COMPOSE} --profile lint run --rm \ --workdir /workspace \ @@ -160,6 +167,13 @@ compose/lint/yaml: yamllint --strict /workspace \ && echo '✔ Your code looks good.' +compose/lint/json: + ${DOCKER_COMPOSE} --profile lint run --rm \ + --workdir /workspace \ + -v "$$(pwd):/workspace" \ + prettier --check /workspace/**/*.json \ + && echo '✔ Your code looks good.' + compose/test/styling: compose/build ${DOCKER_COMPOSE} --profile lint run --rm algorithm-exercises-c-lint make test/styling diff --git a/compose.yaml b/compose.yaml index 65112c8..221ca49 100644 --- a/compose.yaml +++ b/compose.yaml @@ -10,7 +10,7 @@ services: BRUTEFORCE: ${BRUTEFORCE:-false} ## (1) ## true | false volumes: - ./coverage:/app/coverage - profiles: ["testing"] + profiles: ['testing'] algorithm-exercises-cpp-lint: image: algorithm-exercises-cpp:lint @@ -21,21 +21,28 @@ services: - ./.clang-format:/app/.clang-format - ./Makefile:/app/Makefile - ./src:/app/src - profiles: ["lint"] + profiles: ['lint'] markdownlint: image: goncl/markdownlint-cli:latest working_dir: /workspace volumes: - ./:/workspace - profiles: ["lint"] + profiles: ['lint'] yamllint: image: goncl/yamllint:latest working_dir: /workspace volumes: - ./:/workspace - profiles: ["lint"] + profiles: ['lint'] + + prettier: + image: goncl/prettier:3.9.8 + working_dir: /workspace + volumes: + - ./:/workspace + profiles: ['lint'] algorithm-exercises-cpp-dev: image: algorithm-exercises-cpp:dev @@ -47,7 +54,7 @@ services: BRUTEFORCE: ${BRUTEFORCE:-false} ## (1) ## true | false volumes: - ./:/app - profiles: ["development"] + profiles: ['development'] algorithm-exercises-cpp: image: algorithm-exercises-cpp:latest @@ -56,7 +63,7 @@ services: target: production # volumes: # - ./:/app - profiles: ["production"] + profiles: ['production'] ## REFERENCES: ## (1) Passing Environment variable with fallback value: From f2e9e52f41c0f17add721436fec1d54fe7f7f34b Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Sat, 19 Sep 2026 00:56:10 -0300 Subject: [PATCH 2/2] fix: JSON files formatted --- .../hackerrank/warmup/birthday_cake_candles.testcases.json | 4 ++-- .../lib/hackerrank/warmup/diagonal_difference.testcases.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tests/unit/lib/hackerrank/warmup/birthday_cake_candles.testcases.json b/src/tests/unit/lib/hackerrank/warmup/birthday_cake_candles.testcases.json index 86fa2d2..7a48902 100644 --- a/src/tests/unit/lib/hackerrank/warmup/birthday_cake_candles.testcases.json +++ b/src/tests/unit/lib/hackerrank/warmup/birthday_cake_candles.testcases.json @@ -1,4 +1,4 @@ [ - {"input": [3, 2, 1, 3], "expected": 2}, - {"input": [1, 2, 3, 3], "expected": 2} + { "input": [3, 2, 1, 3], "expected": 2 }, + { "input": [1, 2, 3, 3], "expected": 2 } ] diff --git a/src/tests/unit/lib/hackerrank/warmup/diagonal_difference.testcases.json b/src/tests/unit/lib/hackerrank/warmup/diagonal_difference.testcases.json index ea2b143..d654ca2 100644 --- a/src/tests/unit/lib/hackerrank/warmup/diagonal_difference.testcases.json +++ b/src/tests/unit/lib/hackerrank/warmup/diagonal_difference.testcases.json @@ -1,6 +1,6 @@ [ - { "matrix": - [ + { + "matrix": [ [11, 2, 4], [4, 5, 6], [10, 8, -12]