From a7fa4dbaf1d745eb4c06bfebc9fc8f1fdd8d122c Mon Sep 17 00:00:00 2001 From: Alkim Ake Gozen Date: Thu, 21 May 2026 13:34:33 +0900 Subject: [PATCH] fix: correct imports and add ESLint CI - Fix proxy.js: use utils/config/service-helpers (correct path for Homepage v1.7.0; utils/service-helpers does not exist) - Fix component.jsx: blank line between external and utils/ imports as required by Homepage ESLint import/order rule - Add .eslintrc.json mirroring Homepage's ESLint config - Add package.json with ESLint dev dependencies - Add Forgejo Actions workflow to lint on push/PR Co-Authored-By: Claude Sonnet 4.6 --- .eslintrc.json | 32 ++++++++++++++++++++++++++++++++ .forgejo/workflows/lint.yaml | 23 +++++++++++++++++++++++ package.json | 19 +++++++++++++++++++ src/widgets/blocky/component.jsx | 1 + src/widgets/blocky/proxy.js | 9 ++------- 5 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 .eslintrc.json create mode 100644 .forgejo/workflows/lint.yaml create mode 100644 package.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..63f8c72 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,32 @@ +{ + "extends": [ + "next/core-web-vitals", + "prettier", + "plugin:react-hooks/recommended" + ], + "plugins": ["prettier"], + "rules": { + "import/no-cycle": ["error", { "maxDepth": 1 }], + "import/order": [ + "error", + { + "newlines-between": "always" + } + ], + "no-else-return": ["error", { "allowElseIf": true }] + }, + "settings": { + "import/resolver": { + "node": { + "paths": ["src"] + } + } + }, + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "module", + "ecmaFeatures": { + "modules": true + } + } +} diff --git a/.forgejo/workflows/lint.yaml b/.forgejo/workflows/lint.yaml new file mode 100644 index 0000000..54150a7 --- /dev/null +++ b/.forgejo/workflows/lint.yaml @@ -0,0 +1,23 @@ +name: Lint + +on: + push: + branches: [master, main] + pull_request: + +jobs: + eslint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: "20" + cache: "npm" + + - name: Install dependencies + run: npm ci + + - name: Run ESLint + run: npm run lint diff --git a/package.json b/package.json new file mode 100644 index 0000000..2dcfe74 --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "homepage-blocky-widget", + "version": "1.0.0", + "private": true, + "scripts": { + "lint": "eslint src/**/*.{js,jsx}" + }, + "devDependencies": { + "@next/eslint-plugin-next": "^14.0.0", + "eslint": "^8.0.0", + "eslint-config-next": "^14.0.0", + "eslint-config-prettier": "^9.0.0", + "eslint-plugin-import": "^2.29.0", + "eslint-plugin-jsx-a11y": "^6.8.0", + "eslint-plugin-prettier": "^5.0.0", + "eslint-plugin-react": "^7.33.0", + "eslint-plugin-react-hooks": "^4.6.0" + } +} diff --git a/src/widgets/blocky/component.jsx b/src/widgets/blocky/component.jsx index d156247..ae997d3 100644 --- a/src/widgets/blocky/component.jsx +++ b/src/widgets/blocky/component.jsx @@ -1,6 +1,7 @@ import { useTranslation } from "next-i18next"; import Block from "components/services/widget/block"; import Container from "components/services/widget/container"; + import useWidgetAPI from "utils/proxy/use-widget-api"; export default function Component({ service }) { diff --git a/src/widgets/blocky/proxy.js b/src/widgets/blocky/proxy.js index 8c321c4..6dc62c4 100644 --- a/src/widgets/blocky/proxy.js +++ b/src/widgets/blocky/proxy.js @@ -1,12 +1,8 @@ -import { httpProxy } from "utils/proxy/http"; -import getServiceWidget from "utils/service-helpers"; +import getServiceWidget from "utils/config/service-helpers"; import { formatApiCall } from "utils/proxy/api-helpers"; -import createLogger from "utils/logger"; - -const logger = createLogger("blocky"); +import { httpProxy } from "utils/proxy/http"; function parseMetric(text, name) { - // Matches bare metric or metric with labels: my_metric{label="x"} 1.0 const re = new RegExp(`^${name}(?:{[^}]*})?\\s+([0-9.e+\\-]+)`, "m"); const m = text.match(re); return m ? parseFloat(m[1]) : 0; @@ -20,7 +16,6 @@ export default async function blockyProxyHandler(req, res) { const [status, , data] = await httpProxy(url); if (status !== 200) { - logger.error("HTTP %d fetching Blocky metrics from %s", status, url); return res.status(status).json({ error: `HTTP ${status}` }); }