Repository navigation
chore: track the modernisation of the nullish checks (do not merge) - #1355
Draft
redfish4ktc wants to merge 30 commits into
Draft
redfish4ktc wants to merge 30 commits into
redfish4ktc wants to merge 30 commits into
Conversation
Keep the original dictated prompt and its rewrite with the 4D framework, so the review of the coming pull requests can trace how the explore phase was scoped. The rewrite settles the open points: whole repository in scope, explore output in .claude/tasks/02-explore, origin of each risky truthiness check investigated after the local branch search. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Inventory of the null checks per package and per folder, five truthiness bugs found on the way with their origin, history of the falsy-check fixes since v0.1.0, ESLint options, coverage per folder, bundle size baseline and a proposed PR split. The open pull requests were checked: none deals with the topic. The count script and the type-aware ESLint config used for the scan are kept so the measures can be re-run on each pull request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Several open pull requests touch the files this effort will change. Rebasing either side over hundreds of changed checks is wasted time, so the extractions of AbstractGraph members into mixins become mandatory prerequisites for the files they touch, and the plan decides for the other pull requests. List the folders no open pull request touches, to show the work can start without waiting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The optional chaining and nullish coalescing simplifications go in the same folder pull requests as the null checks, to keep the number of pull requests down. The characterization tests of the poorly covered folders go in separate pull requests merged first, so a folder pull request only changes code. The resizeWidth and resizeHeight question is still under review. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
scaleCell treats an unset resizeWidth or resizeHeight as false, so a parent resized with recursiveResize moves its children without resizing them. mxGraph, and draw.io today, keep a third state where unset lets the geometry scale proportionally. The redundant `if (x) ... else if (!x)` points to a conversion that lost that state rather than to a choice, so the fix restores it. The analysis comes from reading the code only: record the reproduction, the failing test, the check of the other readers, the documentation rewrite and the CHANGELOG entry as work to do before the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The five bugs found while exploring the null checks are reported nowhere. Record that each gets an issue carrying its analysis and history, with the details collapsed or attached, and saying it comes from a systematic analysis rather than a user report. Whether to file one issue per bug or a single one is left to the plan. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Turn the exploration into a sequence of small pull requests: the rule update, one issue per bug under an umbrella issue, one fix per bug with a failing test first, characterization tests for the poorly covered folders, then one pull request per folder enabling eqeqeq on what it cleaned. The files touched by the open AbstractGraph extraction pull requests and by the event names extraction are skipped until those merge, which delays three of the five bug fixes. A codemod using the TypeScript type checker is planned to classify the 1276 sites, with the type-aware scan as the safety net of each folder pull request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The milestone of the umbrella issue was left open in the plan, the effort spanning several releases. It is decided: every issue of the plan, the umbrella one included, goes to 0.26.0, and the umbrella issue moves to the next milestone at release time if the work is not finished. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…iting Two points were left open in the plan. The codemod stays in the task folder rather than becoming a permanent script: it is a one-off tool, like the scan config. Since the last commit of the branch removes that folder, a local branch keeps the last commit carrying it, so the folder PRs can still run the codemod and the scan after this branch is merged. The fixes of resizeWidth/resizeHeight, pointerEvents and anchorPointDirection keep waiting for the open PRs touching their files, despite being one to three lines each: no exception to the waiting rule, so no rebase to manage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The plan is a programme of about thirty pull requests with external blockers, so it is cut into 38 task files, one per pull request or tooling step, each with its dependencies, to be picked in order and ticked in the index. The tasks waiting for the open PRs (B2, B3, B4 and the catch-up folders) are listed with the others, marked as waiting, rather than left out, so the index stays the complete list of what remains. The B2 investigation is split from its fix because it is read-only and can run before those PRs are merged. Also rewrap a line of the plan left longer than the others by the previous edit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The rule update was planned to reach main through the PR of this branch, which carries no code change, so the rule could be merged long before any code follows it, or block the folder PRs behind a review of task notes. It now goes with the first PR applying it, a bug fix or a folder PR, which cherry-picks the commit, so the rule and the first code following it are reviewed together. The PR of this branch carries it only if it is merged first. The folder PRs no longer depend on the PR of this branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ists The issues summarise how the figures and the bugs were found, but the detailed analysis lives in the task folder of this branch. Once its PR exists, the issues get a link to it, pinned to a pushed commit since the last commit of the branch deletes the file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The umbrella issue exists, as a Task rather than the Epic the plan proposed, in milestone 0.26.0. Task 4 is ticked and the plan and task file follow the chosen type. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The five bugs found by the exploration now have their issues, sub-issues of the umbrella one, so the index maps each bug to its number and task 5 is ticked. The umbrella issue went back to the Epic type, so the plan and task 4 say so again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The StylesheetCodec fix has its PR, which also carries the rule update. For the TextShape bounding box, the exploration called it a bug, but the deviation from mxGraph turned out to be the better behaviour for hidden containers: the issue is closed as not planned and a PR makes the intent explicit instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The first two bug fix PRs left every example size unchanged, as expected for a change of one or two lines. The measurement is kept for the folder PRs, where hundreds of rewritten checks will have an impact worth following. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A size table alone says how much each example moved, not why, and an unchanged size can mean that the example does not bundle the rewritten code at all. Each folder PR now carries the table with an explanation of each difference or of its absence, based on which examples bundle the changed modules. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The type-aware scan gave a parsing error on each of the 108 test files: the project service picks the nearest tsconfig.json, and the one of packages/core excludes the tests. The tests now get a config block of their own that names packages/core/tsconfig.test.json, while the sources and the stories keep the project service. Checked against a run of the previous config: no fatal error left, the findings on the sources are identical, and the tests give 11 findings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The loose comparisons with null are too many to rewrite by hand, and the right replacement depends on the type of the operand. The codemod asks the TypeScript checker for that type and classifies each site with the coding rule: truthiness when the non-nullish part only holds objects, isNullish when it can be a string, a number, a boolean, any, unknown, a type parameter or an empty object type. Literals count by their value, so 'north' | 'south' is never falsy. Two cases needed more than the type: - `x != null` turned into `x` keeps the behaviour only where the result is just tested (condition, left operand of && or ||, branch of a tested conditional). Where its boolean value is used, the site is planned as `!!x`. - An operand the checker types as never, or as always null after narrowing, is reported instead of planned. Operands with calls are classified like the others, unlike what the plan said: the replacement evaluates them once, as the comparison did. On view/layout the dry run finds the 275 sites the grep counts. On the whole of packages/core/src it finds 1264: 1258 comparisons with null, where the grep also counts the ones in comments (1276), and 6 loose comparisons with undefined, which the grep does not count. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The folder PRs need the planned changes applied, not only printed. The write mode applies them, adds `isNullish` to the import of the internal utils or a new import at the right relative depth, and repeats the analysis until no planned site is left: a site nested in another one is applied on the next pass, since the outer replacement embeds its original text. Tried on a scratch copy of view/layout: 273 sites rewritten in 22 files in one pass, the 2 sites typed never left for a manual review, a second run changes nothing, and the core build, the type check of the tests and the 821 core tests pass. The type-aware scan showed 93 new "object is always truthy" findings. They come from `x != null` on operands the types declare non-nullable, just as always true before, so the safety net cannot be a raw count of the findings: scan-delta.py compares two scans and fails only on new findings on falsy-capable types, and the plan and the folder tasks now refer to it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The compact tree layout tests `isVertex() != null`, always true for a boolean. mxGraph and draw.io have the same test, so the codemod did not reveal a regression of the migration; the folder PR of view/layout decides how to write it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A folder covered at 62 % of its branches still has rewritten sites that no test runs, such as the parent location option of the compact tree layout. Each folder PR now crosses the coverage with the codemod sites and adds characterization tests first for the uncovered sites that are not mechanical: the isNullish and `!!x` rewrites and the hand edits. The truthiness rewrites on object types are equivalent by construction and get none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r tests The first characterization tests of view/layout passed whatever the rewritten check, since none used 0, and the codemod turned a number into a truthiness check because its declared type was wrong. The procedure now asks for the falsy value in the tests, a mutation check to prove them, and a reading of the truthiness sites on indexed accesses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The folder PR of view/layout is open. The wrong declared type of the rank heights of CompactTreeLayout, found on the way, gets a PR of its own once it is merged, rather than an issue, since the fix is small. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rites The ?? rewrite of view/layout left an isNullish import unused, which the lint of the repository does not report and the code analysis of the pull request did. The folder procedure now removes them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
The task files are useful to the reviewers of every PR of the programme, not only the first one, so the PR of this branch stays a draft that tracks the programme instead of being merged once reviewed. The removal commit and the local branch kept to run the codemod after it are no longer needed, and the rule update already reached main with the B1 fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| def load(path): | ||
| findings = collections.Counter() | ||
| sites = collections.defaultdict(set) | ||
| for file in json.load(open(path)): |
The plan said to apply prefer-optional-chain with --fix through the scan config. On the layout folder that changed nothing: the rule only offers suggestions on these sites, so they were edited by hand. Say so, so the next folder does not rely on the autofix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…les at the end Both rules list the sites the folder PRs convert, through the scan config only. Enforcing them needs type-aware linting, like strict-boolean-expressions, so the closing task measures that cost once and decides for the three. prefer-nullish-coalescing also flags the || defaults, which are never converted mechanically: whatever is decided, the ESLint config explains why the rule, or its || check, stays off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ind it A positive guard returning NonNullable, like isPresent of ts-extras, was considered. Its negation by isNullish narrows the same way on every case except a bare type parameter, and none of the six generic signatures tried for isNullish closes that gap, a limit of TypeScript. No planned site has such an operand, so isNullish stays as it is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This branch has not been deployed
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.



Important
This draft PR will never be merged. It keeps the analysis, the plan and the tooling of the nullish checks modernisation in one place, and tracks the PRs that implement it. Each change reaches
mainthrough its own PR, listed below.Part of #1342.
Why
The modernisation of the null checks inherited from mxGraph spans dozens of small PRs over several weeks. Each of them follows the same procedure and relies on the same tooling, and the decisions taken along the way (what to rewrite, what to leave, which bugs to fix separately) need to stay readable for the reviewers of every PR, not only the first one. Committing them to
mainwould bring working notes into the repository, so they live on this branch instead.What this branch holds
All under
.claude/tasks/:_initial-prompt.md: the request the work started from.02-explore/explore.md: the analysis of the nullish and falsy checks ofpackages/core, which found the bugs tracked in the sub-issues of Modernize the code inherited from mxGraph: loops, default parameters and nullish checks #1342.02-explore/plan.md: the decisions, and the procedure every folder PR follows (characterization tests first, rewrite, safety scan,eqeqeq, bundle sizes).02-explore/tasks/: the plan split into tasks, ticked as they land.02-explore/codemod/nullish-codemod.mjs: the script rewriting the comparisons. It asks the TypeScript compiler for the type of each operand to choose between truthiness andisNullish.02-explore/nullish-scan.eslint.config.mjsand02-explore/scan-delta.py: the type-aware lint scan run before and after a rewrite, and the comparison that fails when a truthiness check on a falsy-capable type appears.The branch is updated as the work progresses, so the files reflect the current state of the plan.
PRs
Bug fixes:
resizeWidth/resizeHeight), waits for open PRspointerEventsdefault), waits for open PRsanchorPointDirectiondefault), waits for open PRsFolder PRs:
view/layoutThe other folders, the characterization tests of the poorly covered ones and the stories follow the order of
02-explore/tasks/index.md. The remaining count per folder is in #1342.🤖 Generated with Claude Code (Claude Opus 5.5)