no-absolute-path
Added in v0.9.4Configuration
Rule Details
Disallow absolute module paths, which tie imports to a particular filesystem
layout. The rule checks imports, re-exports, dynamic imports, and direct
require() calls with string literals.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
The automatic fix replaces the absolute path with a double-quoted path relative
to the importing file. Like upstream, absolute-path detection follows the host
platform: paths starting with / are absolute on all platforms, while Windows
drive paths such as C:/project/lib/value.js are only reported on Windows.
Fixes use / as the path separator on all platforms.
Options
The rule accepts one object:
For example, { "commonjs": false, "amd": true } checks AMD dependencies while
ignoring CommonJS calls:
For example, { "ignore": ["^/generated/"] } allows absolute paths beginning
with /generated/. Patterns are case-sensitive and match the decoded path,
including any escaped characters. When specified, ignore must contain at
least one pattern, without duplicate entries.
Differences from upstream
- Automatic fixes escape
<,>,&, U+2028, and U+2029. For example, a path containing<a>becomes"./\u003ca\u003e"instead of"./<a>". The fixed paths have the same JavaScript value and refer to the same module. - Fixes for names beginning with a dot include the relative-path prefix. For
example, importing
/project/.hidden.jsfrom/project/index.jsbecomes"./.hidden.js". Upstream produces".hidden.js", which module loaders can interpret as a package name and fail to load. - Some
ignorecharacter ranges containing emoji are rejected. For example, use"[\\ud83d\\ude00-\\uFFFF]"instead of"[😀-\\uFFFF]"; upstream accepts both with the same matching behavior. ignorerejects named capture groups reused across separate alternatives. For example,"(?:(?<x>/foo)|(?<x>/bar))"is rejected. Use"(?<x>/foo|/bar)"to ignore the same paths. Upstream accepts the former when its JavaScript runtime supports duplicate named capture groups.