web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.3 KiB

  1. # import/no-absolute-path: Forbid import of modules using absolute paths
  2. Node.js allows the import of modules using an absolute path such as `/home/xyz/file.js`. That is a bad practice as it ties the code using it to your computer, and therefore makes it unusable in packages distributed on `npm` for instance.
  3. ## Rule Details
  4. ### Fail
  5. ```js
  6. import f from '/foo';
  7. import f from '/some/path';
  8. var f = require('/foo');
  9. var f = require('/some/path');
  10. ```
  11. ### Pass
  12. ```js
  13. import _ from 'lodash';
  14. import foo from 'foo';
  15. import foo from './foo';
  16. var _ = require('lodash');
  17. var foo = require('foo');
  18. var foo = require('./foo');
  19. ```
  20. ### Options
  21. By default, only ES6 imports and CommonJS `require` calls will have this rule enforced.
  22. You may provide an options object providing true/false for any of
  23. - `esmodule`: defaults to `true`
  24. - `commonjs`: defaults to `true`
  25. - `amd`: defaults to `false`
  26. If `{ amd: true }` is provided, dependency paths for AMD-style `define` and `require`
  27. calls will be resolved:
  28. ```js
  29. /*eslint import/no-absolute-path: [2, { commonjs: false, amd: true }]*/
  30. define(['/foo'], function (foo) { /*...*/ }) // reported
  31. require(['/foo'], function (foo) { /*...*/ }) // reported
  32. const foo = require('/foo') // ignored because of explicit `commonjs: false`
  33. ```