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

0 commit comments

Comments
 (0)