Skip to content

chore: make eslint run again and format the codebase - #215

Closed
edospadoni wants to merge 2 commits into
mainfrom
chore/eslint-config
Closed

edospadoni wants to merge 2 commits into
mainfrom
chore/eslint-config

Conversation

@edospadoni

Copy link
Copy Markdown
Member

Why

npm run lint did not run at all: the config extended react-app and react-app/jest, which are neither installed nor in package.json, so eslint aborted before linting a single file.

With that unblocked it reported 4149 problems (682 errors). This PR takes it to 0 errors.

Two commits

1. chore: make eslint run again — config only, no code touched.

  • drop the react-app configs (CRA-era, unmaintained, not applicable to an Electron app)
  • install eslint-plugin-react-hooks, already listed in plugins but missing from the deps
  • 'react/display-name': false is not a valid severity → 'off'
  • drop import/no-anonymous-default-export and the import resolver setting, both referring to the uninstalled eslint-plugin-import

2. style: format the codebase — the autofixer over the whole repo, plus the rules that did not fit this project.

Rule decisions

Each of these is a case where the rule was wrong for this codebase, not the code:

Rule Decision
spaced-comment keep the / marker — see the warning below
camelcase properties: 'never': the NethVoice API and the design tokens are snake_case on the wire
quotes avoidEscape: true, for strings that embed single quotes
react/prop-types off — TypeScript prop types already cover it
react-hooks/* not applied to main, preload, shared: a use* factory there is not a React hook, so the rule only produced false positives
ban-ts-comment downgraded to a warning

⚠️ Two regressions the autofixer introduced

Both were caught by building, not by the linter. Worth knowing before running the autofixer again:

1. It destroyed the TypeScript triple-slash directives. spaced-comment rewrote

/// <reference types="vite/client" />   →   // / <reference types="vite/client" />

in both env.d.ts files, which silently removed the module declarations for .svg and .css imports. Fixed by configuring the rule with markers: ['/'].

2. It moved a @ts-ignore off its target. Prettier split a call across lines, so the directive ended up one line above the expression that actually errors. Fixed by putting it back on the right line, with a comment explaining why it has to stay there.

Hand fixes

What the autofixer could not resolve: duplicate imports, empty blocks, an empty props interface, Function as a type, and — the only non-mechanical one — a new Promise() wrapper around an already-async function whose executor was async, which swallowed rejections. The rewrite is behaviour-equivalent.

What is left

316 warnings, untouched on purpose — mostly no-explicit-any (175) and unused vars (92). They need real code changes, not formatting, and belong in their own PR.

Note npm run lint runs with --fix, so it rewrites files in place.

How to test

npm run lint → 0 errors. npm run typecheck and npm run build pass, and electron-builder --dir still packages.

Since this touches 137 files, CI going green is necessary but not sufficient: the app is worth a manual smoke test (login, calls, PhoneIsland, settings) before merging.

eslint aborted on every run: .eslintrc.cjs extended react-app and
react-app/jest from eslint-config-react-app, which is neither installed
nor listed in package.json.

- drop the react-app configs, CRA era and unmaintained, not applicable to
  an electron app
- install eslint-plugin-react-hooks, already declared in plugins but
  missing, and extend plugin:react-hooks/recommended to keep the hook
  rules react-app used to provide
- 'react/display-name': false is not a valid severity, use 'off'
- drop import/no-anonymous-default-export and the import resolver
  setting, both referring to the uninstalled eslint-plugin-import
- set settings.react.version to detect and dedupe the repeated extends
  entries

This only makes eslint run again. It does not address the 4149 problems
it now reports on the existing codebase, and note that the lint script
runs with --fix, so it would reformat the whole repository.
Runs the autofixer over the whole repository and settles the rules that
did not fit this codebase, taking eslint from 4149 problems (682 errors)
to 0 errors.

Rule changes, all of them cases where the rule was wrong for this project
rather than the code:

- spaced-comment keeps the '/' marker, otherwise the autofix rewrites
  TypeScript triple-slash directives into // / <reference ... /> and the
  asset module declarations silently stop being picked up
- camelcase only checks declarations: the NethVoice API and the design
  tokens are snake_case on the wire
- quotes allows double quotes to avoid escaping, for strings that embed
  single quotes
- react/prop-types off, TypeScript prop types already cover it
- react-hooks rules do not apply to main, preload and shared: a use*
  factory there is not a React hook
- ban-ts-comment downgraded to a warning

Hand fixes for what the autofixer could not resolve: duplicate imports,
empty blocks, an empty props interface, Function as a type, and a
Promise wrapper around an already async function whose executor was
async, which swallowed rejections.

317 warnings are left (mostly no-explicit-any and unused vars) and are
untouched on purpose: they need real code changes, not formatting.
@edospadoni edospadoni self-assigned this Sep 16, 2026
@github-actions

Copy link
Copy Markdown

Automatic builds from https://github.com/NethServer/nethlink/actions/runs/35069768871.
Commit: 79e9b06

Name Platform Link
win-app.exe Windows (x64) Link
macos-app-x64.dmg MacOS (x64) Link
macos-app-arm64.dmg MacOS (arm64) Link
linux-app.AppImage Linux (x64) Link

edospadoni added a commit that referenced this pull request Sep 18, 2026
ESLint was entirely broken on main: .eslintrc.cjs extended 'react-app'
and 'react-app/jest' while eslint-config-react-app was never installed,
so 'npm run lint' failed before linting a single file.

Rather than repair the eslintrc setup on eslint 8, this migrates to
eslint 9 flat config, which also unblocks the two Renovate majors that
were stuck on the 'eslint >= 9' peer requirement:

- eslint ^8.56.0 -> ^9.39.5
- @electron-toolkit/eslint-config-ts ^1.0.1 -> ^3.1.0 (#206)
- @electron-toolkit/eslint-config-prettier ^2.0.0 -> ^3.0.0 (#205)
- eslint-plugin-react ^7.33.2 -> ^7.37.5 (flat config support)
- eslint-plugin-react-hooks ^5.2.0 (was referenced, never installed)

.eslintrc.cjs and .eslintignore are replaced by eslint.config.mjs.

Config decisions:

- React and react-hooks rules are scoped to src/renderer/**. The main
  process has plain functions named use* (useNethVoiceAPI, useLogin)
  that rules-of-hooks reported as hook violations in AccountController.
- camelcase is off. Every one of its 41 reports was a snake_case field
  fixed by the backend API contract (speeddial_num, shared_groups,
  dst_cnam) or a theme token (extra_large, full_w).
- react/prop-types is off, since TypeScript already checks props.
- spaced-comment carries markers: ['/'] so --fix cannot mangle
  TypeScript triple-slash directives into '// / <reference ... />',
  which silently broke the vite/client types behind every .svg import.

Beyond formatting, these lint errors needed real fixes:

- useNethVoiceAPI.ts: drop the redundant async Promise executor around
  logout; the body already resolved unconditionally in finally, so
  behaviour is unchanged and no rejection path is lost.
- logger.ts: replace the unsafe Function type with an explicit signature.
- main.ts, Modal/index.tsx: merge duplicate imports.
- AboutModule.tsx: drop the empty destructuring pattern.
- usePresenceService.ts: drop an empty finally block.
- ipcEvents.ts: document the intentionally silent catch in the drag path.
- store.ts: move a // @ts-ignore next to the expression it suppresses.
  Reformatting split the statement it used to cover onto two lines,
  which silently un-suppressed a zustand typing error.

'npm run lint' now reports 0 errors and 339 warnings. typecheck and
build are green, and the code merged from #192 and #213 is intact.

Supersedes #215.
@edospadoni

Copy link
Copy Markdown
Member Author

Superata da #220, che oltre a far ripartire eslint migra a eslint 9 flat config e include anche #205 e #206.

@edospadoni edospadoni closed this Sep 18, 2026
@edospadoni
edospadoni deleted the chore/eslint-config branch September 18, 2026 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant