1 | # `no-var-requires`
|
2 |
|
3 | Disallows the use of require statements except in import statements.
|
4 |
|
5 | In other words, the use of forms such as `var foo = require("foo")` are banned. Instead use ES6 style imports or `import foo = require("foo")` imports.
|
6 |
|
7 | ## Rule Details
|
8 |
|
9 | Examples of code for this rule:
|
10 |
|
11 |
|
12 |
|
13 | ### ❌ Incorrect
|
14 |
|
15 | ```ts
|
16 | var foo = require('foo');
|
17 | const foo = require('foo');
|
18 | let foo = require('foo');
|
19 | ```
|
20 |
|
21 | ### ✅ Correct
|
22 |
|
23 | ```ts
|
24 | import foo = require('foo');
|
25 | require('foo');
|
26 | import foo from 'foo';
|
27 | ```
|
28 |
|
29 | ## Options
|
30 |
|
31 | ```jsonc
|
32 | // .eslintrc.json
|
33 | {
|
34 | "rules": {
|
35 | "@typescript-eslint/no-var-requires": "error"
|
36 | }
|
37 | }
|
38 | ```
|
39 |
|
40 | This rule is not configurable.
|
41 |
|
42 | ## When Not To Use It
|
43 |
|
44 | If you don't care about TypeScript module syntax, then you will not need this rule.
|
45 |
|
46 | ## Related To
|
47 |
|
48 | - TSLint: [no-var-requires](https://palantir.github.io/tslint/rules/no-var-requires/)
|
49 |
|
50 | ## Attributes
|
51 |
|
52 | - Configs:
|
53 | - [x] ✅ Recommended
|
54 | - [x] 🔒 Strict
|
55 | - [ ] 🔧 Fixable
|
56 | - [ ] 💭 Requires type information
|