From da072583c1afea4e133752e34e6162526f8ab57a Mon Sep 17 00:00:00 2001 From: therewillbecode Date: Fri, 7 Mar 2025 19:03:01 +0000 Subject: [PATCH 1/2] Improve docs for eslint no-func-assign --- .../src/rules/eslint/no_func_assign.rs | 40 +++++++++++++++++-- .../src/snapshots/eslint_no_func_assign.snap | 7 ++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/crates/oxc_linter/src/rules/eslint/no_func_assign.rs b/crates/oxc_linter/src/rules/eslint/no_func_assign.rs index 96888144fcc08..12dfb8e25b051 100644 --- a/crates/oxc_linter/src/rules/eslint/no_func_assign.rs +++ b/crates/oxc_linter/src/rules/eslint/no_func_assign.rs @@ -19,14 +19,47 @@ declare_oxc_lint!( /// Disallow reassigning `function` declarations /// /// ### Why is this bad? - /// Overwriting/reassigning a function written as a FunctionDeclaration is often indicative of a mistake or issue. /// - /// ### Example - /// ```javascript + /// Overwriting/reassigning a function written as a FunctionDeclaration is often indicative of + /// a mistake or issue. + /// + /// ### Examples /// + /// Examples of **incorrect** code for this rule: + /// ```javascript /// function foo() {} /// foo = bar; /// ``` + /// + /// ```javascript + /// function foo() { + /// foo = bar; + /// } + /// ``` + /// + /// ```javascript + /// let a = function hello() { + /// hello = 123; + /// }; + /// ``` + /// + /// Examples of **correct** code for this rule: + /// ```javascript + /// let foo = function () {} + /// foo = bar; + /// ``` + /// + /// ```javascript + /// function baz(baz) { // `baz` is shadowed. + /// baz = bar; + /// } + /// ``` + /// + /// ``` + /// function qux() { + /// const qux = bar; // `qux` is shadowed. + /// } + /// ``` NoFuncAssign, eslint, correctness @@ -72,6 +105,7 @@ fn test() { ("function foo() { [foo] = bar; }", None), ("(function() { ({x: foo = 0} = bar); function foo() { }; })();", None), ("var a = function foo() { foo = 123; };", None), + ("let a = function hello() { hello = 123;};", None) ]; Tester::new(NoFuncAssign::NAME, NoFuncAssign::PLUGIN, pass, fail).test_and_snapshot(); diff --git a/crates/oxc_linter/src/snapshots/eslint_no_func_assign.snap b/crates/oxc_linter/src/snapshots/eslint_no_func_assign.snap index d536f1e395600..4d65846d06570 100644 --- a/crates/oxc_linter/src/snapshots/eslint_no_func_assign.snap +++ b/crates/oxc_linter/src/snapshots/eslint_no_func_assign.snap @@ -56,3 +56,10 @@ source: crates/oxc_linter/src/tester.rs · ─┬─ · ╰── foo is re-assigned here ╰──── + + ⚠ eslint(no-func-assign): 'hello' is a function. + ╭─[no_func_assign.tsx:1:28] + 1 │ let a = function hello() { hello = 123;}; + · ──┬── + · ╰── hello is re-assigned here + ╰──── From 12af6f036e7e4f2ee18d5ed728ed770c184dc7b7 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Fri, 7 Mar 2025 19:05:24 +0000 Subject: [PATCH 2/2] [autofix.ci] apply automated fixes --- crates/oxc_linter/src/rules/eslint/no_func_assign.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/oxc_linter/src/rules/eslint/no_func_assign.rs b/crates/oxc_linter/src/rules/eslint/no_func_assign.rs index 12dfb8e25b051..cd6e815078fff 100644 --- a/crates/oxc_linter/src/rules/eslint/no_func_assign.rs +++ b/crates/oxc_linter/src/rules/eslint/no_func_assign.rs @@ -105,7 +105,7 @@ fn test() { ("function foo() { [foo] = bar; }", None), ("(function() { ({x: foo = 0} = bar); function foo() { }; })();", None), ("var a = function foo() { foo = 123; };", None), - ("let a = function hello() { hello = 123;};", None) + ("let a = function hello() { hello = 123;};", None), ]; Tester::new(NoFuncAssign::NAME, NoFuncAssign::PLUGIN, pass, fail).test_and_snapshot();