From b915e6908cdf1143069edee1385e29a48557ddc2 Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 19 Dec 2025 07:27:21 +0100 Subject: [PATCH] Add JSON linting (#36192) Uses https://github.com/eslint/json to lint all JSON and JSONC files in the repo. --- .github/workflows/files-changed.yml | 6 ++++++ .github/workflows/pull-compliance.yml | 15 ++++++++++++++ Makefile | 8 +++++++ eslint.json.config.ts | 30 +++++++++++++++++++++++++++ package.json | 1 + pnpm-lock.yaml | 20 ++++++++++++++++++ 6 files changed, 80 insertions(+) create mode 100644 eslint.json.config.ts diff --git a/.github/workflows/files-changed.yml b/.github/workflows/files-changed.yml index d18ee6e998..cbf8758ab3 100644 --- a/.github/workflows/files-changed.yml +++ b/.github/workflows/files-changed.yml @@ -19,6 +19,8 @@ on: value: ${{ jobs.detect.outputs.swagger }} yaml: value: ${{ jobs.detect.outputs.yaml }} + json: + value: ${{ jobs.detect.outputs.json }} jobs: detect: @@ -35,6 +37,7 @@ jobs: docker: ${{ steps.changes.outputs.docker }} swagger: ${{ steps.changes.outputs.swagger }} yaml: ${{ steps.changes.outputs.yaml }} + json: ${{ steps.changes.outputs.json }} steps: - uses: actions/checkout@v6 - uses: dorny/paths-filter@v3 @@ -100,3 +103,6 @@ jobs: - "**/*.yaml" - ".yamllint.yaml" - "pyproject.toml" + + json: + - "**/*.json" diff --git a/.github/workflows/pull-compliance.yml b/.github/workflows/pull-compliance.yml index a5b6c550bb..99ff95e9c6 100644 --- a/.github/workflows/pull-compliance.yml +++ b/.github/workflows/pull-compliance.yml @@ -63,6 +63,21 @@ jobs: - run: make deps-py - run: make lint-yaml + lint-json: + if: needs.files-changed.outputs.json == 'true' + needs: files-changed + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@v6 + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v5 + with: + node-version: 24 + - run: make deps-frontend + - run: make lint-json + lint-swagger: if: needs.files-changed.outputs.swagger == 'true' needs: files-changed diff --git a/Makefile b/Makefile index 4536447e86..ccd3c25da8 100644 --- a/Makefile +++ b/Makefile @@ -413,6 +413,14 @@ lint-templates: .venv node_modules ## lint template files lint-yaml: .venv ## lint yaml files @uv run --frozen yamllint -s . +.PHONY: lint-json +lint-json: node_modules ## lint json files + $(NODE_VARS) pnpm exec eslint -c eslint.json.config.ts --color --max-warnings=0 + +.PHONY: lint-json-fix +lint-json-fix: node_modules ## lint and fix json files + $(NODE_VARS) pnpm exec eslint -c eslint.json.config.ts --color --max-warnings=0 --fix + .PHONY: watch watch: ## watch everything and continuously rebuild @bash tools/watch.sh diff --git a/eslint.json.config.ts b/eslint.json.config.ts new file mode 100644 index 0000000000..45696fb79c --- /dev/null +++ b/eslint.json.config.ts @@ -0,0 +1,30 @@ +import {defineConfig, globalIgnores} from 'eslint/config'; +import json from '@eslint/json'; + +export default defineConfig([ + globalIgnores([ + '**/.venv', + '**/node_modules', + '**/public', + ]), + { + files: ['**/*.json'], + plugins: {json}, + language: 'json/json', + extends: ['json/recommended'], + }, + { + files: [ + 'tsconfig.json', + '.devcontainer/*.json', + '.vscode/*.json', + 'contrib/ide/vscode/*.json', + ], + plugins: {json}, + language: 'json/jsonc', + languageOptions: { + allowTrailingCommas: true, + }, + extends: ['json/recommended'], + }, +]); diff --git a/package.json b/package.json index 6193687593..af4ccb54d8 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ }, "devDependencies": { "@eslint-community/eslint-plugin-eslint-comments": "4.5.0", + "@eslint/json": "0.14.0", "@playwright/test": "1.57.0", "@stylistic/eslint-plugin": "5.6.1", "@stylistic/stylelint-plugin": "4.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8835303925..117896c941 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -201,6 +201,9 @@ importers: '@eslint-community/eslint-plugin-eslint-comments': specifier: 4.5.0 version: 4.5.0(eslint@9.39.2(jiti@2.6.1)) + '@eslint/json': + specifier: 0.14.0 + version: 0.14.0 '@playwright/test': specifier: 1.57.0 version: 1.57.0 @@ -856,6 +859,10 @@ packages: resolution: {integrity: sha512-q1mjIoW1VX4IvSocvM/vbTiveKC4k9eLrajNEuSsmjymSDEbpGddtpfOoN7YGAqBK3NG+uqo8ia4PDTt8buCYA==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + '@eslint/json@0.14.0': + resolution: {integrity: sha512-rvR/EZtvUG3p9uqrSmcDJPYSH7atmWr0RnFWN6m917MAPx82+zQgPUmDu0whPFG6XTyM0vB/hR6c1Q63OaYtCQ==} + engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + '@eslint/object-schema@2.1.7': resolution: {integrity: sha512-VtAOaymWVfZcmZbp6E2mympDIHvyjXs/12LqWYjVw6qjrfF+VK+fyG33kChz3nnK+SU5/NeHOqrTEHS8sXO3OA==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -894,6 +901,10 @@ packages: resolution: {integrity: sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==} engines: {node: '>=12.22'} + '@humanwhocodes/momoa@3.3.10': + resolution: {integrity: sha512-KWiFQpSAqEIyrTXko3hFNLeQvSK8zXlJQzhhxsyVn58WFRYXST99b3Nqnu+ttOtjds2Pl2grUHGpe2NzhPynuQ==} + engines: {node: '>=18'} + '@humanwhocodes/retry@0.4.3': resolution: {integrity: sha512-bV0Tgo9K4hfPCek+aMAn81RppFKv2ySDQeMoSZuvTASywNTnVJCArCZE2FWqpvIatKu7VMRLWlR1EazvVhDyhQ==} engines: {node: '>=18.18'} @@ -4815,6 +4826,13 @@ snapshots: '@eslint/js@9.39.2': {} + '@eslint/json@0.14.0': + dependencies: + '@eslint/core': 0.17.0 + '@eslint/plugin-kit': 0.4.1 + '@humanwhocodes/momoa': 3.3.10 + natural-compare: 1.4.0 + '@eslint/object-schema@2.1.7': {} '@eslint/plugin-kit@0.4.1': @@ -4846,6 +4864,8 @@ snapshots: '@humanwhocodes/module-importer@1.0.1': {} + '@humanwhocodes/momoa@3.3.10': {} + '@humanwhocodes/retry@0.4.3': {} '@iconify/types@2.0.0': {}