Skip to content

Commit

Permalink
[fix] order: recognize ".." as a "parent" path
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot committed Feb 17, 2020
1 parent 2beec94 commit 6aa3c2c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/core/importType.js
Expand Up @@ -67,7 +67,7 @@ function isInternalModule(name, settings, path) {
}

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

const indexFiles = ['.', './', './index', './index.js']
Expand Down
30 changes: 28 additions & 2 deletions tests/src/rules/order.js
Expand Up @@ -3,7 +3,7 @@ import { test, getTSParsers } from '../utils'
import { RuleTester } from 'eslint'

const ruleTester = new RuleTester()
, rule = require('rules/order')
, rule = require('../../../src/rules/order')

function withoutAutofixOutput(test) {
return Object.assign({}, test, { output: test.code })
Expand All @@ -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 6aa3c2c

Please sign in to comment.