Skip to content

Commit 10b995c

Browse files
docs: add TS options and examples for nofunc in no-use-before-define (#20249)
* docs: add ts options to nofunc * add option heading * apply suggestions and add correct examples
1 parent 167d097 commit 10b995c

File tree

1 file changed

+100
-2
lines changed

1 file changed

+100
-2
lines changed

docs/src/rules/no-use-before-define.md

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ export { foo };
130130
"functions": true,
131131
"classes": true,
132132
"variables": true,
133-
"allowNamedExports": false
133+
"allowNamedExports": false,
134+
"enums": true,
135+
"typedefs": true,
136+
"ignoreTypeReferences": true
134137
}]
135138
}
136139
```
@@ -170,7 +173,7 @@ This rule additionally supports TypeScript type syntax. The following options en
170173
Default is `true`.
171174

172175
This rule accepts `"nofunc"` string as an option.
173-
`"nofunc"` is the same as `{ "functions": false, "classes": true, "variables": true, "allowNamedExports": false }`.
176+
`"nofunc"` is the same as `{ "functions": false, "classes": true, "variables": true, "allowNamedExports": false, "enums": true, "typedefs": true, "ignoreTypeReferences": true }`.
174177

175178
### functions
176179

@@ -488,3 +491,98 @@ interface Foo {}
488491
```
489492

490493
:::
494+
495+
### nofunc
496+
497+
Examples of **incorrect** code for the `"nofunc"` option:
498+
499+
::: incorrect
500+
501+
```js
502+
/*eslint no-use-before-define: ["error", "nofunc"]*/
503+
504+
a();
505+
var a = function() {};
506+
507+
console.log(foo);
508+
var foo = 1;
509+
510+
function f() {
511+
return b;
512+
}
513+
var b = 1;
514+
515+
new A();
516+
class A {
517+
}
518+
519+
function g() {
520+
return new B();
521+
}
522+
class B {
523+
}
524+
525+
export default bar;
526+
const bar = 1;
527+
528+
export { baz };
529+
const baz = 1;
530+
```
531+
532+
:::
533+
534+
::: incorrect
535+
536+
```ts
537+
/*eslint no-use-before-define: ["error", "nofunc"]*/
538+
539+
function foo(): Foo {
540+
return Foo.FOO;
541+
}
542+
543+
enum Foo {
544+
FOO,
545+
}
546+
```
547+
548+
:::
549+
550+
Examples of **correct** code for the `"nofunc"` option:
551+
552+
::: correct
553+
554+
```js
555+
/*eslint no-use-before-define: ["error", "nofunc"]*/
556+
557+
f();
558+
function f() {}
559+
560+
class A {
561+
}
562+
new A();
563+
564+
var a = 10;
565+
alert(a);
566+
567+
const foo = 1;
568+
export { foo };
569+
570+
const bar = 1;
571+
export default bar;
572+
```
573+
574+
:::
575+
576+
::: correct
577+
578+
```ts
579+
/*eslint no-use-before-define: ["error", "nofunc"]*/
580+
581+
enum Foo {
582+
FOO,
583+
}
584+
585+
const foo = Foo.Foo;
586+
```
587+
588+
:::

0 commit comments

Comments
 (0)