docs(linter/consistent-function-scoping): improve rule documentation (#5015)

This commit is contained in:
DonIsaac 2024-08-21 00:47:17 +00:00
parent 79c2493223
commit cd9f1cd278
2 changed files with 521 additions and 662 deletions

View file

@ -1,54 +1,9 @@
--- ---
source: crates/oxc_linter/src/tester.rs 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: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. ⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
╭─[consistent_function_scoping.tsx:3:30] ╭─[consistent_function_scoping.tsx:3:30]
2 │ function doFoo(FooComponent) { 2 │ {
3 │ function Bar() {
· ───
4 │ return <FooComponent />;
╰────
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:30]
2 │ function Foo() {
3 │ function Bar () {
· ───
4 │ return <div />
╰────
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:30]
2 │ function foo() {
3 │ function bar() {
· ───
4 │ return <JSX/>;
╰────
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: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:30]
2 │ function doFoo(foo) {
3 │ function doBar(bar) { 3 │ function doBar(bar) {
· ───── · ─────
4 │ return bar; 4 │ return bar;
@ -56,11 +11,52 @@ source: crates/oxc_linter/src/tester.rs
help: Move this function to the outer scope. help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope. ⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
╭─[consistent_function_scoping.tsx:4:30] ╭─[consistent_function_scoping.tsx:2:26]
3 │ const foo = 'foo'; 1 │ function doFoo(FooComponent) {
4 │ function doBar(bar) { 2 │ function Bar() {
· ───── · ───
5 │ return bar; 3 │ return <FooComponent />;
╰────
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:2:26]
1 │ function Foo() {
2 │ function Bar () {
· ───
3 │ return <div />
╰────
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:1:27]
1 │ function foo() { function bar() { return <JSX/>; } }
· ───
╰────
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:1:29]
1 │ function doFoo(Foo) { const doBar = () => arguments; 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:2:26]
1 │ function doFoo(foo) {
2 │ function doBar(bar) {
· ─────
3 │ 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:26]
2 │ const foo = 'foo';
3 │ function doBar(bar) {
· ─────
4 │ return bar;
╰──── ╰────
help: Move this function to the outer scope. help: Move this function to the outer scope.
@ -79,11 +75,11 @@ source: crates/oxc_linter/src/tester.rs
help: Move this function to the outer scope. help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope. ⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
╭─[consistent_function_scoping.tsx:3:35] ╭─[consistent_function_scoping.tsx:2:31]
2 │ const doFoo = function() { 1 │ const doFoo = function() {
3 │ const doBar = function(bar) { 2 │ const doBar = function(bar) {
· ──────── · ────────
4 │ return bar; 3 │ return bar;
╰──── ╰────
help: Move this function to the outer scope. help: Move this function to the outer scope.
@ -109,11 +105,9 @@ source: crates/oxc_linter/src/tester.rs
help: Move this function to the outer scope. help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope. ⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
╭─[consistent_function_scoping.tsx:3:30] ╭─[consistent_function_scoping.tsx:1:32]
2 │ function doFoo(Foo) { 1 │ function doFoo(Foo) { function doBar() { return this; } return doBar(); };
3 │ function doBar() { · ─────
· ─────
4 │ return this;
╰──── ╰────
help: Move this function to the outer scope. help: Move this function to the outer scope.
@ -125,47 +119,47 @@ source: crates/oxc_linter/src/tester.rs
help: Move this function to the outer scope. help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope. ⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
╭─[consistent_function_scoping.tsx:3:27] ╭─[consistent_function_scoping.tsx:2:23]
2 │ function doFoo(Foo) { 1 │ function doFoo(Foo) {
3 │ const doBar = () => (function() {return () => this})(); 2 │ const doBar = () => (function() {return () => this})();
· ───── · ─────
4 │ return doBar(); 3 │ return doBar();
╰──── ╰────
help: Move this function to the outer scope. help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope. ⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
╭─[consistent_function_scoping.tsx:3:30] ╭─[consistent_function_scoping.tsx:2:26]
2 │ function doFoo(Foo) { 1 │ function doFoo(Foo) {
3 │ function doBar() { 2 │ function doBar() {
· ───── · ─────
4 │ return arguments; 3 │ return arguments;
╰──── ╰────
help: Move this function to the outer scope. help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope. ⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
╭─[consistent_function_scoping.tsx:3:27] ╭─[consistent_function_scoping.tsx:2:23]
2 │ function doFoo(Foo) { 1 │ function doFoo(Foo) {
3 │ const doBar = () => (function() {return arguments})(); 2 │ const doBar = () => (function() {return arguments})();
· ───── · ─────
4 │ return doBar(); 3 │ return doBar();
╰──── ╰────
help: Move this function to the outer scope. help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope. ⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
╭─[consistent_function_scoping.tsx:3:30] ╭─[consistent_function_scoping.tsx:2:26]
2 │ function doFoo(foo) { 1 │ function doFoo(foo) {
3 │ function doBar(bar) { 2 │ function doBar(bar) {
· ───── · ─────
4 │ return doBar(bar); 3 │ return doBar(bar);
╰──── ╰────
help: Move this function to the outer scope. help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope. ⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
╭─[consistent_function_scoping.tsx:3:30] ╭─[consistent_function_scoping.tsx:2:26]
2 │ function doFoo(foo) { 1 │ function doFoo(foo) {
3 │ function doBar(bar) { 2 │ function doBar(bar) {
· ───── · ─────
4 │ return bar; 3 │ return bar;
╰──── ╰────
help: Move this function to the outer scope. help: Move this function to the outer scope.
@ -177,20 +171,16 @@ source: crates/oxc_linter/src/tester.rs
help: Move this function to the outer scope. help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope. ⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
╭─[consistent_function_scoping.tsx:5:38] ╭─[consistent_function_scoping.tsx:1:36]
4 │ { 1 │ function doFoo(foo) { { { function doBar(bar) { return bar; } } } return foo; }
5 │ function doBar(bar) { · ─────
· ─────
6 │ return bar;
╰──── ╰────
help: Move this function to the outer scope. help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope. ⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
╭─[consistent_function_scoping.tsx:4:34] ╭─[consistent_function_scoping.tsx:1:14]
3 │ { 1 │ { { function doBar(bar) { return bar; } } }
4 │ function doBar(bar) { · ─────
· ─────
5 │ return bar;
╰──── ╰────
help: Move this function to the outer scope. help: Move this function to the outer scope.
@ -251,101 +241,101 @@ source: crates/oxc_linter/src/tester.rs
help: Move this function to the outer scope. help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope. ⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
╭─[consistent_function_scoping.tsx:4:34] ╭─[consistent_function_scoping.tsx:3:30]
3 │ function foo() { 2 │ function foo() {
4 │ function bar() { 3 │ function bar() {
· ─── · ───
5 │ } 4 │ }
╰────
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:34]
3 │ function foo() {
4 │ function bar() {
· ───
5 │ }
╰──── ╰────
help: Move this function to the outer scope. help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope. ⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
╭─[consistent_function_scoping.tsx:3:30] ╭─[consistent_function_scoping.tsx:3:30]
2 │ process.nextTick(() => { 2 │ function foo() {
3 │ function returnsZero() { 3 │ function bar() {
· ─────────── · ───
4 │ return true; 4 │ }
╰──── ╰────
help: Move this function to the outer scope. help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope. ⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
╭─[consistent_function_scoping.tsx:5:34] ╭─[consistent_function_scoping.tsx:2:26]
4 │ function() { 1 │ process.nextTick(() => {
5 │ function bar() { 2 │ function returnsZero() {
· ─── · ───────────
6 │ } 3 │ return true;
╰──── ╰────
help: Move this function to the outer scope. 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: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. ⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
╭─[consistent_function_scoping.tsx:4:30] ╭─[consistent_function_scoping.tsx:4:30]
3 │ const Bar = <div /> 3 │ function() {
4 │ function doBaz() { 4 │ function bar() {
· ─────
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:30]
2 │ function Foo() {
3 │ function Bar () {
· ─── · ───
4 │ return <div />
╰────
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:30]
5 │ } 5 │ }
6 │ function doBaz() {
· ─────
7 │ return 42
╰──── ╰────
help: Move this function to the outer scope. help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope. ⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
╭─[consistent_function_scoping.tsx:6:30] ╭─[consistent_function_scoping.tsx:8:30]
5 │ } 7 │ function() {
6 │ function b() {} 8 │ function baz() {
· ─ · ───
7 │ function c() {} 9 │ }
╰──── ╰────
help: Move this function to the outer scope. help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope. ⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
╭─[consistent_function_scoping.tsx:7:30] ╭─[consistent_function_scoping.tsx:3:26]
6 │ function b() {} 2 │ const Bar = <div />
7 │ function c() {} 3 │ function doBaz() {
· · ────
8 │ } 4 │ return 42
╰──── ╰────
help: Move this function to the outer scope. help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope. ⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
╭─[consistent_function_scoping.tsx:10:30] ╭─[consistent_function_scoping.tsx:2:26]
9 │ function fn2() { 1 │ function Foo() {
10 │ function foo() {} 2 │ function Bar () {
· ─── · ───
11 │ } 3 │ return <div />
╰────
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:26]
4 │ }
5 │ function doBaz() {
· ─────
6 │ 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:5:26]
4 │ }
5 │ function b() {}
· ─
6 │ 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:6:26]
5 │ function b() {}
6 │ function c() {}
· ─
7 │ }
╰────
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:26]
8 │ function fn2() {
9 │ function foo() {}
· ───
10 │ }
╰──── ╰────
help: Move this function to the outer scope. help: Move this function to the outer scope.
@ -399,10 +389,8 @@ source: crates/oxc_linter/src/tester.rs
help: Move this function to the outer scope. help: Move this function to the outer scope.
⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope. ⚠ eslint-plugin-unicorn(consistent-function-scoping): Function does not capture any variables from the outer scope.
╭─[consistent_function_scoping.tsx:3:35] ╭─[consistent_function_scoping.tsx:1:34]
2 │ function doFoo() { 1 │ function doFoo() { const doBar = function(bar) { return bar; }; }
3 │ const doBar = function(bar) { · ────────
· ────────
4 │ return bar;
╰──── ╰────
help: Move this function to the outer scope. help: Move this function to the outer scope.