Tim van der Lippe | fdbd42e | 2020-04-07 14:14:36 | [diff] [blame] | 1 | # import/no-nodejs-modules: No Node.js builtin modules |
| 2 | |
| 3 | Forbid the use of Node.js builtin modules. Can be useful for client-side web projects that do not have access to those modules. |
| 4 | |
| 5 | ### Options |
| 6 | |
| 7 | This rule supports the following options: |
| 8 | |
| 9 | - `allow`: Array of names of allowed modules. Defaults to an empty array. |
| 10 | |
| 11 | ## Rule Details |
| 12 | |
| 13 | ### Fail |
| 14 | |
| 15 | ```js |
| 16 | import fs from 'fs'; |
| 17 | import path from 'path'; |
| 18 | |
| 19 | var fs = require('fs'); |
| 20 | var path = require('path'); |
| 21 | ``` |
| 22 | |
| 23 | ### Pass |
| 24 | |
| 25 | ```js |
| 26 | import _ from 'lodash'; |
| 27 | import foo from 'foo'; |
| 28 | import foo from './foo'; |
| 29 | |
| 30 | var _ = require('lodash'); |
| 31 | var foo = require('foo'); |
| 32 | var foo = require('./foo'); |
| 33 | |
| 34 | /* eslint import/no-nodejs-modules: ["error", {"allow": ["path"]}] */ |
| 35 | import path from 'path'; |
| 36 | ``` |
| 37 | |
| 38 | ## When Not To Use It |
| 39 | |
| 40 | If you have a project that is run mainly or partially using Node.js. |