diff --git a/crates/oxc_linter/src/rules/unicorn/consistent_function_scoping.rs b/crates/oxc_linter/src/rules/unicorn/consistent_function_scoping.rs
index 02cc534b03412..c7164533a79eb 100644
--- a/crates/oxc_linter/src/rules/unicorn/consistent_function_scoping.rs
+++ b/crates/oxc_linter/src/rules/unicorn/consistent_function_scoping.rs
@@ -44,11 +44,14 @@ impl std::ops::Deref for ConsistentFunctionScoping {
declare_oxc_lint!(
/// ### What it does
///
- /// Disallow functions that are declared in a scope which does not capture any variables from the outer scope.
+ /// Disallow functions that are declared in a scope which does not capture
+ /// any variables from the outer scope.
///
/// ### Why is this bad?
///
- /// Moving function declarations to the highest possible scope improves readability, directly improves performance and allows JavaScript engines to better optimize your performance.
+ /// Moving function declarations to the highest possible scope improves
+ /// readability, directly improves performance and allows JavaScript engines
+ /// to better optimize your performance.
///
///
/// ### Examples
@@ -127,10 +130,7 @@ impl Rule for ConsistentFunctionScoping {
return;
}
}
- AstKind::ArrowFunctionExpression(arrow_function) => {
- if !self.check_arrow_functions {
- return;
- }
+ AstKind::ArrowFunctionExpression(arrow_function) if self.check_arrow_functions => {
if let Some(binding_ident) = get_function_like_declaration(node, ctx) {
(
binding_ident.symbol_id.get().unwrap(),
@@ -150,9 +150,10 @@ impl Rule for ConsistentFunctionScoping {
return;
}
- if let Some(AstKind::ReturnStatement(_)) =
- outermost_paren_parent(node, ctx).map(oxc_semantic::AstNode::kind)
- {
+ if matches!(
+ outermost_paren_parent(node, ctx).map(AstNode::kind),
+ Some(AstKind::ReturnStatement(_) | AstKind::Argument(_))
+ ) {
return;
}
@@ -258,504 +259,345 @@ fn test() {
use crate::tester::Tester;
let pass = vec![
- (
- "
- function doFoo(foo) {
- return foo;
- }
- ",
- None,
- ),
- (
- "
- function doFoo(foo) {
- return bar;
- }
- ",
- None,
- ),
- (
- "
- const doFoo = function() {};
- ",
- None,
- ),
- (
- "
- const doFoo = foo => foo;
- ",
- None,
- ),
- (
- "
- foo => foo;
- ",
- None,
- ),
- (
- "
- function doFoo(foo) {
- function doBar(bar) {
- return foo + bar;
- }
- return foo;
- }
- ",
- None,
- ),
- (
- "
- const doFoo = function(foo) {
- function doBar(bar) {
- return foo + bar;
- }
- return foo;
- };
- ",
- None,
- ),
- (
- "
- const doFoo = function(foo) {
- const doBar = function(bar) {
- return foo + bar;
- };
- return foo;
- };
- ",
- None,
- ),
- (
- "
- function doFoo(foo) {
- const doBar = function(bar) {
- return foo + bar;
- };
- return foo;
- }
- ",
- None,
- ),
- (
- "
- function doFoo(foo) {
- function doBar(bar) {
- return foo + bar;
- }
- }
- ",
- None,
- ),
- (
- "
- function doFoo(foo = 'foo') {
- function doBar(bar) {
- return foo + bar;
- }
- }
- ",
- None,
- ),
- (
- "
- function doFoo() {
- const foo = 'foo';
- function doBar(bar) {
- return foo + bar;
- }
- return foo;
- }
- ",
- None,
- ),
- (
- "
- function doFoo(foo) {
- function doBar(bar) {
- function doZaz(zaz) {
- return foo + bar + zaz;
- }
- return bar;
- }
- return foo;
- }
- ",
- None,
- ),
- (
- "
- for (let foo = 0; foo < 1; foo++) {
- function doBar(bar) {
- return bar + foo;
- }
- }
- ",
- None,
- ),
- (
- "
- let foo = 0;
- function doFoo() {
- foo = 1;
- function doBar(bar) {
- return foo + bar;
- }
- return foo;
- }
- ",
- None,
- ),
- (
- "
- const doFoo = foo => {
- return foo;
- }
- ",
- None,
- ),
- (
- "
- const doFoo =
- foo =>
- bar =>
- foo + bar;
- ",
- None,
- ),
- (
- "
- const doFoo = () => {
- return bar => bar;
- }
- ",
- None,
- ),
- (
- "
- function doFoo() {
- return bar => bar;
- }
- ",
- None,
- ),
- (
- "
- const doFoo = foo => {
- const doBar = bar => {
- return foo + bar;
- }
- return foo;
- }
- ",
- None,
- ),
- (
- "
- function doFoo() {
- {
- const foo = 'foo';
- function doBar(bar) {
- return bar + foo;
- }
- }
- }
- ",
- None,
- ),
- (
- "
- function doFoo(foo) {
- function doBar(bar) {
- foo.bar = bar;
- }
- function doZaz(zaz) {
- doBar(zaz);
- }
-
- doZaz('zaz');
- };
- ",
- None,
- ),
- (
- "
- function doFoo() {
- return function doBar() {};
- }
- ",
- None,
- ),
- (
- "
- function doFoo(Foo) {
- function doBar() {
- return new Foo();
- }
- return doBar;
- };
- ",
+ ("function doFoo(foo) { return foo; }", None),
+ ("function doFoo(foo) { return bar; }", None),
+ ("const doFoo = function() {};", None),
+ ("const doFoo = foo => foo;", None),
+ ("foo => foo;", None),
+ (
+ "
+ function doFoo(foo) {
+ function doBar(bar) {
+ return foo + bar;
+ }
+ return foo;
+ }
+ ",
None,
),
(
"
- function doFoo(FooComponent) {
- return ;
- }
- ",
+ const doFoo = function(foo) {
+ function doBar(bar) {
+ return foo + bar;
+ }
+ return foo;
+ };
+ ",
None,
),
(
"
- const foo = ;
- ",
+ const doFoo = function(foo) {
+ const doBar = function(bar) {
+ return foo + bar;
+ };
+ return foo;
+ };
+ ",
None,
),
(
"
- function foo() {
- function bar() {
- return ;
- }
- }
- ",
+ function doFoo(foo) {
+ const doBar = function(bar) {
+ return foo + bar;
+ };
+ return foo;
+ }
+ ",
None,
),
(
"
- function doFoo(Foo) {
- const doBar = () => this;
- return doBar();
- };
- ",
+ function doFoo(foo) {
+ function doBar(bar) {
+ return foo + bar;
+ }
+ }
+ ",
None,
),
(
"
- function doFoo(Foo) {
- const doBar = () => () => this;
- return doBar();
- };
- ",
+ function doFoo(foo = 'foo') {
+ function doBar(bar) {
+ return foo + bar;
+ }
+ }
+ ",
None,
),
(
"
- function doFoo(Foo) {
- const doBar = () => () => () => this;
- return doBar();
- };
- ",
+ function doFoo() {
+ const foo = 'foo';
+ function doBar(bar) {
+ return foo + bar;
+ }
+ return foo;
+ }
+ ",
None,
),
(
"
- useEffect(() => {
- function foo() {}
- }, [])
- ",
+ function doFoo(foo) {
+ function doBar(bar) {
+ function doZaz(zaz) {
+ return foo + bar + zaz;
+ }
+ return bar;
+ }
+ return foo;
+ }
+ ",
None,
),
(
"
- React.useEffect(() => {
- function foo() {}
- }, [])
- ",
+ for (let foo = 0; foo < 1; foo++) {
+ function doBar(bar) {
+ return bar + foo;
+ }
+ }
+ ",
None,
),
(
"
- (function() {
- function bar() {}
- })();
- ",
+ let foo = 0;
+ function doFoo() {
+ foo = 1;
+ function doBar(bar) {
+ return foo + bar;
+ }
+ return foo;
+ }
+ ",
None,
),
+ ("const doFoo = foo => { return foo; }", None),
+ ("const doFoo = foo => bar => foo + bar;", None),
+ ("const doFoo = () => { return bar => bar; } ", None),
(
"
- (function() {
- function bar() {}
- }());
- ",
+ const doFoo = foo => {
+ const doBar = bar => {
+ return foo + bar;
+ }
+ return foo;
+ }
+ ",
None,
),
(
"
- !function() {
- function bar() {}
- }();
- ",
+ function doFoo() {
+ {
+ const foo = 'foo';
+ function doBar(bar) {
+ return bar + foo;
+ }
+ }
+ }
+ ",
None,
),
(
"
- (() => {
- function bar() {}
- })();
- ",
+ function doFoo(foo) {
+ function doBar(bar) {
+ foo.bar = bar;
+ }
+ function doZaz(zaz) {
+ doBar(zaz);
+ }
+
+ doZaz('zaz');
+ };
+ ",
None,
),
+ ("function doFoo() { return function doBar() {}; }", None),
(
"
- (async function() {
- function bar() {}
- })();
- ",
+ function doFoo(Foo) {
+ function doBar() {
+ return new Foo();
+ }
+ return doBar;
+ };
+ ",
None,
),
+ ("function doFoo(FooComponent) { return ; } ", None),
+ ("const foo = ;", None),
+ ("function foo() { function bar() { return ; } }", None),
+ ("function doFoo(Foo) { const doBar = () => this; return doBar(); };", None),
+ ("function doFoo(Foo) { const doBar = () => () => this; return doBar(); };", None),
(
"
- (async function * () {
- function bar() {}
- })();
- ",
+ function doFoo(Foo) {
+ const doBar = () => () => () => this;
+ return doBar();
+ };
+ ",
None,
),
+ ("useEffect(() => { function foo() {} }, []) ", None),
+ ("React.useEffect(() => { function foo() {} }, [])", None),
+ ("(function() { function bar() {} })();", None),
+ ("(function() { function bar() {} }());", None),
+ (" !function() { function bar() {} }();", None),
+ ("(() => { function bar() {} })();", None),
+ ("(async function() { function bar() {} })();", None),
+ (" (async function * () { function bar() {} })();", None),
(
"
- function doFoo() {
- const doBar = (function(bar) {
- return bar;
- })();
- }
- ",
+ function doFoo() {
+ const doBar = (function(bar) {
+ return bar;
+ })();
+ }
+ ",
None,
),
(
"
- const enrichErrors = (packageName, cliArgs, f) => async (...args) => {
- try {
- return await f(...args);
- } catch (error) {
- error.packageName = packageName;
- error.cliArgs = cliArgs;
- throw error;
- }
- };
- ",
+ const enrichErrors = (packageName, cliArgs, f) => async (...args) => {
+ try {
+ return await f(...args);
+ } catch (error) {
+ error.packageName = packageName;
+ error.cliArgs = cliArgs;
+ throw error;
+ }
+ };
+ ",
None,
),
(
"
- export const canStepForward = ([X, Y]) => ([x, y]) => direction => {
- switch (direction) {
- case 0:
- return y !== 0
- case 1:
- return x !== X - 1
- case 2:
- return y !== Y - 1
- case 3:
- return x !== 0
- default:
- throw new Error('unknown direction')
- }
- }
- ",
+ export const canStepForward = ([X, Y]) => ([x, y]) => direction => {
+ switch (direction) {
+ case 0:
+ return y !== 0
+ case 1:
+ return x !== X - 1
+ case 2:
+ return y !== Y - 1
+ case 3:
+ return x !== 0
+ default:
+ throw new Error('unknown direction')
+ }
+ }
+ ",
None,
),
(
"
- 'use strict';
+ 'use strict';
- module.exports = function recordErrors(eventEmitter, stateArgument) {
- const stateVariable = stateArgument;
- function onError(error) {
- stateVariable.inputError = error;
- }
- eventEmitter.once('error', onError);
- };
- ",
+ module.exports = function recordErrors(eventEmitter, stateArgument) {
+ const stateVariable = stateArgument;
+ function onError(error) {
+ stateVariable.inputError = error;
+ }
+ eventEmitter.once('error', onError);
+ };
+ ",
None,
),
(
"
- module.exports = function recordErrors(eventEmitter, stateArgument) {
- function onError(error) {
- stateArgument.inputError = error;
- }
- function onError2(error) {
- onError(error);
- }
+ module.exports = function recordErrors(eventEmitter, stateArgument) {
+ function onError(error) {
+ stateArgument.inputError = error;
+ }
+ function onError2(error) {
+ onError(error);
+ }
- eventEmitter.once('error', onError2);
- };
- ",
+ eventEmitter.once('error', onError2);
+ };
+ ",
None,
),
(
"
- function outer(stream) {
- let content;
+ function outer(stream) {
+ let content;
- function inner() {
- process.stdout.write(content);
- }
+ function inner() {
+ process.stdout.write(content);
+ }
- inner();
- }
- ",
+ inner();
+ }
+ ",
None,
),
(
- "
- function outer () {
- const inner = () => {}
- }
- ",
+ "function outer () { const inner = () => {} }",
Some(serde_json::json!([{"checkArrowFunctions": false}])),
),
(
"
- type Data = T extends 'error' ? Error : Record | unknown[]
+ type Data = T extends 'error' ? Error : Record | unknown[]
- type Method = 'info' | 'error'
+ type Method = 'info' | 'error'
- export function createLogger(name: string) {
- // Two lint errors are on the next line.
- const log = (method: T) => (data: Data) => {
- try {
- // eslint-disable-next-line no-console
- console[method](JSON.stringify({ name, data }))
- } catch (error) {
- console.error(error)
- }
- }
+ export function createLogger(name: string) {
+ // Two lint errors are on the next line.
+ const log = (method: T) => (data: Data) => {
+ try {
+ // eslint-disable-next-line no-console
+ console[method](JSON.stringify({ name, data }))
+ } catch (error) {
+ console.error(error)
+ }
+ }
- return {
- info: log('info'),
- error: log('error'),
- }
- }
- ",
+ return {
+ info: log('info'),
+ error: log('error'),
+ }
+ }
+ ",
None,
),
(
"
- test('it works', async function(assert) {
- function assertHeader(assertions) {
- for (const [key, value] of Object.entries(assertions)) {
- assert.strictEqual(
- native[key],
- value
- );
- }
- }
+ test('it works', async function(assert) {
+ function assertHeader(assertions) {
+ for (const [key, value] of Object.entries(assertions)) {
+ assert.strictEqual(
+ native[key],
+ value
+ );
+ }
+ }
- // ...
- });
- ",
+ // ...
+ });
+ ",
None,
),
(
"
- export function a(x: number) {
- const b = (y: number) => (z: number): number => x + y + z;
- return b(1)(2);
- }
- ",
+ export function a(x: number) {
+ const b = (y: number) => (z: number): number => x + y + z;
+ return b(1)(2);
+ }
+ ",
None,
),
+ // https://github.com/oxc-project/oxc/pull/4948#issuecomment-2295819822
+ ("t.throws(() => receiveString(function a() {}), {})", None),
+ ("function test () { t.throws(() => receiveString(function a() {}), {}) }", None),
+ ("function foo() { let x = new Bar(function b() {}) }", None),
];
let fail = vec![
@@ -764,259 +606,192 @@ fn test() {
// declared function is inside a block statement
(
"
- function doFoo(foo) {
- {
- function doBar(bar) {
- return bar;
- }
- }
- return foo;
- }
- ",
+ function doFoo(foo) {
+ {
+ function doBar(bar) {
+ return bar;
+ }
+ }
+ return foo;
+ }
+ ",
None,
),
(
"
- function doFoo(FooComponent) {
- function Bar() {
- return ;
- }
- return Bar;
- };
- ",
+ function doFoo(FooComponent) {
+ function Bar() {
+ return ;
+ }
+ return Bar;
+ };
+ ",
None,
),
(
"
- function Foo() {
- function Bar () {
- return
- }
- return { Bar() }
- }
- ",
+ function Foo() {
+ function Bar () {
+ return
+ }
+ return { Bar() }
+ }
+ ",
None,
),
(
"
- function foo() {
- function bar() {
- return ;
- }
- }
- ",
+ function foo() {
+ function bar() {
+ return ;
+ }
+ }
+ ",
None,
),
(
"
- function doFoo(Foo) {
- const doBar = () => arguments;
- return doBar();
- };
- ",
+ function doFoo(Foo) {
+ const doBar = () => arguments;
+ return doBar();
+ };
+ ",
None,
),
// end of cases that eslint-plugin-unicorn passes, but we fail.
(
"
- function doFoo(foo) {
- function doBar(bar) {
- return bar;
- }
- return foo;
- }
- ",
- None,
- ),
- (
- "
- function doFoo() {
- const foo = 'foo';
- function doBar(bar) {
- return bar;
- }
- return foo;
- }
- ",
- None,
- ),
- (
- "
- function doFoo() {
- function doBar(bar) {
- return bar;
- }
- }
- ",
- None,
- ),
- (
- "
- const doFoo = function() {
- function doBar(bar) {
- return bar;
- }
- };
- ",
- None,
- ),
- (
- "
- const doFoo = function() {
- const doBar = function(bar) {
- return bar;
- };
- };
- ",
- None,
- ),
- (
- "
- function doFoo() {
- const doBar = function(bar) {
- return bar;
- };
- }
- ",
- None,
- ),
- (
- "
- function doFoo() {
- const doBar = function(bar) {
- return bar;
- };
- doBar();
- }
- ",
- None,
- ),
- (
- "
- const doFoo = () => {
- const doBar = bar => {
- return bar;
- }
- }
- ",
+ function doFoo(foo) {
+ function doBar(bar) {
+ return bar;
+ }
+ return foo;
+ }
+ ",
None,
),
(
"
- function doFoo(Foo) {
- function doBar() {
- return this;
- }
- return doBar();
- };
- ",
+ function doFoo() {
+ const foo = 'foo';
+ function doBar(bar) {
+ return bar;
+ }
+ return foo;
+ }
+ ",
None,
),
+ ("function doFoo() { function doBar(bar) { return bar; } }", None),
+ ("const doFoo = function() { function doBar(bar) { return bar; } };", None),
(
"
- function doFoo(Foo) {
- const doBar = () => (function() {return this})();
- return doBar();
- };
- ",
+ const doFoo = function() {
+ const doBar = function(bar) {
+ return bar;
+ };
+ };
+ ",
None,
),
+ ("function doFoo() { const doBar = function(bar) { return bar; }; }", None),
+ ("function doFoo() { const doBar = function(bar) { return bar; }; doBar(); }", None),
+ ("const doFoo = () => { const doBar = bar => { return bar; } }", None),
(
"
- function doFoo(Foo) {
- const doBar = () => (function() {return () => this})();
- return doBar();
- };
- ",
+ function doFoo(Foo) {
+ function doBar() {
+ return this;
+ }
+ return doBar();
+ };
+ ",
None,
),
(
- "
- function doFoo(Foo) {
- function doBar() {
- return arguments;
- }
- return doBar();
- };
- ",
+ "function doFoo(Foo) { const doBar = () => (function() {return this})(); return doBar(); };",
None,
),
(
"
- function doFoo(Foo) {
- const doBar = () => (function() {return arguments})();
- return doBar();
- };
- ",
+ function doFoo(Foo) {
+ const doBar = () => (function() {return () => this})();
+ return doBar();
+ };
+ ",
None,
),
(
"
- function doFoo(foo) {
- function doBar(bar) {
- return doBar(bar);
- }
- return foo;
- }
- ",
+ function doFoo(Foo) {
+ function doBar() {
+ return arguments;
+ }
+ return doBar();
+ };
+ ",
None,
),
(
"
- function doFoo(foo) {
- function doBar(bar) {
- return bar;
- }
- return doBar;
- }
- ",
+ function doFoo(Foo) {
+ const doBar = () => (function() {return arguments})();
+ return doBar();
+ };
+ ",
None,
),
(
"
- function doFoo() {
- function doBar() {}
- }
- ",
+ function doFoo(foo) {
+ function doBar(bar) {
+ return doBar(bar);
+ }
+ return foo;
+ }
+ ",
None,
),
(
"
- function doFoo(foo) {
- {
- {
- function doBar(bar) {
- return bar;
- }
- }
- }
- return foo;
- }
- ",
+ function doFoo(foo) {
+ function doBar(bar) {
+ return bar;
+ }
+ return doBar;
+ }
+ ",
None,
),
+ ("function doFoo() { function doBar() {} }", None),
(
"
- {
- {
- function doBar(bar) {
- return bar;
- }
- }
- }
- ",
+ function doFoo(foo) {
+ {
+ {
+ function doBar(bar) {
+ return bar;
+ }
+ }
+ }
+ return foo;
+ }
+ ",
None,
),
(
"
- for (let foo = 0; foo < 1; foo++) {
- function doBar(bar) {
- return bar;
- }
- }
- ",
+ {
+ {
+ function doBar(bar) {
+ return bar;
+ }
+ }
+ }
+ ",
None,
),
+ ("for (let foo = 0; foo < 1; foo++) { function doBar(bar) { return bar; } }", None),
("function foo() { function bar() {} }", None),
("function foo() { async function bar() {} }", None),
("function foo() { function* bar() {} }", None),
@@ -1027,176 +802,130 @@ fn test() {
("function foo() { async function* baz() {} }", None),
(
"
- useEffect(() => {
- function foo() {
- function bar() {
- }
- }
- }, [])
- ",
+ useEffect(() => {
+ function foo() {
+ function bar() {
+ }
+ }
+ }, [])
+ ",
None,
),
(
"
- (function() {
- function foo() {
- function bar() {
- }
- }
- })();
- ",
+ (function() {
+ function foo() {
+ function bar() {
+ }
+ }
+ })();
+ ",
None,
),
(
"
- process.nextTick(() => {
- function returnsZero() {
- return true;
- }
- process.exitCode = returnsZero();
- });
- ",
+ process.nextTick(() => {
+ function returnsZero() {
+ return true;
+ }
+ process.exitCode = returnsZero();
+ });
+ ",
None,
),
(
"
- foo(
- // This is not IIFE
- function() {
- function bar() {
- }
- },
- // This is IIFE
- (function() {
- function baz() {
- }
- })(),
- )
- ",
+ foo(
+ // This is not IIFE
+ function() {
+ function bar() {
+ }
+ },
+ // This is IIFE
+ (function() {
+ function baz() {
+ }
+ })(),
+ )
+ ",
None,
),
(
"
- // This is IIFE
- (function() {
- function bar() {
- }
- })(
- // This is not IIFE
- function() {
- function baz() {
- }
- },
- )
- ",
+ // This is an IIFE
+ (function() {
+ function bar() {
+ }
+ })(
+ // This is not IIFE
+ function() {
+ function baz() {
+ }
+ },
+ )
+ ",
None,
),
(
"
- function Foo() {
- const Bar =
- function doBaz() {
- return 42
- }
- return { doBaz() }
- }
- ",
+ function Foo() {
+ const Bar =
+ function doBaz() {
+ return 42
+ }
+ return { doBaz() }
+ }
+ ",
None,
),
(
"
- function Foo() {
- function Bar () {
- return
- }
- function doBaz() {
- return 42
- }
- return { doBaz() }
- }
- ",
+ function Foo() {
+ function Bar () {
+ return
+ }
+ function doBaz() {
+ return 42
+ }
+ return { doBaz() }
+ }
+ ",
None,
),
(
"
- function fn1() {
- function a() {
- return ;
- }
- function b() {}
- function c() {}
- }
- function fn2() {
- function foo() {}
- }
- ",
+ function fn1() {
+ function a() {
+ return ;
+ }
+ function b() {}
+ function c() {}
+ }
+ function fn2() {
+ function foo() {}
+ }
+ ",
None,
),
(
- "
- const outer = () => {
- function inner() {}
- }
- ",
+ "const outer = () => { function inner() {} }",
Some(serde_json::json!([{"checkArrowFunctions": false}])),
),
- (
- "
- function foo() {
- function bar() {}
- }
- ",
- None,
- ),
- (
- "
- function foo() {
- async function bar() {}
- }
- ",
- None,
- ),
- (
- "
- function foo() {
- function * bar() {}
- }
- ",
- None,
- ),
- (
- "
- function foo() {
- async function * bar() {}
- }
- ",
- None,
- ),
- (
- "
- function foo() {
- const bar = () => {}
- }
- ",
- None,
- ),
+ ("function foo() { function bar() {} }", None),
+ ("function foo() { async function bar() {} }", None),
+ ("function foo() { function * bar() {} }", None),
+ ("function foo() { async function * bar() {} }", None),
+ ("function foo() { const bar = () => {} }", None),
// ("const doFoo = () => bar => bar;", None),
+ ("function foo() { const bar = async () => {} }", None),
(
"
- function foo() {
- const bar = async () => {}
- }
- ",
- None,
- ),
- (
- "
- function doFoo() {
- const doBar = function(bar) {
- return bar;
- };
- }
- ",
+ function doFoo() {
+ const doBar = function(bar) {
+ return bar;
+ };
+ }
+ ",
None,
),
];
diff --git a/crates/oxc_linter/src/snapshots/consistent_function_scoping.snap b/crates/oxc_linter/src/snapshots/consistent_function_scoping.snap
index b61d9a06c64d7..defa93f85b883 100644
--- a/crates/oxc_linter/src/snapshots/consistent_function_scoping.snap
+++ b/crates/oxc_linter/src/snapshots/consistent_function_scoping.snap
@@ -2,218 +2,202 @@
source: crates/oxc_linter/src/tester.rs
---
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:4:26]
- 3 │ {
- 4 │ function doBar(bar) {
- · ─────
- 5 │ return bar;
+ ╭─[consistent_function_scoping.tsx:4:34]
+ 3 │ {
+ 4 │ function doBar(bar) {
+ · ─────
+ 5 │ return bar;
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:23]
- 2 │ function doFoo(FooComponent) {
- 3 │ function Bar() {
- · ───
- 4 │ return ;
+ ╭─[consistent_function_scoping.tsx:3:30]
+ 2 │ function doFoo(FooComponent) {
+ 3 │ function Bar() {
+ · ───
+ 4 │ return ;
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:23]
- 2 │ function Foo() {
- 3 │ function Bar () {
- · ───
- 4 │ return
+ ╭─[consistent_function_scoping.tsx:3:30]
+ 2 │ function Foo() {
+ 3 │ function Bar () {
+ · ───
+ 4 │ return
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:23]
- 2 │ function foo() {
- 3 │ function bar() {
- · ───
- 4 │ return ;
+ ╭─[consistent_function_scoping.tsx:3:30]
+ 2 │ function foo() {
+ 3 │ function bar() {
+ · ───
+ 4 │ return ;
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:20]
- 2 │ function doFoo(Foo) {
- 3 │ const doBar = () => arguments;
- · ─────
- 4 │ return doBar();
+ ╭─[consistent_function_scoping.tsx:3:27]
+ 2 │ function doFoo(Foo) {
+ 3 │ const doBar = () => arguments;
+ · ─────
+ 4 │ return doBar();
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:18]
- 2 │ function doFoo(foo) {
- 3 │ function doBar(bar) {
- · ─────
- 4 │ return bar;
+ ╭─[consistent_function_scoping.tsx:3:30]
+ 2 │ function doFoo(foo) {
+ 3 │ function doBar(bar) {
+ · ─────
+ 4 │ return bar;
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:4:18]
- 3 │ const foo = 'foo';
- 4 │ function doBar(bar) {
- · ─────
- 5 │ return bar;
+ ╭─[consistent_function_scoping.tsx:4:30]
+ 3 │ const foo = 'foo';
+ 4 │ function doBar(bar) {
+ · ─────
+ 5 │ return bar;
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:18]
- 2 │ function doFoo() {
- 3 │ function doBar(bar) {
- · ─────
- 4 │ return bar;
+ ╭─[consistent_function_scoping.tsx:1:29]
+ 1 │ function doFoo() { function doBar(bar) { return bar; } }
+ · ─────
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:18]
- 2 │ const doFoo = function() {
- 3 │ function doBar(bar) {
- · ─────
- 4 │ return bar;
+ ╭─[consistent_function_scoping.tsx:1:37]
+ 1 │ const doFoo = function() { function doBar(bar) { return bar; } };
+ · ─────
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:23]
- 2 │ const doFoo = function() {
- 3 │ const doBar = function(bar) {
- · ────────
- 4 │ return bar;
+ ╭─[consistent_function_scoping.tsx:3:35]
+ 2 │ const doFoo = function() {
+ 3 │ const doBar = function(bar) {
+ · ────────
+ 4 │ return bar;
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:23]
- 2 │ function doFoo() {
- 3 │ const doBar = function(bar) {
- · ────────
- 4 │ return bar;
+ ╭─[consistent_function_scoping.tsx:1:34]
+ 1 │ function doFoo() { const doBar = function(bar) { return bar; }; }
+ · ────────
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:23]
- 2 │ function doFoo() {
- 3 │ const doBar = function(bar) {
- · ────────
- 4 │ return bar;
+ ╭─[consistent_function_scoping.tsx:1:34]
+ 1 │ function doFoo() { const doBar = function(bar) { return bar; }; doBar(); }
+ · ────────
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:15]
- 2 │ const doFoo = () => {
- 3 │ const doBar = bar => {
- · ─────
- 4 │ return bar;
+ ╭─[consistent_function_scoping.tsx:1:29]
+ 1 │ const doFoo = () => { const doBar = bar => { return bar; } }
+ · ─────
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:18]
- 2 │ function doFoo(Foo) {
- 3 │ function doBar() {
- · ─────
- 4 │ return this;
+ ╭─[consistent_function_scoping.tsx:3:30]
+ 2 │ function doFoo(Foo) {
+ 3 │ function doBar() {
+ · ─────
+ 4 │ return this;
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:15]
- 2 │ function doFoo(Foo) {
- 3 │ const doBar = () => (function() {return this})();
- · ─────
- 4 │ return doBar();
+ ╭─[consistent_function_scoping.tsx:1:29]
+ 1 │ function doFoo(Foo) { const doBar = () => (function() {return this})(); return doBar(); };
+ · ─────
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:15]
- 2 │ function doFoo(Foo) {
- 3 │ const doBar = () => (function() {return () => this})();
- · ─────
- 4 │ return doBar();
+ ╭─[consistent_function_scoping.tsx:3:27]
+ 2 │ function doFoo(Foo) {
+ 3 │ const doBar = () => (function() {return () => this})();
+ · ─────
+ 4 │ return doBar();
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:18]
- 2 │ function doFoo(Foo) {
- 3 │ function doBar() {
- · ─────
- 4 │ return arguments;
+ ╭─[consistent_function_scoping.tsx:3:30]
+ 2 │ function doFoo(Foo) {
+ 3 │ function doBar() {
+ · ─────
+ 4 │ return arguments;
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:15]
- 2 │ function doFoo(Foo) {
- 3 │ const doBar = () => (function() {return arguments})();
- · ─────
- 4 │ return doBar();
+ ╭─[consistent_function_scoping.tsx:3:27]
+ 2 │ function doFoo(Foo) {
+ 3 │ const doBar = () => (function() {return arguments})();
+ · ─────
+ 4 │ return doBar();
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:24]
- 2 │ function doFoo(foo) {
- 3 │ function doBar(bar) {
- · ─────
- 4 │ return doBar(bar);
+ ╭─[consistent_function_scoping.tsx:3:30]
+ 2 │ function doFoo(foo) {
+ 3 │ function doBar(bar) {
+ · ─────
+ 4 │ return doBar(bar);
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:18]
- 2 │ function doFoo(foo) {
- 3 │ function doBar(bar) {
- · ─────
- 4 │ return bar;
+ ╭─[consistent_function_scoping.tsx:3:30]
+ 2 │ function doFoo(foo) {
+ 3 │ function doBar(bar) {
+ · ─────
+ 4 │ return bar;
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:18]
- 2 │ function doFoo() {
- 3 │ function doBar() {}
- · ─────
- 4 │ }
+ ╭─[consistent_function_scoping.tsx:1:29]
+ 1 │ function doFoo() { function doBar() {} }
+ · ─────
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:5:20]
- 4 │ {
- 5 │ function doBar(bar) {
- · ─────
- 6 │ return bar;
+ ╭─[consistent_function_scoping.tsx:5:38]
+ 4 │ {
+ 5 │ function doBar(bar) {
+ · ─────
+ 6 │ return bar;
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:4:19]
- 3 │ {
- 4 │ function doBar(bar) {
- · ─────
- 5 │ return bar;
+ ╭─[consistent_function_scoping.tsx:4:34]
+ 3 │ {
+ 4 │ function doBar(bar) {
+ · ─────
+ 5 │ return bar;
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:18]
- 2 │ for (let foo = 0; foo < 1; foo++) {
- 3 │ function doBar(bar) {
- · ─────
- 4 │ return bar;
+ ╭─[consistent_function_scoping.tsx:1:46]
+ 1 │ for (let foo = 0; foo < 1; foo++) { function doBar(bar) { return bar; } }
+ · ─────
╰────
help: Move this function to the outer scope.
@@ -267,172 +251,158 @@ source: crates/oxc_linter/src/tester.rs
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:4:19]
- 3 │ function foo() {
- 4 │ function bar() {
- · ───
- 5 │ }
+ ╭─[consistent_function_scoping.tsx:4:34]
+ 3 │ function foo() {
+ 4 │ function bar() {
+ · ───
+ 5 │ }
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:4:19]
- 3 │ function foo() {
- 4 │ function bar() {
- · ───
- 5 │ }
+ ╭─[consistent_function_scoping.tsx:4:34]
+ 3 │ function foo() {
+ 4 │ function bar() {
+ · ───
+ 5 │ }
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:18]
- 2 │ process.nextTick(() => {
- 3 │ function returnsZero() {
- · ───────────
- 4 │ return true;
+ ╭─[consistent_function_scoping.tsx:3:30]
+ 2 │ process.nextTick(() => {
+ 3 │ function returnsZero() {
+ · ───────────
+ 4 │ return true;
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:5:19]
- 4 │ function() {
- 5 │ function bar() {
- · ───
- 6 │ }
+ ╭─[consistent_function_scoping.tsx:5:34]
+ 4 │ function() {
+ 5 │ function bar() {
+ · ───
+ 6 │ }
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:9:19]
- 8 │ function() {
- 9 │ function baz() {
- · ───
- 10 │ }
+ ╭─[consistent_function_scoping.tsx:9:34]
+ 8 │ function() {
+ 9 │ function baz() {
+ · ───
+ 10 │ }
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:4:18]
- 3 │ const Bar =
- 4 │ function doBaz() {
- · ─────
- 5 │ return 42
+ ╭─[consistent_function_scoping.tsx:4:30]
+ 3 │ const Bar =
+ 4 │ function doBaz() {
+ · ─────
+ 5 │ return 42
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:18]
- 2 │ function Foo() {
- 3 │ function Bar () {
- · ───
- 4 │ return
+ ╭─[consistent_function_scoping.tsx:3:30]
+ 2 │ function Foo() {
+ 3 │ function Bar () {
+ · ───
+ 4 │ return
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:6:18]
- 5 │ }
- 6 │ function doBaz() {
- · ─────
- 7 │ return 42
+ ╭─[consistent_function_scoping.tsx:6:30]
+ 5 │ }
+ 6 │ function doBaz() {
+ · ─────
+ 7 │ return 42
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:6:18]
- 5 │ }
- 6 │ function b() {}
- · ─
- 7 │ function c() {}
+ ╭─[consistent_function_scoping.tsx:6:30]
+ 5 │ }
+ 6 │ function b() {}
+ · ─
+ 7 │ function c() {}
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:7:18]
- 6 │ function b() {}
- 7 │ function c() {}
- · ─
- 8 │ }
+ ╭─[consistent_function_scoping.tsx:7:30]
+ 6 │ function b() {}
+ 7 │ function c() {}
+ · ─
+ 8 │ }
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:10:18]
- 9 │ function fn2() {
- 10 │ function foo() {}
- · ───
- 11 │ }
+ ╭─[consistent_function_scoping.tsx:10:30]
+ 9 │ function fn2() {
+ 10 │ function foo() {}
+ · ───
+ 11 │ }
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:18]
- 2 │ const outer = () => {
- 3 │ function inner() {}
- · ─────
- 4 │ }
+ ╭─[consistent_function_scoping.tsx:1:32]
+ 1 │ const outer = () => { function inner() {} }
+ · ─────
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:17]
- 2 │ function foo() {
- 3 │ function bar() {}
- · ───
- 4 │ }
+ ╭─[consistent_function_scoping.tsx:1:27]
+ 1 │ function foo() { function bar() {} }
+ · ───
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:23]
- 2 │ function foo() {
- 3 │ async function bar() {}
- · ───
- 4 │ }
+ ╭─[consistent_function_scoping.tsx:1:33]
+ 1 │ function foo() { async function bar() {} }
+ · ───
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:19]
- 2 │ function foo() {
- 3 │ function * bar() {}
- · ───
- 4 │ }
+ ╭─[consistent_function_scoping.tsx:1:29]
+ 1 │ function foo() { function * bar() {} }
+ · ───
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:25]
- 2 │ function foo() {
- 3 │ async function * bar() {}
- · ───
- 4 │ }
+ ╭─[consistent_function_scoping.tsx:1:35]
+ 1 │ function foo() { async function * bar() {} }
+ · ───
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:14]
- 2 │ function foo() {
- 3 │ const bar = () => {}
- · ───
- 4 │ }
+ ╭─[consistent_function_scoping.tsx:1:24]
+ 1 │ function foo() { const bar = () => {} }
+ · ───
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:14]
- 2 │ function foo() {
- 3 │ const bar = async () => {}
- · ───
- 4 │ }
+ ╭─[consistent_function_scoping.tsx:1:24]
+ 1 │ function foo() { const bar = async () => {} }
+ · ───
╰────
help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
- ╭─[consistent_function_scoping.tsx:3:22]
- 2 │ function doFoo() {
- 3 │ const doBar = function(bar) {
- · ────────
- 4 │ return bar;
+ ╭─[consistent_function_scoping.tsx:3:35]
+ 2 │ function doFoo() {
+ 3 │ const doBar = function(bar) {
+ · ────────
+ 4 │ return bar;
╰────
help: Move this function to the outer scope.