Repository navigation
[NoQA] Add lint rule against opaque use of namespace imports - #107131
Conversation
|
@codex Review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Review finding[P2] Account for source order when checking alias reads — eslint-plugin-local-rules/no-opaque-namespace-usage.js:168–170 The rule counts member accesses anywhere in the file, but Knip registers aliases in source order. This valid pattern therefore passes lint while still hiding unused exports: import * as NS from './utils';
function run() { Alias.used(); }
const Alias = NS;
NS.used();
run();Confirmed with Knip 6.34.0: when Match Knip’s source-order behavior and add regression coverage for both declaration orders. Validation: Changed-file lint passed; 2,545 focused Jest tests and 19 Bun tests passed. No browser testing performed. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2780b16d19
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
Review finding[P2] Include named-import aliases in source-order tracking — eslint-plugin-local-rules/no-opaque-namespace-usage.js:179–185
import * as Utils from './utils';
import {obj} from './other';
function first() {
const Alias = obj;
return Alias.member;
}
function second() {
const Alias = Utils;
consume(Alias);
}
Utils.other();
first();
second();Confirmed with Knip 6.34.0 and the actual lint pipeline: lint reports The previous source-order finding is fixed. Validation passed: 2,506 focused Jest tests and changed-file lint. No browser testing performed. |
|
@MelvinBot Review |
Review finding[P2] Exclude external-package aliases from declaration tracking — eslint-plugin-local-rules/no-opaque-namespace-usage.js:230–233 The new bookkeeping includes package imports, but Knip 6.34 registers aliases only for internally resolved imports. Consequently, this pattern incorrectly passes the rule: import * as Utils from './utils';
import React from 'react';
function first() {
const Alias = React;
return Alias.createElement;
}
function second() {
const Alias = Utils;
consume(Alias);
}
Utils.other();
first();
second();The rule counts the earlier React alias access; Knip does not register that alias, so the later namespace alias remains opaque and hides unused exports. Restrict auxiliary alias declarations to internal imports and add regression coverage. The previous internal named-import case is addressed. Verification: Traced against installed Knip source. Runtime reproduction, lint, and tests were blocked by execution permissions. |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
@MelvinBot Review |
Review findings[P2] Restrict exported-spread traversal to Knip-supported property keys — eslint-plugin-local-rules/no-opaque-namespace-usage.js:169–170 The traversal accepts quoted property keys, but Knip only descends through identifier keys. For example: Utils.used();
export const copy = {'nested': {...obj}};
function run() {
const copy = Utils;
consume(copy);
}
run();With internal imports for [P2] Register destructuring-default aliases — eslint-plugin-local-rules/no-opaque-namespace-usage.js:136–154 Knip registers Validation: Both findings reproduced against Knip 6.34.0 and the current rule. The previous external-package alias finding is fixed. Focused checks passed: 857 Jest tests, 19 Bun tests, and changed-file lint. |
|
The previos finding mirrors how Knip 6.34 registers aliases, but our lint rule does not copy every internal quirk. Shapes such as quoted keys inside an exported nested spread, destructuring-default aliases, shadowed or parenthesized namespace names, and two {key: NS} declarations with the same variable and key do not occur in the repo, and the rule reports 0 violations in it. They are listed in the rule header, and the rule can be extended with a test if one ever appears. |
|
@bernhardoj Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
Sorry for the noise @bernhardoj, this issue doeb't require C+ |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safari |
|
🚧 roryabraham has triggered a test Expensify/App build. You can view the workflow run here. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/roryabraham in version: 9.5.41-0 🚀
|
|
No help site update needed — this PR adds developer linting and refactors internal imports without changing user-facing features, workflows, or labels, so no existing article becomes incorrect. |
|
🚀 Deployed to production by https://github.com/marcaaron in version: 9.5.41-2 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
Step 5 of the plan in #106552.
Problem
knip stops checking a module's exports when the module is imported as
import * as XandXis then used in a way knip cannot follow: indexed with a computed key, enumerated withObject.keysorfor...in, rest-destructured, used as a destructuring default, or assigned to a variable that is never read asalias.member. It then treats every export as used and dead ones stay hidden. Earlier steps cleared the existing cases, but nothing stops new ones from coming back.Solution
A lint rule reports exactly those forms for namespace imports of the repo's own modules. The list comes from running knip on each form: other whole-namespace uses such as spread, passing the namespace to a function, returning it or re-exporting it are tracked by knip, so they stay allowed. The five places on main that broke the rule are fixed here, so it needs no baseline entries:
WorkspaceDefaultAvatars,GroupDefaultAvatarsandMCCIconsexport one default object.ReportUtilsanduseEReceiptpicked an icon by a computed key on the namespace, and these dictionaries have no other consumer, so indexing a plain object is the smallest change.Result
A new hidden use of a namespace now fails lint, and knip sees unused exports in the three icon modules again.
Fixed Issues
$ #106552
PROPOSAL:
Tests
A computed key on a namespace is reported
src/libs/NamespaceProbe.tswithimport * as Formula from '@libs/Formula'; export default function probe(key: keyof typeof Formula) { return Formula[key]; }.npm run lint -- src/libs/NamespaceProbe.ts.rulesdir/no-opaque-namespace-usagewith "computed key".Plain member access is not reported
src/libs/NamespaceProbe.tswithimport * as Formula from '@libs/Formula'; export default function probe() { return Formula.parse; }.npm run lint -- src/libs/NamespaceProbe.ts.rulesdir/no-opaque-namespace-usage.Offline tests
N/A, tooling only
QA Steps
N/A
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari