Skip to content

Commit f9132f9

Browse files
authored
chore: sort imports alphabetically (#10757)
1 parent 95169d3 commit f9132f9

File tree

310 files changed

+602
-663
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

310 files changed

+602
-663
lines changed

.eslintrc.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
const {sync: readPkg} = require('read-pkg');
9+
const {getPackages} = require('./scripts/buildUtils');
10+
11+
const internalPackages = getPackages()
12+
.map(packageDir => {
13+
const pkg = readPkg({cwd: packageDir});
14+
15+
return pkg.name;
16+
})
17+
.sort();
18+
819
module.exports = {
920
extends: [
1021
'fb-strict',
@@ -243,11 +254,29 @@ module.exports = {
243254
'scripts/**',
244255
'babel.config.js',
245256
'testSetupFile.js',
257+
'.eslintrc.js',
246258
],
247259
},
248260
],
249261
'import/no-unresolved': ['error', {ignore: ['fsevents']}],
250-
'import/order': 'error',
262+
'import/order': [
263+
'error',
264+
{
265+
alphabetize: {
266+
order: 'asc',
267+
},
268+
// this is the default order except for added `internal` in the middle
269+
groups: [
270+
'builtin',
271+
'external',
272+
'internal',
273+
'parent',
274+
'sibling',
275+
'index',
276+
],
277+
'newlines-between': 'never',
278+
},
279+
],
251280
'no-console': 'off',
252281
'no-restricted-imports': [
253282
'error',
@@ -262,5 +291,9 @@ module.exports = {
262291
},
263292
settings: {
264293
'import/ignore': ['react-native'],
294+
// using `new RegExp` makes sure to escape `/`
295+
'import/internal-regex': new RegExp(
296+
internalPackages.map(pkg => `^${pkg}$`).join('|'),
297+
).source,
265298
},
266299
};

docs/BypassingModuleMocks.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ Your test will want to mock the `fetch` function so that we can be sure that it
2424
jest.mock('node-fetch');
2525

2626
import fetch, {Response} from 'node-fetch';
27-
2827
import {createUser} from './createUser';
2928

3029
test('createUser calls fetch with the right args and returns the user id', async () => {

docs/Configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ Default: `undefined`
300300
This option allows the use of a custom dependency extractor. It must be a node module that exports an object with an `extract` function. E.g.:
301301

302302
```javascript
303-
const fs = require('fs');
304303
const crypto = require('crypto');
304+
const fs = require('fs');
305305

306306
module.exports = {
307307
extract(code, filePath, defaultExtract) {

docs/Es6ClassMocks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ Here's a complete test file which uses the module factory parameter to `jest.moc
328328

329329
```javascript
330330
// sound-player-consumer.test.js
331-
import SoundPlayerConsumer from './sound-player-consumer';
332331
import SoundPlayer from './sound-player';
332+
import SoundPlayerConsumer from './sound-player-consumer';
333333

334334
const mockPlaySoundFile = jest.fn();
335335
jest.mock('./sound-player', () => {

docs/JestObjectAPI.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ module.exports = audio;
538538
Example test:
539539

540540
```js
541+
const audio = require('./audio');
541542
const video = require('./video');
542543

543544
test('plays video', () => {
@@ -550,8 +551,6 @@ test('plays video', () => {
550551
spy.mockRestore();
551552
});
552553

553-
const audio = require('./audio');
554-
555554
test('plays audio', () => {
556555
const spy = jest.spyOn(audio, 'volume', 'set'); // we pass 'set'
557556
audio.volume = 100;

docs/Puppeteer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ Here's an example of the GlobalSetup script
5555

5656
```js
5757
// setup.js
58-
const path = require('path');
5958
const fs = require('fs');
6059
const os = require('os');
60+
const path = require('path');
6161
const mkdirp = require('mkdirp');
6262
const puppeteer = require('puppeteer');
6363

@@ -80,8 +80,8 @@ Then we need a custom Test Environment for puppeteer
8080
```js
8181
// puppeteer_environment.js
8282
const fs = require('fs');
83-
const path = require('path');
8483
const os = require('os');
84+
const path = require('path');
8585
const puppeteer = require('puppeteer');
8686
const NodeEnvironment = require('jest-environment-node');
8787

e2e/Utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
*/
77

88
import * as path from 'path';
9-
import * as fs from 'graceful-fs';
10-
import type {Config} from '@jest/types';
9+
import dedent = require('dedent');
1110
import {ExecaReturnValue, sync as spawnSync} from 'execa';
12-
import type {PackageJson} from 'type-fest';
11+
import * as fs from 'graceful-fs';
1312
import rimraf = require('rimraf');
14-
import dedent = require('dedent');
13+
import type {PackageJson} from 'type-fest';
1514
import which = require('which');
15+
import type {Config} from '@jest/types';
1616

1717
interface RunResult extends ExecaReturnValue {
1818
status: number;

e2e/__tests__/asyncAndCallback.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import {skipSuiteOnJasmine} from '@jest/test-utils';
98
import wrap from 'jest-snapshot-serializer-raw';
10-
import runJest from '../runJest';
9+
import {skipSuiteOnJasmine} from '@jest/test-utils';
1110
import {extractSummary} from '../Utils';
11+
import runJest from '../runJest';
1212

1313
skipSuiteOnJasmine();
1414

e2e/__tests__/babelPluginJestHoist.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
*/
77

88
import * as path from 'path';
9-
import {json as runWithJson} from '../runJest';
109
import {runYarn} from '../Utils';
10+
import {json as runWithJson} from '../runJest';
1111

1212
const DIR = path.resolve(__dirname, '..', 'babel-plugin-jest-hoist');
1313

e2e/__tests__/beforeEachQueue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import {skipSuiteOnJestCircus} from '@jest/test-utils';
98
import {wrap} from 'jest-snapshot-serializer-raw';
9+
import {skipSuiteOnJestCircus} from '@jest/test-utils';
1010
import runJest from '../runJest';
1111

1212
skipSuiteOnJestCircus(); // Circus does not support funky async definitions

e2e/__tests__/chaiAssertionLibrary.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import * as path from 'path';
99
import {wrap} from 'jest-snapshot-serializer-raw';
10-
import runJest from '../runJest';
1110
import {extractSummary, runYarn} from '../Utils';
11+
import runJest from '../runJest';
1212

1313
test('chai assertion errors should display properly', () => {
1414
const dir = path.resolve(__dirname, '../chai-assertion-library-errors');

e2e/__tests__/circusDeclarationErrors.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import {skipSuiteOnJasmine} from '@jest/test-utils';
98
import {wrap} from 'jest-snapshot-serializer-raw';
9+
import {skipSuiteOnJasmine} from '@jest/test-utils';
1010
import {extractSummary} from '../Utils';
1111
import runJest from '../runJest';
1212

e2e/__tests__/customMatcherStackTrace.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
*/
77

88
import {wrap} from 'jest-snapshot-serializer-raw';
9-
import runJest from '../runJest';
109
import {extractSummary} from '../Utils';
10+
import runJest from '../runJest';
1111

1212
test('works with custom matchers', () => {
1313
const {stderr} = runJest('custom-matcher-stack-trace', ['sync.test.js']);

e2e/__tests__/customReporters.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import {tmpdir} from 'os';
99
import * as path from 'path';
1010
import {wrap} from 'jest-snapshot-serializer-raw';
11-
import runJest from '../runJest';
1211
import {cleanup, extractSummary, writeFiles} from '../Utils';
12+
import runJest from '../runJest';
1313

1414
const DIR = path.resolve(tmpdir(), 'custom-reporters-test-dir');
1515

e2e/__tests__/customTestSequencers.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
*/
77

88
import * as path from 'path';
9-
import runJest from '../runJest';
109
import {extractSummary} from '../Utils';
10+
import runJest from '../runJest';
1111
const dir = path.resolve(__dirname, '../custom-test-sequencer');
1212

1313
test('run prioritySequence first sync', () => {

e2e/__tests__/dependencyClash.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import * as path from 'path';
98
import {tmpdir} from 'os';
9+
import * as path from 'path';
1010
import {cleanup, createEmptyPackage, writeFiles} from '../Utils';
1111
import runJest from '../runJest';
1212

e2e/__tests__/domDiffing.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
*
77
*/
88

9-
import runJest from '../runJest';
109
import {replaceTime} from '../Utils';
10+
import runJest from '../runJest';
1111

1212
test('should work without error', () => {
1313
const output = runJest('dom-diffing');

e2e/__tests__/each.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import * as path from 'path';
99
import {wrap} from 'jest-snapshot-serializer-raw';
10-
import runJest from '../runJest';
1110
import {extractSummary} from '../Utils';
11+
import runJest from '../runJest';
1212

1313
const dir = path.resolve(__dirname, '../each');
1414

e2e/__tests__/emptyDescribeWithHooks.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import * as path from 'path';
99
import {skipSuiteOnJasmine} from '@jest/test-utils';
10-
import runJest from '../runJest';
1110
import {extractSummary} from '../Utils';
11+
import runJest from '../runJest';
1212

1313
const dir = path.resolve(__dirname, '../empty-describe-with-hooks');
1414

e2e/__tests__/errorOnDeprecated.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import {wrap} from 'jest-snapshot-serializer-raw';
99
import {skipSuiteOnJestCircus} from '@jest/test-utils';
10-
import runJest from '../runJest';
1110
import {extractSummary} from '../Utils';
11+
import runJest from '../runJest';
1212

1313
skipSuiteOnJestCircus();
1414

e2e/__tests__/existentRoots.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import * as path from 'path';
98
import {tmpdir} from 'os';
9+
import * as path from 'path';
1010
import {tryRealpath} from 'jest-util';
1111
import {cleanup, writeFiles} from '../Utils';
1212
import runJest from '../runJest';

e2e/__tests__/expectAsyncMatcher.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import * as path from 'path';
99
import {wrap} from 'jest-snapshot-serializer-raw';
10-
import runJest from '../runJest';
1110
import {extractSummary, runYarn} from '../Utils';
11+
import runJest from '../runJest';
1212

1313
const dir = path.resolve(__dirname, '../expect-async-matcher');
1414

e2e/__tests__/fatalWorkerError.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import * as path from 'path';
98
import {tmpdir} from 'os';
9+
import * as path from 'path';
1010
import {
1111
cleanup,
1212
generateTestFilesToForceUsingWorkers,

e2e/__tests__/forceExit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import {tmpdir} from 'os';
99
import * as path from 'path';
10-
import runJest from '../runJest';
1110
import {cleanup, writeFiles} from '../Utils';
11+
import runJest from '../runJest';
1212

1313
const DIR = path.resolve(tmpdir(), 'force-exit-test');
1414

e2e/__tests__/globalSetup.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import {tmpdir} from 'os';
99
import * as path from 'path';
1010
import * as fs from 'graceful-fs';
11-
import runJest, {json as runWithJson} from '../runJest';
1211
import {cleanup, runYarn} from '../Utils';
12+
import runJest, {json as runWithJson} from '../runJest';
1313

1414
const DIR = path.join(tmpdir(), 'jest-global-setup');
1515
const project1DIR = path.join(tmpdir(), 'jest-global-setup-project-1');

e2e/__tests__/globalTeardown.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {tmpdir} from 'os';
99
import * as path from 'path';
1010
import * as fs from 'graceful-fs';
1111
import {createDirectory} from 'jest-util';
12-
import runJest, {json as runWithJson} from '../runJest';
1312
import {cleanup, runYarn} from '../Utils';
13+
import runJest, {json as runWithJson} from '../runJest';
1414

1515
const DIR = path.join(tmpdir(), 'jest-global-teardown');
1616
const project1DIR = path.join(tmpdir(), 'jest-global-teardown-project-1');

e2e/__tests__/globals.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import * as path from 'path';
98
import {tmpdir} from 'os';
9+
import * as path from 'path';
1010
import {wrap} from 'jest-snapshot-serializer-raw';
11-
import runJest from '../runJest';
1211
import {
1312
cleanup,
1413
createEmptyPackage,
1514
extractSummary,
1615
writeFiles,
1716
} from '../Utils';
17+
import runJest from '../runJest';
1818

1919
const DIR = path.resolve(tmpdir(), 'globalVariables.test');
2020
const TEST_DIR = path.resolve(DIR, '__tests__');

e2e/__tests__/injectGlobals.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import * as path from 'path';
98
import {tmpdir} from 'os';
9+
import * as path from 'path';
1010
import {wrap} from 'jest-snapshot-serializer-raw';
1111
import {skipSuiteOnJasmine} from '@jest/test-utils';
12-
import {json as runJest} from '../runJest';
1312
import {
1413
cleanup,
1514
createEmptyPackage,
1615
extractSummary,
1716
writeFiles,
1817
} from '../Utils';
18+
import {json as runJest} from '../runJest';
1919

2020
const DIR = path.resolve(tmpdir(), 'injectGlobalVariables.test');
2121
const TEST_DIR = path.resolve(DIR, '__tests__');

e2e/__tests__/jest.config.js.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import * as path from 'path';
99
import {wrap} from 'jest-snapshot-serializer-raw';
10-
import runJest from '../runJest';
1110
import {cleanup, extractSummary, writeFiles} from '../Utils';
11+
import runJest from '../runJest';
1212

1313
const DIR = path.resolve(__dirname, '../jest-config-js');
1414

e2e/__tests__/jest.config.ts.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import * as path from 'path';
99
import {wrap} from 'jest-snapshot-serializer-raw';
10-
import runJest from '../runJest';
1110
import {cleanup, extractSummary, writeFiles} from '../Utils';
11+
import runJest from '../runJest';
1212

1313
const DIR = path.resolve(__dirname, '../jest-config-ts');
1414

0 commit comments

Comments
 (0)