Skip to content

feat(rule): complete isolated_functions#21926

Draft
AliceLanniste wants to merge 1 commit intooxc-project:mainfrom
AliceLanniste:isolated-function
Draft

feat(rule): complete isolated_functions#21926
AliceLanniste wants to merge 1 commit intooxc-project:mainfrom
AliceLanniste:isolated-function

Conversation

@AliceLanniste
Copy link
Copy Markdown
Contributor

part of #684

@AliceLanniste
Copy link
Copy Markdown
Contributor Author

AliceLanniste commented Apr 30, 2026

@camc314 Hello, I have two problems and need your help.

  1. The isolated functions support selectors , but I couldn't find a selector method that works in OXC, which prevented me from passing the test in the selector section.

  2. When override_globals is empty, eslint-plugin-unicorn/isolated-functions will make the global variable location check for writable. I don't know if OXC has a library for storing global variables to perform this check. the current implementation will also trigger a warning for location.
    eslint-plugin-unicorn

{
			name: 'check globals writability',
			code: outdent`
				makeSynchronous(function () {
					location = new URL('https://example.com');
					process = {env: {}};
					process.env.FOO = 'bar';
				});
			`,
			errors: [
				// Only one error, `location = new URL('https://example.com')` and `process.env.FOO = 'bar'` are fine, the problem is `process = {...}`.
				error({
					name: 'process',
					reason: 'callee of function named "makeSynchronous" (global variable is not writable)',
				}),
			],
		},
		```
		
the implementation:

eslint-plugin-unicorn(isolated-functions): overrideGlobals: 'location' is a global variable, and its usage conflicts with the default property.
╭─[isolated_functions.tsx:2:17]
1 │ makeSynchronous(function () {
2 │ location = new URL('https://example.com');
· ────────
3 │ process = {env: {}};
╰────
help: add overrideGlobals option in config file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant