Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] order: recognize ".." as a "parent" path #1658

Merged
merged 1 commit into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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