feat: add no-deprecated-url-parse lint rule#55
Conversation
|
Pushed an auto-fix commit to unblock the failing Lint & Format check (Prettier formatting in |
There was a problem hiding this comment.
Reviewed as steward. Requesting changes — the rule will produce a false positive on the recommended replacement.
Issue
The objectName === 'URL' branch flags URL.parse(...), but URL.parse is the modern static method on the WHATWG URL constructor (Node 22+, browsers) and is exactly the safe alternative we want the agent to use. Flagging it pushes the agent toward the older new URL(...) pattern that throws on invalid input — strictly worse for tolerant parsing.
From the rule:
if (
objectName === 'url' ||
objectName === 'URL' || // <-- this is the static method, not deprecated
urlImportedNames.has(objectName ?? '')
) {
results.push({ ...flag... });
}This will fire on:
const result = URL.parse(maybeUrl); // valid Node 22+ / modern browser APIProposed fix
Drop objectName === 'URL' from the condition. Only the lowercase legacy url module (and namespace/default imports of it) are deprecated.
if (
objectName === 'url' ||
urlImportedNames.has(objectName ?? '')
) { ... }A test that pins this down would also be welcome:
it('does not flag URL.parse static method', () => {
const result = lint(`const u = URL.parse('https://example.com');`);
expect(result).toHaveLength(0);
});Minor: the message could nudge toward either URL.parse(input) (returns null on invalid) or new URL(input, base) (throws), since both are valid replacements with different ergonomics.
Once the URL.parse exemption is in, happy to approve.
|
@danielchen0 — heads up: lainterr[bot] requested changes on this PR (review submitted 2026-05-01T00:09:31Z, on the current head SHA 7712133). Substantive concern: the rule fires on Not auto-fixable from here — the rule semantics need a real call. Pinging you to address. — danielchen0-pr-monitor |
|
Auto-fix: Lint & Format CI was failing on this rebase because README.md needed prettier formatting. Pushed prettier --write README.md as a follow-up commit. CI should go green on the next run. |
Rebased onto main to resolve conflicts after #51 merge.
75269bf to
d83b853
Compare
Auto-resolved trivial conflicts in shared files. Resolved by Lainter (steward).
|
Auto-fix: lainterr's main-merge bumped this branch's head and the README rule-table alignment drifted (prettier flagged it on the new head). Pushed lainterr[bot]'s CHANGES_REQUESTED on the URL.parse false-positive is still open from 05-01 (substantive — |
Auto-resolved trivial conflicts in shared files. Resolved by Lainter (steward).
Summary
no-deprecated-url-parserule that detects usage ofurl.parse(), deprecated in Node.jsnew URL(input, base)insteadimport * as url), and named imports (import { parse }) from bothurlandnode:urlbackendonlyTest plan
url.parse('...')with default importurl.parse('...')withimport * as url from 'node:url'parse('...')withimport { parse } from 'url'urlParse('...')withimport { parse as urlParse }new URL('...')url.format(...)parse()frompathmodule