Skip to content

Commit 41c6911

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[eslint] Enable import/sort rule
This provides consistency of how imports are order, reducing differences in authored files. Bug: none Change-Id: I45ddd71e3e0004aca32f101cb926101544a34157 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6218490 Commit-Queue: Nikolay Vitkov <[email protected]> Reviewed-by: Benedikt Meurer <[email protected]>
1 parent f3d916d commit 41c6911

File tree

283 files changed

+344
-407
lines changed

Some content is hidden

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

283 files changed

+344
-407
lines changed

eslint.config.mjs

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
// found in the LICENSE file.
44

55
/* eslint-disable import/no-default-export */
6+
7+
import stylisticPlugin from '@stylistic/eslint-plugin';
68
import typescriptPlugin from '@typescript-eslint/eslint-plugin';
7-
import mochaPlugin from 'eslint-plugin-mocha';
8-
import rulesdirPlugin from 'eslint-plugin-rulesdir';
9+
import tsParser from '@typescript-eslint/parser';
910
import importPlugin from 'eslint-plugin-import';
1011
import jsdocPlugin from 'eslint-plugin-jsdoc';
12+
import mochaPlugin from 'eslint-plugin-mocha';
13+
import rulesdirPlugin from 'eslint-plugin-rulesdir';
1114
import globals from 'globals';
12-
import tsParser from '@typescript-eslint/parser';
13-
import stylisticPlugin from '@stylistic/eslint-plugin';
1415
import { join } from 'path';
1516

1617
rulesdirPlugin.RULES_DIR = join(
@@ -259,6 +260,24 @@ export default [
259260
* import * as FooModule from './foo.js'
260261
**/
261262
'import/no-duplicates': 'error',
263+
/**
264+
* Provides more consistency in the imports.
265+
*/
266+
'import/order': [
267+
'error',
268+
{
269+
// We need to group the builtin and external as clang-format
270+
// can't differentiate the two
271+
groups: [['builtin', 'external'], 'parent', 'sibling', 'index'],
272+
'newlines-between': 'always',
273+
// clang-format has it's own logic overriding this
274+
named: false,
275+
alphabetize: {
276+
order: 'asc',
277+
caseInsensitive: true,
278+
},
279+
},
280+
],
262281
// Try to spot '// console.log()' left over from debugging
263282
'rulesdir/no-commented-out-console': 'error',
264283
// Prevent imports being commented out rather than deleted.
@@ -283,11 +302,11 @@ export default [
283302
parserOptions: {
284303
allowAutomaticSingleRunInference: true,
285304
project: join(
286-
import.meta.dirname,
287-
'config',
288-
'typescript',
289-
'tsconfig.eslint.json',
290-
),
305+
import.meta.dirname,
306+
'config',
307+
'typescript',
308+
'tsconfig.eslint.json',
309+
),
291310
},
292311
},
293312

@@ -476,12 +495,12 @@ export default [
476495
{
477496
// Enforce that any import of models/trace/trace.js names the import Trace.
478497
modulePath: join(
479-
import.meta.dirname,
480-
'front_end',
481-
'models',
482-
'trace',
483-
'trace.js',
484-
),
498+
import.meta.dirname,
499+
'front_end',
500+
'models',
501+
'trace',
502+
'trace.js',
503+
),
485504
importName: 'Trace',
486505
},
487506
],

front_end/Images/generate-css-vars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44
const path = require('path');
5+
56
const {writeIfChanged} = require('../../scripts/build/ninja/write-if-changed.js');
67
const [, , buildTimestamp, targetGenDir, targetName, ...imageSources] = process.argv;
78

