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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
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
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
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