no-relative-parent-imports
Added in v0.9.4Configuration
Rule Details
Disallow imports whose resolved file is in a parent directory. The rule checks
static imports, re-exports and dynamic import() calls, including type-only
imports and exports. Unresolved paths and external packages are ignored.
Paths are checked after resolution, so ./../main.js and aliases that resolve
to a parent file can also be reported.
Examples of incorrect code for this rule in lib/example.js:
Examples of correct code for this rule:
Move the importing file, pass the dependency as a function argument, or expose it as a package. The rule does not provide automatic fixes or suggestions.
Options
If provided, ignore must contain at least one pattern, with no duplicates.
It is separate from settings['import/ignore'], which does not exempt imports
from this rule.
This configuration also checks CommonJS imports and allows parent imports from
generated:
Resolution settings
Set import/resolver to node or typescript. Their full names,
eslint-import-resolver-node and eslint-import-resolver-typescript, are also
accepted. The default Node resolver supports JavaScript and JSON paths; use
typescript for TypeScript paths and aliases. import/core-modules,
import/internal-regex and import/external-module-folders also affect which
imports are reported.
Differences from upstream
- If your ESLint configuration uses
webpackor another custom resolver, rslint reports a resolver error for imports checked by this rule. Usenode, or usetypescriptwith matchingpathsintsconfig.jsonfor aliases. The rule'signoreoption can exclude imports you do not want to check. - To select a TypeScript project, use
languageOptions.parserOptions.project. Settingimport/resolverto{ typescript: { project: 'tsconfig.app.json' } }does not select that project in rslint. Other TypeScript resolver options, includingalwaysTryTypes, also have no effect, so imports may resolve differently from ESLint. - When configuring multiple resolvers, use an array such as
['typescript', 'node']to set their priority. Object configurations are tried alphabetically in rslint:{ typescript: {}, node: {} }triesnodefirst, whereas ESLint triestypescriptfirst. This can change the resolved file and whether the import is reported. - Babel's experimental
export value from './module'syntax is not supported. Useexport { default as value } from './module'instead.