import-js/eslint-plugin-import

no-restricted-paths - absolute path expected where relative path is provided

Open

#1.890 aberto em 24 de ago. de 2020

Ver no GitHub
 (1 comment) (0 reactions) (0 assignees)JavaScript (1.540 forks)batch import
help wanted

Métricas do repositório

Stars
 (4.946 stars)
Métricas de merge de PR
 (Mesclagem média 5d 21h) (9 fundiu PRs em 30d)

Description

I am having trouble with the configuration for this rule and believe there is a bug in the way paths are resolved

// see https://github.com/benmosher/eslint-plugin-import/blob/master/src/rules/no-restricted-paths.js#L72
// it returns a relative path, are we sure thats what we want? 
const absoluteImportPath = resolve(importPath, context) 

Here we use resolve which comes from utils/resolve and it returns a relative path

https://github.com/benmosher/eslint-plugin-import/blob/569d72688fa6ae5c038c51eafa4f6016fc1ee802/utils/resolve.js#L220

should we be using path.resolve to return an absolute path instead? I am happy to open a PR with the change once confirmed

to be clear the change I am proposing is

- const absoluteImportPath = resolve(basePath, context)
+ const absoluteImportPath = path.resolve(basePath, importPath);

Guia do colaborador