Skip to content

Commit 12971f5

Browse files
golopotljharb
authored andcommitted
[Fix] order: recognize ".." as a "parent" path
Fixes #1405.
1 parent 47f912e commit 12971f5

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
77
## [Unreleased]
88
### Fixed
99
- [`order`]: fix `isExternalModule` detect on windows ([#1651], thanks [@fisker])
10+
- [`order`]: recognize ".." as a "parent" path ([#1658], thanks [@golopot])
1011

1112
## [2.20.1] - 2020-02-01
1213
### Fixed
@@ -654,6 +655,7 @@ for info on changes for earlier releases.
654655

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

658+
[#1658]: https://github.com/benmosher/eslint-plugin-import/pull/1658
657659
[#1651]: https://github.com/benmosher/eslint-plugin-import/pull/1651
658660
[#1635]: https://github.com/benmosher/eslint-plugin-import/issues/1635
659661
[#1625]: https://github.com/benmosher/eslint-plugin-import/pull/1625

src/core/importType.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function isInternalModule(name, settings, path) {
6868
}
6969

7070
function isRelativeToParent(name) {
71-
return /^\.\.[\\/]/.test(name)
71+
return/^\.\.$|^\.\.[\\/]/.test(name)
7272
}
7373

7474
const indexFiles = ['.', './', './index', './index.js']

tests/src/rules/order.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ ruleTester.run('order', rule, {
1919
var relParent1 = require('../foo');
2020
var relParent2 = require('../foo/bar');
2121
var relParent3 = require('../');
22+
var relParent4 = require('..');
2223
var sibling = require('./foo');
2324
var index = require('./');`,
2425
}),
@@ -196,7 +197,13 @@ ruleTester.run('order', rule, {
196197
import { Input } from '-/components/Input';
197198
import { Button } from '-/components/Button';
198199
199-
import { add } from './helper';`,
200+
import p from '..';
201+
import q from '../';
202+
203+
import { add } from './helper';
204+
205+
import i from '.';
206+
import j from './';`,
200207
options: [
201208
{
202209
'newlines-between': 'always',
@@ -2002,6 +2009,25 @@ ruleTester.run('order', rule, {
20022009
message: '`foo` import should occur before import of `Bar`',
20032010
}],
20042011
}),
2012+
// Alphabetize with parent paths
2013+
test({
2014+
code: `
2015+
import a from '../a';
2016+
import p from '..';
2017+
`,
2018+
output: `
2019+
import p from '..';
2020+
import a from '../a';
2021+
`,
2022+
options: [{
2023+
groups: ['external', 'index'],
2024+
alphabetize: {order: 'asc'},
2025+
}],
2026+
errors: [{
2027+
ruleID: 'order',
2028+
message: '`..` import should occur before import of `../a`',
2029+
}],
2030+
}),
20052031
// Alphabetize with require
20062032
test({
20072033
code: `

0 commit comments

Comments
 (0)