Skip to content

Commit

Permalink
add fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pri1311 committed Mar 3, 2022
1 parent de52c4b commit b15d902
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
11 changes: 5 additions & 6 deletions src/rules/order.js
@@ -1,6 +1,5 @@
'use strict';

import { min } from 'lodash';
import minimatch from 'minimatch';
import importType from '../core/importType';
import isStaticRequire from '../core/staticRequire';
Expand Down Expand Up @@ -258,10 +257,10 @@ function getSorter(ascending) {
} else {
const A = importA.split('/');
const B = importB.split('/');
const a = A.length
const b = B.length
const a = A.length;
const b = B.length;

for (var i = 0; i < min([a, b]); i++) {
for (let i = 0; i < Math.min(a, b); i++) {
if (A[i] < B[i]) {
result = -1;
break;
Expand All @@ -271,8 +270,8 @@ function getSorter(ascending) {
}
}

if (!result && a != b) {
result = a < b ? -1 : 1
if (!result && a !== b) {
result = a < b ? -1 : 1;
}
}

Expand Down
20 changes: 10 additions & 10 deletions tests/src/rules/order.js
Expand Up @@ -683,8 +683,8 @@ ruleTester.run('order', rule, {
import d from "foo/barfoo";
import b from "foo-bar";`,
options: [{
alphabetize: { order: 'asc' },
}],
alphabetize: { order: 'asc' },
}],
}),
// Option alphabetize: {order: 'asc'} and move nested import entries closer to the main import entry
test({
Expand All @@ -694,8 +694,8 @@ ruleTester.run('order', rule, {
import d from "foo/foobar/barfoo";
import b from "foo-bar";`,
options: [{
alphabetize: { order: 'asc' },
}],
alphabetize: { order: 'asc' },
}],
}),
// Option alphabetize: {order: 'desc'} and move nested import entries closer to the main import entry
test({
Expand All @@ -705,8 +705,8 @@ ruleTester.run('order', rule, {
import c from "foo/bar";
import a from "foo";`,
options: [{
alphabetize: { order: 'desc' },
}],
alphabetize: { order: 'desc' },
}],
}),
// Option alphabetize with newlines-between: {order: 'asc', newlines-between: 'always'}
test({
Expand Down Expand Up @@ -2272,17 +2272,17 @@ ruleTester.run('order', rule, {
import d from "foo/barfoo";
`,
options: [{
alphabetize: { order: 'asc' },
alphabetize: { order: 'asc' },
}],
output: `
import a from "foo";
import c from "foo/bar";
import d from "foo/barfoo";
import b from "foo-bar";
`,
errors: [
{ message: '`foo-bar` import should occur after import of `foo/barfoo`'}
]
errors: [{
message: '`foo-bar` import should occur after import of `foo/barfoo`',
},]
}),
// Option alphabetize {order: 'asc': caseInsensitive: true}
test({
Expand Down

0 comments on commit b15d902

Please sign in to comment.