import-js / import-js/eslint-plugin-import

no-useless-path-segments rule only works with paths which name starts with "."

Open
#1,280 5 comments 6 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
5.9k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

Given the following folder structure:

```
project-root
├── .eslintrc.js
├── package.json
└── src
├── index.js
└── module.js
```

package.json contents:
```json
{
"devDependencies": {
"eslint": "^5.13.0",
"eslint-plugin-import": "^2.16.0"
},
"dependencies": {
"lodash": "^4.17.11"
}
}
```

.eslintrc contents:
```json
module.exports = {
"plugins": [
"import"
],
"rules": {
"import/no-useless-path-segments": "error"
},
"env": {
"browser": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"root": true
};
```

index.js contents:
```javascript
import sumBy from "lodash/sumBy"; //this is ok
import foo from ".//a.js"; // this is causing error
```

however the following examples don't cause the error:
```javascript
import sumBy from "lodash/////sumBy"; //too many slashes

import sumBy from "lodash/fn/../sumBy"; //should be "lodash/sumBy"

import sumBy from "lodash//fn/..//sumBy"; //should be "lodash/sumBy"

import foo from "src//a.js"; // absolute path, should be "src/a.js"

import foo from "src/bar/../a.js"; // absolute path, should be "src/a.js"
```

It might be due to the next code:
https://github.com/benmosher/eslint-plugin-import/blob/bdc05aa1d029b70125ae415e5ca5dca22250858b/src/rules/no-useless-path-segments.js#L70-L72

My expectation is that the rule should work for all imports, not only those starting with dot.

Contributor guide

Open the contributing guide

Research direction

Start with src/rules/no-useless-path-segments.js at the linked lines and trace how import paths are classified before normalization. Compare the rule's behavior against the examples in the issue, including bare and relative imports. Done means the rule consistently reports useless path segments for the stated import forms; add or update focused rule tests if the repository provides them.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.