Skip to content

Commit 16bdbf7

Browse files
committed
test(tests): account for different error handling behavior from different eslint versions
1 parent a3b96ab commit 16bdbf7

File tree

1 file changed

+68
-50
lines changed

1 file changed

+68
-50
lines changed

tests/src/rules/order.js

+68-50
Original file line numberDiff line numberDiff line change
@@ -5894,53 +5894,56 @@ context('TypeScript', function () {
58945894
},
58955895
],
58965896
}),
5897-
// Documentation failing example #1 for alphabetize
5898-
test({
5899-
code: `
5900-
import React, { PureComponent } from 'react';
5901-
import aTypes from 'prop-types';
5902-
import { compose, apply } from 'xcompose';
5903-
import * as classnames from 'classnames';
5904-
import blist2 from 'blist';
5905-
import blist from 'BList';
5906-
`,
5907-
// The reason why this output does not match the success example after being fixed is because eslint will leave overlapping errors alone, so only one import gets reordered when fixes are applied
5908-
output: `
5909-
import aTypes from 'prop-types';
5910-
import React, { PureComponent } from 'react';
5911-
import { compose, apply } from 'xcompose';
5912-
import * as classnames from 'classnames';
5913-
import blist2 from 'blist';
5914-
import blist from 'BList';
5915-
`,
5916-
...parserConfig,
5917-
options: [
5918-
{
5919-
alphabetize: {
5920-
order: 'asc',
5921-
caseInsensitive: true,
5897+
// Multiple errors
5898+
...semver.satisfies(eslintPkg.version, '< 3.0.0') ? [] : [
5899+
// Documentation failing example #1 for alphabetize
5900+
test({
5901+
code: `
5902+
import React, { PureComponent } from 'react';
5903+
import aTypes from 'prop-types';
5904+
import { compose, apply } from 'xcompose';
5905+
import * as classnames from 'classnames';
5906+
import blist2 from 'blist';
5907+
import blist from 'BList';
5908+
`,
5909+
// The reason why this output does not match the success example after being fixed is because eslint will leave overlapping errors alone, so only one import gets reordered when fixes are applied
5910+
output: `
5911+
import aTypes from 'prop-types';
5912+
import React, { PureComponent } from 'react';
5913+
import { compose, apply } from 'xcompose';
5914+
import * as classnames from 'classnames';
5915+
import blist2 from 'blist';
5916+
import blist from 'BList';
5917+
`,
5918+
...parserConfig,
5919+
options: [
5920+
{
5921+
alphabetize: {
5922+
order: 'asc',
5923+
caseInsensitive: true,
5924+
},
59225925
},
5923-
},
5924-
],
5925-
errors: [
5926-
{
5927-
message: '`prop-types` import should occur before import of `react`',
5928-
line: 3,
5929-
},
5930-
{
5931-
message: '`classnames` import should occur before import of `react`',
5932-
line: 5,
5933-
},
5934-
{
5935-
message: '`blist` import should occur before import of `react`',
5936-
line: 6,
5937-
},
5938-
{
5939-
message: '`BList` import should occur before import of `react`',
5940-
line: 7,
5941-
},
5942-
],
5943-
}),
5926+
],
5927+
errors: [
5928+
{
5929+
message: '`prop-types` import should occur before import of `react`',
5930+
line: 3,
5931+
},
5932+
{
5933+
message: '`classnames` import should occur before import of `react`',
5934+
line: 5,
5935+
},
5936+
{
5937+
message: '`blist` import should occur before import of `react`',
5938+
line: 6,
5939+
},
5940+
{
5941+
message: '`BList` import should occur before import of `react`',
5942+
line: 7,
5943+
},
5944+
],
5945+
}),
5946+
],
59445947
// Documentation failing example #1 for named
59455948
test({
59465949
code: `
@@ -5972,12 +5975,12 @@ context('TypeScript', function () {
59725975
import './styles.css';
59735976
import path from 'path';
59745977
`,
5975-
// Should not be fixed
5976-
output: `
5978+
// Should not be fixed (eslint@>=9 expects null)
5979+
output: semver.satisfies(eslintPkg.version, '< 9.0.0') ? `
59775980
import fs from 'fs';
59785981
import './styles.css';
59795982
import path from 'path';
5980-
`,
5983+
` : null,
59815984
...parserConfig,
59825985
options: [
59835986
{
@@ -6007,7 +6010,22 @@ context('TypeScript', function () {
60076010
import e from "./";
60086011
`,
60096012
// This is the "correct" behavior, but it's the wrong outcome (expectedly)
6010-
output: `
6013+
output: semver.satisfies(eslintPkg.version, '< 3.0.0')
6014+
// eslint@2 apparently attempts to fix multiple errors in one pass,
6015+
// which results in different erroneous output
6016+
? `
6017+
import type E from './';
6018+
import type A from "fs";
6019+
import type B from "path";
6020+
import type C from "../foo.js";
6021+
import type D from "./bar.js";
6022+
6023+
import a from "fs";
6024+
import b from "path";
6025+
import c from "../foo.js";
6026+
import d from "./bar.js";
6027+
import e from "./";
6028+
` : `
60116029
import type C from "../foo.js";
60126030
import type A from "fs";
60136031
import type B from "path";

0 commit comments

Comments
 (0)