Skip to content

Commit

Permalink
path.normalize sometimes . eg when there's only one .
Browse files Browse the repository at this point in the history
seems to not normalize trailing path seps.

./foo -> foo
./ -> ./
. -> .
.. -> ..
../ -> ../
  • Loading branch information
graingert committed Aug 8, 2017
1 parent fa304ad commit a3cc1af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"eslint-module-utils": "^2.1.1",
"has": "^1.0.1",
"lodash.cond": "^4.3.0",
"lodash.escaperegexp": "^4.1.2",
"lodash.sumby": "^4.3.0",
"minimatch": "^3.0.3",
"read-pkg-up": "^2.0.0"
Expand Down
7 changes: 6 additions & 1 deletion src/rules/no-useless-path-segments.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@

import path from 'path'
import sumBy from 'lodash.sumby'
import escapeRegExp from 'lodash.escaperegexp'
import resolve from 'eslint-module-utils/resolve'
import moduleVisitor from 'eslint-module-utils/moduleVisitor'

function toRel(rel, sep) {
return rel.startsWith(`..${sep}`) ? rel : `.${sep}${rel}`
const rSep = escapeRegExp(sep)
const stripped = rel.replace(new RegExp(`${rSep}$`, 'g'), '')
return stripped.match(new RegExp(`^((\\.\\.)|(\\.))($|${rSep})`)) ?
stripped :
`.${sep}${stripped}`
}

function normalize(fn, sep) {
Expand Down

0 comments on commit a3cc1af

Please sign in to comment.