Lint TypeScript files#84
Open
ICubE01 wants to merge 3 commits into
Open
Conversation
ESLint only matched **/*.{js,jsx}, so no .ts or .tsx file in the app was
linted. Add typescript-eslint and a matching config block.
This surfaces 41 pre-existing react-hooks errors from two causes: early
returns placed above hooks in the page components, and useStomp being a
class that calls hooks. Both need a refactor rather than a lint fix, so
those rules are warnings for now with a TODO.
- Brace the case blocks in TichuPage that declare lexical bindings - Drop the unused catch bindings in LoginPage and SignupPage - Replace the `Function` type with concrete signatures - Use const for a loop binding that is never reassigned
The check workflow built the frontend but never linted it, so nothing enforced the rules. Split the frontend job into install, lint, and build steps so a lint failure is reported on its own.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.tsand.tsxfiles, which it previously skipped entirelynpm run lintpasses againFrontend
Chore
eslint.config.jsonly matched**/*.{js,jsx}, so not a single application source file was being linted. Addedtypescript-eslintand a**/*.{ts,tsx}block extending the same rule sets, plusargsIgnorePattern: '^_'so intentionally unused parameters stay valid.Bugfix
TichuPage.tsxbrace the 15caseblocks that declare lexical bindings. Without the braces, aconstin one branch is visible to every later branch in the same switch.LoginPage.tsx,SignupPage.tsxdrop the unusedcatchbindings.useStomp.tsxreplace theFunctiontype on subscription callbacks with a namedMessageCallbacksignature.TichuPage.tsx,HanabiPage.tsxtypeonGameEndas() => voidrather thanFunction.Trick.tsuseconstfor a loop binding that is never reassigned.General
Chore
reusable-check.yamlrunnpm run lintin the check workflow. It built the frontend but never linted it, so nothing enforced the rules. The frontend job is now install, lint, then build, so a lint failure is reported on its own rather than as a build failure.Follow-up
41 react-hooks violations remain, downgraded to warnings so
npm run lintis usable as a signal for everything else. They come from two causes:TichuPage,HanabiPage, andRoomDetailPageplace an earlyreturnabove their hooks. If the guarded value flips between renders, React throws "Rendered fewer hooks than expected". Fixing means moving the returns below the hooks and handling the null case in each hook body.useStompis a class that callsuseRef/useMemo. It works only because it is constructed during render and the hook order happens to stay stable. Converting it to a real custom hook is the fix.The remaining 7 are
react-hooks/refs,set-state-in-effect,immutability, and onereact-refreshwarning. There are also 16 pre-existingexhaustive-depswarnings, which were already warnings.Since CI now runs the linter, warnings pass but errors do not. Once the two refactors above land and those rules go back to
error, the gate tightens automatically. Adding--max-warningsis a further option, but it would fail on the 57 warnings that exist today.