|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
780 bytes
|
| Line | |
|---|
| 1 | # import/no-dynamic-require
|
|---|
| 2 |
|
|---|
| 3 | <!-- end auto-generated rule header -->
|
|---|
| 4 |
|
|---|
| 5 | The `require` method from CommonJS is used to import modules from different files. Unlike the ES6 `import` syntax, it can be given expressions that will be resolved at runtime. While this is sometimes necessary and useful, in most cases it isn't. Using expressions (for instance, concatenating a path and variable) as the argument makes it harder for tools to do static code analysis, or to find where in the codebase a module is used.
|
|---|
| 6 |
|
|---|
| 7 | This rule forbids every call to `require()` that uses expressions for the module name argument.
|
|---|
| 8 |
|
|---|
| 9 | ## Rule Details
|
|---|
| 10 |
|
|---|
| 11 | ### Fail
|
|---|
| 12 |
|
|---|
| 13 | ```js
|
|---|
| 14 | require(name);
|
|---|
| 15 | require('../' + name);
|
|---|
| 16 | require(`../${name}`);
|
|---|
| 17 | require(name());
|
|---|
| 18 | ```
|
|---|
| 19 |
|
|---|
| 20 | ### Pass
|
|---|
| 21 |
|
|---|
| 22 | ```js
|
|---|
| 23 | require('../name');
|
|---|
| 24 | require(`../name`);
|
|---|
| 25 | ```
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.