Repository navigation
chore: add ESLint rules - #123
MatiasArriola wants to merge 14 commits into
Conversation
BundleMonNo change in files bundle size Unchanged groups (1)
Final result: ✅ View report in BundleMon website ➡️ |
There was a problem hiding this comment.
Tested on CPR development (8fc505a). New rules only. Counts: yarn lint:all hits / files.
KEEP
layer-dependencies(259/221): all real violations.http-client-access(37/30): real hits. Rule fix: do not flagBlobused as a type.no-collection-mutation(21/9): low noise. Config fix: exclude tests (fixture builders).no-unsafe-type-assertion(183/81): most valuable for LLM code.no-unsafe-*(101/27): realanyleaks.no-floating-promises(30/28): real hits.toPromise()ban (8/7): 1 real hit; rest are composition roots, scripts and migrations.Promiseban (50/8): real hits in domain; data hits are 5 adapter files, disable per file.no-explicit-any(43/16): 25 inextends. Config fix: allow viano-restricted-syntax.makeStylesban (30/30): fine, CPR already uses styled-components (46 files).no-param-reassignprops (12/6): fine; only DOM code needs exceptions.no-var,no-eval,no-new-func,rules-of-hooks, testing-library rules: 0 hits.- Ignoring existing errors (
eslint-suppressions.json): makes adoption possible.
REMOVE (proposal)
as Type[]ban (35/25): redundant withno-unsafe-type-assertion.as unknownban (25/12): redundant withno-unsafe-type-assertion.array-callback-return(25/20): flags legit uses like voidFuture.map; 24 false hits.
Notes
- Lint time: 6.1s → 17.7s (2.9×). Type info +2.6s; new rules +9s, mostly
no-unsafe-*. - Node 22.18+ already runs the
.tsconfig natively; Node 24 is not required. allowImportingTsExtensionsneeds TS 5; on TS 4.9 lint works buteslint/is not typechecked.
Allow platform types, test fixture mutation, and generic any constraints. Remove noisy cast and callback checks, update adoption docs, and migrate suppressions. Add regression coverage and improve test readability. Validated with yarn check and focused tests.
|
Thanks @tokland!! Agreed on your proposals and the findings are very valuable. Included in latest commit:
The other proposed “keep” rules remain enabled. Promise/ I did some more testing in metadata-synchronization and tried some performance improvements like caching module resolution, but it did not introduce valuable gains. Using Based on lint errors in metadata-sync, we have also some issues that could be considered "false positives" but maybe we can consider that belongs to a project-specific customization based on this template |
|
Thanks Matias, the fixes all look good - verified One blocker: Regarding the draft: whenever the internal discussion lands, happy to review the final state and approve. |
📌 References
📝 Implementation
eslint-suppressions.json.yarn lint:allexcludes suppressions allowing to fix existing issues. Not perfect since it only compare error counts per file.What follows is an AI-generated detail of the changes included:
Purpose
Automate the mechanically checkable parts of EyeSeeTea's coding conventions while
allowing existing projects to adopt them without first rewriting legacy code.
The skeleton now fails lint when errors exceed accepted legacy counts, keeps the
full backlog available for inspection, and provides a reusable warning-first policy
for downstream projects.
This is especially useful for LLM-generated code: agents can miss or inconsistently
apply written conventions, while static checks provide repeatable, blocking feedback
regardless of who wrote the code. For mechanically checkable rules, this is stronger
enforcement than agent instructions alone and lets agents correct violations before
handing work back for review.
The tradeoff is narrower coverage and ongoing rule maintenance: static analysis
cannot reliably judge design intent, business semantics, or every legitimate
exception, and overly broad checks can produce false positives. Agent instructions
and human review still supply that context; lint enforces the subset that can be
checked reliably. The count-based legacy baseline also leaves same-count replacements
to review, as described below.
This PR changes tooling and documentation; it does not migrate application code.
Static checks provide partial convention coverage and complement code review.
Changes
eyeseetea/layer-dependencies,eyeseetea/http-client-access,and
eyeseetea/client-constructionrules with shared boundary helpers.styling, testing, and security restrictions using existing dependencies.
eyeseeteanamespace withoutchanging its behavior.
baseline commands, rule documentation, and downstream adoption guidance.
yarn test) from ESLint tooling tests (yarn test:eslint),with both required by
yarn check. Tooling tests run in Node without React setupor browser polyfills.
.mjsfiles in formatting and test discovery; allow local.tsimportsin the no-emit TypeScript configuration.
Convention mapping
Source:
ai-dev-skeleton/.est_ai/rules/, usinggeneric/,lang/typescript.md,and
dhis2-react/. Kotlin and Android conventions do not apply.Covered means the stated syntax or structural check is implemented.
Partial means related cases still require review. Review means no dedicated
check is introduced here. The table describes detection before baseline suppression.
generic/functional,lang/typescriptprefer-const,no-vareyeseetea/no-collection-mutation;no-param-reassignwithprops: trueReadonlydeclarations are not enforced.lang/typescript@typescript-eslint/no-unsafe-type-assertion, unsafe operation rules,no-explicit-any; syntax restrictions foras unknownandas Type[]; existing strict TypeScriptas constallowed. Explicitanyis restricted more broadly than the source wording.Pick/Omit—lang/typescriptgeneric/architectureeyeseetea/layer-dependencies,eyeseetea/http-client-accessrequire; Node builtins and selected platform APIs, including qualified globals. Transitive dependencies, nonliteral imports, and arbitrary aliases remain unchecked.dhis2-react/testingdhis2-react/architectureeyeseetea/http-client-accessfetchorXMLHttpRequest; arbitrary data flow and aliased access remain unchecked.D2Apiusage and construction —dhis2-react/architectureeyeseetea/http-client-access,eyeseetea/client-constructiondhis2-react/architectureno-restricted-globalsand syntax selectors.toPromise()only in tests —dhis2-react/architectureno-restricted-syntaxmember-call selectortoPromiseare reported; receiver identity and aliases are not resolved..run()insideuseEffect—dhis2-react/architectureFuture.blockcallbacks.makeStyles; use styled-components —dhis2-react/reactno-restricted-importsgeneric/testing,dhis2-react/testingtoBeTruthyandtoBeDefineddhis2-react/testinglocator,getByTestId,$,$$generic/securityno-eval,no-implied-eval,no-new-func, existing React safety checksgeneric/architecture,dhis2-react/architectureD2*domain types,MetadataPick, repository/use-case cross-calls, public APIs, and wiring.dhis2-react/reactuseAppContext()access, and one global context.generic/testing,dhis2-react/testinggeneric/processyarn checkintegrates local verificationAdditional restrictions and explicit exceptions
The policy is an implementation of selected conventions, not an exact encoding of
every source rule:
anyis flagged, beyond the source prohibition on contract-bypassingcasts and untyped parameters.
baseline profile these are errors, including legitimate conditional exceptions.
floating Promises; unused imports; callback returns; and categorical evaluation
bans add correctness or style checks beyond the literal EST rules.
data/are prohibited, including infrastructure helperslocated there. Direct HTTP restrictions also apply to presentation.
exceptions to repository-only usage. Adapters cannot construct clients outside
a permitted root/factory.
Baseline behavior
The reusable
eyeseetea-config.tsdefaults most additions to warnings. This skeletonuses
baseline-config.mjsto promote policy warnings to errors while preservingoptions and scopes, because native ESLint suppressions apply only to errors.
Other framework/base warnings remain advisory.
yarn lint/yarn lint:newsrc; fail on unsuppressed errors or stale accepted counts.yarn lint:allyarn lint:cachedyarn lint:baselineyarn lint:baseline:pruneyarn checkalready invokes the gate throughyarn lint. Normal lint and inspectiondo not rewrite the baseline; CI must never regenerate it. A missing explicitly named
baseline fails. Keep
eslint/empty-suppressions.jsonas{}. The existinglint-allalso runs
ts-pruneand is distinct fromlint:all.Guarantee: suppressions store a count per file and rule. Adding a fourth finding
to a bucket with three accepted findings fails and reports all four; the Git diff
identifies the introduced one. Fixing one and introducing another in the same bucket
can pass with an unchanged count. This is a count ratchet, not finding identity tracking
or proof that all accepted violations are legacy.
Review baseline changes, file moves, and rule upgrades explicitly. Commit pruning
alongside fixes. Required CI uses uncached lint: file caching may miss effects of
imported type/dependency changes. Editors and Node API integrations may still display
accepted findings unless they support bulk suppressions.
Adoption in another project
custom rules from a recorded commit. Keep local overrides separate. See
MIGRATION.md for dependency and integration details.
native
.tsimports, ESLint 9.24+ for suppressions, and compatible direct dependenciesfrom
package.json. Older runtimes need a loader or compiled policy. Include copiedTypeScript rules in a no-emit typecheck with
allowImportingTsExtensions.project, aliases, source/test/E2E scopes, and generated-file ignores. Share architecture
pathsacross enabled rules and setclientFactoriesfor client construction.Supplied path arrays replace defaults. Update old Future capture suppressions to
the
eyeseeteanamespace.copy
baseline-config.mjs,empty-suppressions.json, and the baseline scripts.For the latter, compose the baseline profile after framework config and before
deliberate local overrides.
correctness defects, and identify accepted legacy findings. Generate a project-specific
eslint-suppressions.json; never copy this skeleton's counts.lint:baselineacceptsall current rule errors, including correctness errors; use native
--suppress-rule <rule-id>for selective acceptance.formatting, lint, application tests, and
test:eslintusing the dedicated Nodeconfiguration. Require both suites in CI. Inspect effective config for production, tests, E2E,
and adapters. Commit the reviewed baseline and require uncached
lint:neworcheckin CI. Prune as legacy findings are fixed.Performance
A downstream benchmark in
metadata-synchronizationcompared its previous ESLintconfiguration with the migrated configuration:
The migrated run took 2.18× as long (+17.40 s, +118%) and used more peak memory.
This is a material adoption cost, especially for larger projects and constrained CI
runners. The migrated run reported 93 warnings and no errors; the previous run
reported no diagnostics. All invocations completed successfully.
Method: Node 22.22.0, one unmeasured warm-up and three alternating measured runs per
worktree, with a fresh Node process each time. ESLint's cache was disabled and the
filesystem cache was warm; installation and Yarn wrapper overhead were excluded.
The comparison used downstream
origin/masterat13e300ce8614(ESLint 8.57.1)and branch
chore/test-new-lint-rulesatf3c41cf4691dplus uncommitted migrationchanges (ESLint 9.39.5).
These are actual downstream worktree results, not an isolated measurement of this
PR: ESLint versions differ, and seven source files also changed (84 insertions,
65 deletions). The benchmark does not separate type-aware/custom-rule costs from
the migration or native suppression bookkeeping, and does not measure cold filesystem
or cached local runs. Its Node version also differs from this PR's recommended
Node 24 runtime.
Use
lint:cachedfor local feedback; required CI remains uncached for correctness.For larger consumers, profile rule execution and repeat the comparison on identical
source and the intended runtime before setting performance expectations.
Validation
Validation after separating application and tooling suites:
yarn typecheckyarn prettify:checkyarn lint:newyarn test:unit— 137 application tests across 13 files passed (jsdom)yarn test:eslint— 83 tooling tests across 8 files passed (Node)yarn check— full verification, including both suites, passedgit diff --check