fix: correct imports and add ESLint CI
Some checks failed
Lint / eslint (push) Failing after 1m32s

- 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 <noreply@anthropic.com>
This commit is contained in:
Alkim Ake Gozen 2026-05-21 13:34:33 +09:00
parent cc34c22aa5
commit a7fa4dbaf1
5 changed files with 77 additions and 7 deletions

32
.eslintrc.json Normal file
View file

@ -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
}
}
}

View file

@ -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

19
package.json Normal file
View file

@ -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"
}
}

View file

@ -1,6 +1,7 @@
import { useTranslation } from "next-i18next"; import { useTranslation } from "next-i18next";
import Block from "components/services/widget/block"; import Block from "components/services/widget/block";
import Container from "components/services/widget/container"; import Container from "components/services/widget/container";
import useWidgetAPI from "utils/proxy/use-widget-api"; import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Component({ service }) { export default function Component({ service }) {

View file

@ -1,12 +1,8 @@
import { httpProxy } from "utils/proxy/http"; import getServiceWidget from "utils/config/service-helpers";
import getServiceWidget from "utils/service-helpers";
import { formatApiCall } from "utils/proxy/api-helpers"; import { formatApiCall } from "utils/proxy/api-helpers";
import createLogger from "utils/logger"; import { httpProxy } from "utils/proxy/http";
const logger = createLogger("blocky");
function parseMetric(text, name) { 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 re = new RegExp(`^${name}(?:{[^}]*})?\\s+([0-9.e+\\-]+)`, "m");
const m = text.match(re); const m = text.match(re);
return m ? parseFloat(m[1]) : 0; return m ? parseFloat(m[1]) : 0;
@ -20,7 +16,6 @@ export default async function blockyProxyHandler(req, res) {
const [status, , data] = await httpProxy(url); const [status, , data] = await httpProxy(url);
if (status !== 200) { if (status !== 200) {
logger.error("HTTP %d fetching Blocky metrics from %s", status, url);
return res.status(status).json({ error: `HTTP ${status}` }); return res.status(status).json({ error: `HTTP ${status}` });
} }