Skip to content

Commit

Permalink
[Fix] order: recognize ".." as a "parent" path
Browse files Browse the repository at this point in the history
Fixes #1405.
  • Loading branch information
golopot authored and ljharb committed Feb 17, 2020
1 parent 47f912e commit 12971f5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
## [Unreleased]
### Fixed
- [`order`]: fix `isExternalModule` detect on windows ([#1651], thanks [@fisker])
- [`order`]: recognize ".." as a "parent" path ([#1658], thanks [@golopot])

## [2.20.1] - 2020-02-01
### Fixed
Expand Down Expand Up @@ -654,6 +655,7 @@ for info on changes for earlier releases.

[`memo-parser`]: ./memo-parser/README.md

[#1658]: https://github.com/benmosher/eslint-plugin-import/pull/1658
[#1651]: https://github.com/benmosher/eslint-plugin-import/pull/1651
[#1635]: https://github.com/benmosher/eslint-plugin-import/issues/1635
[#1625]: https://github.com/benmosher/eslint-plugin-import/pull/1625
Expand Down
2 changes: 1 addition & 1 deletion src/core/importType.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function isInternalModule(name, settings, path) {
}

function isRelativeToParent(name) {
return /^\.\.[\\/]/.test(name)
return/^\.\.$|^\.\.[\\/]/.test(name)
}

const indexFiles = ['.', './', './index', './index.js']
Expand Down
28 changes: 27 additions & 1 deletion tests/src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ruleTester.run('order', rule, {
var relParent1 = require('../foo');
var relParent2 = require('../foo/bar');
var relParent3 = require('../');
var relParent4 = require('..');
var sibling = require('./foo');
var index = require('./');`,
}),
Expand Down Expand Up @@ -196,7 +197,13 @@ ruleTester.run('order', rule, {
import { Input } from '-/components/Input';
import { Button } from '-/components/Button';
import { add } from './helper';`,
import p from '..';
import q from '../';
import { add } from './helper';
import i from '.';
import j from './';`,
options: [
{
'newlines-between': 'always',
Expand Down Expand Up @@ -2002,6 +2009,25 @@ ruleTester.run('order', rule, {
message: '`foo` import should occur before import of `Bar`',
}],
}),
// Alphabetize with parent paths
test({
code: `
import a from '../a';
import p from '..';
`,
output: `
import p from '..';
import a from '../a';
`,
options: [{
groups: ['external', 'index'],
alphabetize: {order: 'asc'},
}],
errors: [{
ruleID: 'order',
message: '`..` import should occur before import of `../a`',
}],
}),
// Alphabetize with require
test({
code: `
Expand Down

0 comments on commit 12971f5

Please sign in to comment.