UNPKG

996 BMarkdownView Raw
1# `no-var-requires`
2
3Disallows the use of require statements except in import statements.
4
5In 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
9Examples of code for this rule:
10
11<!--tabs-->
12
13### ❌ Incorrect
14
15```ts
16var foo = require('foo');
17const foo = require('foo');
18let foo = require('foo');
19```
20
21### ✅ Correct
22
23```ts
24import foo = require('foo');
25require('foo');
26import 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
40This rule is not configurable.
41
42## When Not To Use It
43
44If 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