Skip to content

Commit 6f796f1

Browse files
authored
fix: sort imports (#84)
ipfs/eslint-config-ipfs#126 will introduce linting rules on import sorting so order imports during building in a way that will comply with the new linting rules.
1 parent 229afbc commit 6f796f1

23 files changed

+62
-38
lines changed

packages/protons-benchmark/src/decode.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ $ npx playwright-test dist/src/index.js --runner benchmark
66
*/
77

88
import Benchmark from 'benchmark'
9-
import { Test as ProtonsTest } from './protons/bench.js'
9+
1010
import { decodeTest as pbjsDecodeTest } from './pbjs/bench.js'
1111
import { Test as ProtobufjsTest } from './protobufjs/bench.js'
12+
import { Test as ProtonsTest } from './protons/bench.js'
1213

1314
const message = {
1415
meh: {

packages/protons-benchmark/src/encode.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ $ npx playwright-test dist/src/index.js --runner benchmark
66
*/
77

88
import Benchmark from 'benchmark'
9-
import { Test as ProtonsTest } from './protons/bench.js'
9+
1010
import { encodeTest as pbjsEncodeTest } from './pbjs/bench.js'
1111
import { Test as ProtobufjsTest } from './protobufjs/bench.js'
12+
import { Test as ProtonsTest } from './protons/bench.js'
1213

1314
const message = {
1415
meh: {

packages/protons-benchmark/src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ $ node dist/src/index.js
55
$ npx playwright-test dist/src/index.js --runner benchmark
66
*/
77

8-
import Benchmark from 'benchmark'
98
import { expect } from 'aegir/chai'
10-
import { Test as ProtonsTest } from './protons/bench.js'
9+
10+
import Benchmark from 'benchmark'
11+
1112
import { encodeTest as pbjsEncodeTest, decodeTest as pbjsDecodeTest } from './pbjs/bench.js'
12-
import { Test as ProtobufjsTest } from './protobufjs/bench.js'
1313
import { Test as ProtobufTsTest } from './protobuf-ts/bench.js'
14+
import { Test as ProtobufjsTest } from './protobufjs/bench.js'
15+
import { Test as ProtonsTest } from './protons/bench.js'
1416

1517
const message = {
1618
meh: {

packages/protons-benchmark/src/protons/bench.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
55

66
import { encodeMessage, decodeMessage, message, enumeration } from 'protons-runtime'
7-
import type { Uint8ArrayList } from 'uint8arraylist'
87
import type { Codec } from 'protons-runtime'
8+
import type { Uint8ArrayList } from 'uint8arraylist'
99

1010
export interface Foo {
1111
baz?: number

packages/protons-benchmark/src/protons/rpc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
55

66
import { encodeMessage, decodeMessage, message, writer } from 'protons-runtime'
7-
import type { Uint8ArrayList } from 'uint8arraylist'
87
import type { Codec } from 'protons-runtime'
8+
import type { Uint8ArrayList } from 'uint8arraylist'
99

1010
export interface RPC {
1111
subscriptions: RPC.SubOpts[]

packages/protons-benchmark/src/rpc.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ $ node dist/src/index.js
55
$ npx playwright-test dist/src/index.js --runner benchmark
66
*/
77

8+
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
9+
810
import Benchmark from 'benchmark'
9-
import { RPC as ProtonsRPC } from './protons/rpc.js'
11+
1012
import { RPC as ProtobufjsRPC } from './protobufjs/rpc.js'
11-
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
13+
import { RPC as ProtonsRPC } from './protons/rpc.js'
1214

1315
const rpc = {
1416
subscriptions: [],

packages/protons-runtime/src/decode.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Uint8ArrayList } from 'uint8arraylist'
2+
23
import type { Codec } from './codec.js'
34
import { reader } from './utils.js'
45

packages/protons-runtime/src/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import ReaderClass from 'protobufjs/src/reader.js'
33
// @ts-expect-error no types
44
import ReaderBufferClass from 'protobufjs/src/reader_buffer.js'
55
// @ts-expect-error no types
6+
import util from 'protobufjs/src/util/minimal.js'
7+
// @ts-expect-error no types
68
import WriterClass from 'protobufjs/src/writer.js'
79
// @ts-expect-error no types
810
import WriterBufferClass from 'protobufjs/src/writer_buffer.js'
9-
// @ts-expect-error no types
10-
import util from 'protobufjs/src/util/minimal.js'
11+
1112
import type { Reader, Writer } from './index.js'
1213

1314
function configure (): void {

packages/protons/bin/protons.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#! /usr/bin/env node
22

33
import meow from 'meow'
4+
45
import { generate } from '../src/index.js'
56

67
async function main (): Promise<void> {

packages/protons/src/index.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* eslint-disable max-depth */
22

3-
import { main as pbjs } from 'protobufjs-cli/pbjs.js'
3+
import fs from 'fs/promises'
44
import path from 'path'
55
import { promisify } from 'util'
6-
import fs from 'fs/promises'
6+
7+
import { main as pbjs } from 'protobufjs-cli/pbjs.js'
78

89
export enum CODEC_TYPES {
910
VARINT = 0,
@@ -697,29 +698,37 @@ export async function generate (source: string, flags: Flags): Promise<void> {
697698

698699
const moduleDef = defineModule(def)
699700

700-
let lines = [
701+
const ignores = [
701702
'/* eslint-disable import/export */',
702703
'/* eslint-disable complexity */',
703704
'/* eslint-disable @typescript-eslint/no-namespace */',
704705
'/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */',
705-
'/* eslint-disable @typescript-eslint/no-empty-interface */',
706-
''
706+
'/* eslint-disable @typescript-eslint/no-empty-interface */'
707707
]
708708

709+
const imports = []
710+
709711
if (moduleDef.imports.size > 0) {
710-
lines.push(`import { ${Array.from(moduleDef.imports).join(', ')} } from 'protons-runtime'`)
712+
imports.push(`import { ${Array.from(moduleDef.imports).join(', ')} } from 'protons-runtime'`)
711713
}
712714

713715
if (moduleDef.imports.has('encodeMessage')) {
714-
lines.push("import type { Uint8ArrayList } from 'uint8arraylist'")
716+
imports.push("import type { Uint8ArrayList } from 'uint8arraylist'")
715717
}
716718

717719
if (moduleDef.importedTypes.size > 0) {
718-
lines.push(`import type { ${Array.from(moduleDef.importedTypes).join(', ')} } from 'protons-runtime'`)
720+
imports.push(`import type { ${Array.from(moduleDef.importedTypes).join(', ')} } from 'protons-runtime'`)
719721
}
720722

721-
lines = [
722-
...lines,
723+
const lines = [
724+
...ignores,
725+
'',
726+
...imports.sort((a, b) => {
727+
const aModule = a.split("from '")[1].toString()
728+
const bModule = b.split("from '")[1].toString()
729+
730+
return aModule.localeCompare(bModule)
731+
}),
723732
'',
724733
...moduleDef.compiled
725734
]

packages/protons/test/fixtures/basic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/* eslint-disable @typescript-eslint/no-empty-interface */
66

77
import { encodeMessage, decodeMessage, message } from 'protons-runtime'
8-
import type { Uint8ArrayList } from 'uint8arraylist'
98
import type { Codec } from 'protons-runtime'
9+
import type { Uint8ArrayList } from 'uint8arraylist'
1010

1111
export interface Basic {
1212
foo?: string

packages/protons/test/fixtures/circuit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/* eslint-disable @typescript-eslint/no-empty-interface */
66

77
import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime'
8-
import type { Uint8ArrayList } from 'uint8arraylist'
98
import type { Codec } from 'protons-runtime'
9+
import type { Uint8ArrayList } from 'uint8arraylist'
1010

1111
export interface CircuitRelay {
1212
type?: CircuitRelay.Type

packages/protons/test/fixtures/daemon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/* eslint-disable @typescript-eslint/no-empty-interface */
66

77
import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime'
8-
import type { Uint8ArrayList } from 'uint8arraylist'
98
import type { Codec } from 'protons-runtime'
9+
import type { Uint8ArrayList } from 'uint8arraylist'
1010

1111
export interface Request {
1212
type: Request.Type

packages/protons/test/fixtures/dht.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/* eslint-disable @typescript-eslint/no-empty-interface */
66

77
import { encodeMessage, decodeMessage, message, enumeration } from 'protons-runtime'
8-
import type { Uint8ArrayList } from 'uint8arraylist'
98
import type { Codec } from 'protons-runtime'
9+
import type { Uint8ArrayList } from 'uint8arraylist'
1010

1111
export interface Record {
1212
key?: Uint8Array

packages/protons/test/fixtures/maps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/* eslint-disable @typescript-eslint/no-empty-interface */
66

77
import { encodeMessage, decodeMessage, message } from 'protons-runtime'
8-
import type { Uint8ArrayList } from 'uint8arraylist'
98
import type { Codec } from 'protons-runtime'
9+
import type { Uint8ArrayList } from 'uint8arraylist'
1010

1111
export interface SubMessage {
1212
foo: string

packages/protons/test/fixtures/noise.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/* eslint-disable @typescript-eslint/no-empty-interface */
66

77
import { encodeMessage, decodeMessage, message } from 'protons-runtime'
8-
import type { Uint8ArrayList } from 'uint8arraylist'
98
import type { Codec } from 'protons-runtime'
9+
import type { Uint8ArrayList } from 'uint8arraylist'
1010

1111
export interface pb {}
1212

packages/protons/test/fixtures/optional.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/* eslint-disable @typescript-eslint/no-empty-interface */
66

77
import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime'
8-
import type { Uint8ArrayList } from 'uint8arraylist'
98
import type { Codec } from 'protons-runtime'
9+
import type { Uint8ArrayList } from 'uint8arraylist'
1010

1111
export enum OptionalEnum {
1212
NO_VALUE = 'NO_VALUE',

packages/protons/test/fixtures/peer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/* eslint-disable @typescript-eslint/no-empty-interface */
66

77
import { encodeMessage, decodeMessage, message } from 'protons-runtime'
8-
import type { Uint8ArrayList } from 'uint8arraylist'
98
import type { Codec } from 'protons-runtime'
9+
import type { Uint8ArrayList } from 'uint8arraylist'
1010

1111
export interface Peer {
1212
addresses: Address[]

packages/protons/test/fixtures/singular.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/* eslint-disable @typescript-eslint/no-empty-interface */
66

77
import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime'
8-
import type { Uint8ArrayList } from 'uint8arraylist'
98
import type { Codec } from 'protons-runtime'
9+
import type { Uint8ArrayList } from 'uint8arraylist'
1010

1111
export enum SingularEnum {
1212
NO_VALUE = 'NO_VALUE',

packages/protons/test/fixtures/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/* eslint-disable @typescript-eslint/no-empty-interface */
66

77
import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime'
8-
import type { Uint8ArrayList } from 'uint8arraylist'
98
import type { Codec } from 'protons-runtime'
9+
import type { Uint8ArrayList } from 'uint8arraylist'
1010

1111
export enum AnEnum {
1212
HERP = 'HERP',

packages/protons/test/index.spec.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
/* eslint-env mocha */
22

3+
import fs from 'fs'
4+
35
import { expect } from 'aegir/chai'
6+
7+
import Long from 'long'
48
import pbjs from 'pbjs'
5-
import { Basic, Empty } from './fixtures/basic.js'
6-
import { AllTheTypes, AnEnum } from './fixtures/test.js'
7-
import fs from 'fs'
89
import protobufjs, { Type as PBType } from 'protobufjs'
9-
import { Peer } from './fixtures/peer.js'
10+
11+
import { Basic, Empty } from './fixtures/basic.js'
1012
import { CircuitRelay } from './fixtures/circuit.js'
11-
import Long from 'long'
1213
import { Optional, OptionalEnum } from './fixtures/optional.js'
14+
import { Peer } from './fixtures/peer.js'
1315
import { Singular, SingularEnum } from './fixtures/singular.js'
16+
import { AllTheTypes, AnEnum } from './fixtures/test.js'
1417

1518
function longifyBigInts (obj: any): any {
1619
const output = {

packages/protons/test/maps.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
/* eslint-env mocha */
22

33
import { expect } from 'aegir/chai'
4-
import { MapTypes, SubMessage } from './fixtures/maps.js'
5-
import protobufjs from 'protobufjs'
4+
65
import Long from 'long'
6+
import protobufjs from 'protobufjs'
7+
8+
import { MapTypes, SubMessage } from './fixtures/maps.js'
79

810
function longifyBigInts (obj: any): any {
911
const output = {

packages/protons/test/unsupported.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-env mocha */
22

33
import { expect } from 'aegir/chai'
4+
45
import { generate } from '../src/index.js'
56

67
describe('unsupported', () => {

0 commit comments

Comments
 (0)