front_end/core/common/Settings.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,14 +1396,14 @@ export function settingForTest(settingName: string): Setting<unknown> {
13961396
export {
13971397
getLocalizedSettingsCategory,
13981398
maybeRemoveSettingExtension,
1399-
registerSettingExtension,
14001399
RegExpSettingItem,
1400+
registerSettingExtension,
1401+
registerSettingsForTest,
1402+
resetSettings,
14011403
SettingCategory,
14021404
SettingExtensionOption,
14031405
SettingRegistration,
14041406
SettingType,
1405-
registerSettingsForTest,
1406-
resetSettings,
14071407
};
14081408

14091409
export interface Serializer<I, O> {

front_end/core/i18n/collect-ui-strings.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44

55
const glob = require('glob');
66
const path = require('path');
7+
const yargs = require('yargs');
78

9+
const {writeIfChanged} = require('../../../scripts/build/ninja/write-if-changed.js');
10+
const {bakePlaceholders} = require('../../../third_party/i18n/bake-ctc-to-lhl.js');
811
const {collectAllStringsInDir, createPsuedoLocaleStrings, IGNORED_PATH_COMPONENTS} =
912
require('../../../third_party/i18n/collect-strings.js');
10-
const {bakePlaceholders} = require('../../../third_party/i18n/bake-ctc-to-lhl.js');
11-
const {writeIfChanged} = require('../../../scripts/build/ninja/write-if-changed.js');
1213

1314
/** @typedef {import('../../../third_party/i18n/bake-ctc-to-lhl.js').CtcMessage} CtcMessage */
1415

15-
const yargsObject = require('yargs')
16+
const yargsObject = yargs
1617
.option('input-directories', {
1718
type: 'array',
1819
demandOption: true,
@@ -25,7 +26,7 @@ const yargsObject = require('yargs')
2526
type: 'boolean',
2627
})
2728
.strict()
28-
.argv;
29+
.parseSync();
2930

3031
/**
3132
* @param {string} outputDirectory

front_end/core/i18n/generate-locales-js.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
// found in the LICENSE file.
44

55
const path = require('path');
6+
const yargs = require('yargs');
7+
68
const {writeIfChanged} = require('../../../scripts/build/ninja/write-if-changed.js');
79

8-
const yargsObject = require('yargs')
10+
const yargsObject = yargs
911
.option('target-gen-dir', {
1012
type: 'string',
1113
demandOption: true,
@@ -31,7 +33,7 @@ const yargsObject = require('yargs')
3133
demandOption: true,
3234
})
3335
.strict()
34-
.argv;
36+
.parseSync();
3537

3638
const remoteLocaleList = yargsObject['remote-locales'].map(locale => `\n '${locale}',`).join('');
3739
const bundledLocaleList = yargsObject['bundled-locales'].map(locale => `\n '${locale}',`).join('');

front_end/core/protocol_client/InspectorBackend.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929
*/
3030

31-
import {NodeURL} from './NodeURL.js';
32-
import type * as Platform from '../platform/platform.js';
3331
import type * as ProtocolProxyApi from '../../generated/protocol-proxy-api.js';
3432
import type * as Protocol from '../../generated/protocol.js';
33+
import type * as Platform from '../platform/platform.js';
34+
35+
import {NodeURL} from './NodeURL.js';
3536

3637
export const DevToolsStubErrorCode = -32015;
3738
// TODO(dgozman): we are not reporting generic errors in tests, but we should

front_end/core/protocol_client/protocol_client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
import * as InspectorBackendCommands from '../../generated/InspectorBackendCommands.js';
6+
67
import * as InspectorBackend from './InspectorBackend.js';
78
import * as NodeURL from './NodeURL.js';
89

front_end/core/sdk/EmulationModel.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import * as Common from '../common/common.js';
65
import type * as ProtocolProxyApi from '../../generated/protocol-proxy-api.js';
76
import * as Protocol from '../../generated/protocol.js';
7+
import * as Common from '../common/common.js';
88

99
import {CSSModel} from './CSSModel.js';
1010
import {MultitargetNetworkManager} from './NetworkManager.js';
1111
import {Events, OverlayModel} from './OverlayModel.js';
12-
13-
import {Capability, type Target} from './Target.js';
1412
import {SDKModel} from './SDKModel.js';
13+
import {Capability, type Target} from './Target.js';
1514

1615
export class EmulationModel extends SDKModel<void> {
1716
readonly #emulationAgent: ProtocolProxyApi.EmulationApi;

front_end/core/sdk/IOModel.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import type * as Protocol from '../../generated/protocol.js';
56
import * as Common from '../common/common.js';
67

78
import {RemoteObject} from './RemoteObject.js';
8-
9-
import {Capability, type Target} from './Target.js';
109
import {SDKModel} from './SDKModel.js';
11-
import type * as Protocol from '../../generated/protocol.js';
10+
import {Capability, type Target} from './Target.js';
1211

1312
export class IOModel extends SDKModel<void> {
1413
constructor(target: Target) {

front_end/core/sdk/IssuesModel.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
import type * as ProtocolProxyApi from '../../generated/protocol-proxy-api.js';
66
import type * as Protocol from '../../generated/protocol.js';
77

8-
import {Capability, type Target} from './Target.js';
98
import {SDKModel} from './SDKModel.js';
9+
import {
10+
Capability,
11+
type Target,
12+
} from './Target.js';
1013

1114
/**
1215
* The `IssuesModel` is a thin dispatch that does not store issues, but only creates the representation

0 commit comments

Comments
 (0)