From 17833b8c9498efa32773c83f592162f57834bc6a Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 1 Feb 2023 14:53:45 +0100 Subject: [PATCH] fix: sort imports https://github.com/ipfs/eslint-config-ipfs/pull/126 will introduce linting rules on import sorting so order imports during building in a way that will comply with the new linting rules. --- packages/protons-benchmark/src/decode.ts | 3 +- packages/protons-benchmark/src/encode.ts | 3 +- packages/protons-benchmark/src/index.ts | 8 +++-- .../protons-benchmark/src/protons/bench.ts | 2 +- packages/protons-benchmark/src/protons/rpc.ts | 2 +- packages/protons-benchmark/src/rpc.ts | 6 ++-- packages/protons-runtime/src/decode.ts | 1 + packages/protons-runtime/src/utils.ts | 5 ++-- packages/protons/bin/protons.ts | 1 + packages/protons/src/index.ts | 29 ++++++++++++------- packages/protons/test/fixtures/basic.ts | 2 +- packages/protons/test/fixtures/circuit.ts | 2 +- packages/protons/test/fixtures/daemon.ts | 2 +- packages/protons/test/fixtures/dht.ts | 2 +- packages/protons/test/fixtures/maps.ts | 2 +- packages/protons/test/fixtures/noise.ts | 2 +- packages/protons/test/fixtures/optional.ts | 2 +- packages/protons/test/fixtures/peer.ts | 2 +- packages/protons/test/fixtures/singular.ts | 2 +- packages/protons/test/fixtures/test.ts | 2 +- packages/protons/test/index.spec.ts | 13 +++++---- packages/protons/test/maps.spec.ts | 6 ++-- packages/protons/test/unsupported.spec.ts | 1 + 23 files changed, 62 insertions(+), 38 deletions(-) diff --git a/packages/protons-benchmark/src/decode.ts b/packages/protons-benchmark/src/decode.ts index 271068f..cdd798d 100644 --- a/packages/protons-benchmark/src/decode.ts +++ b/packages/protons-benchmark/src/decode.ts @@ -6,9 +6,10 @@ $ npx playwright-test dist/src/index.js --runner benchmark */ import Benchmark from 'benchmark' -import { Test as ProtonsTest } from './protons/bench.js' + import { decodeTest as pbjsDecodeTest } from './pbjs/bench.js' import { Test as ProtobufjsTest } from './protobufjs/bench.js' +import { Test as ProtonsTest } from './protons/bench.js' const message = { meh: { diff --git a/packages/protons-benchmark/src/encode.ts b/packages/protons-benchmark/src/encode.ts index 68fb964..119a01a 100644 --- a/packages/protons-benchmark/src/encode.ts +++ b/packages/protons-benchmark/src/encode.ts @@ -6,9 +6,10 @@ $ npx playwright-test dist/src/index.js --runner benchmark */ import Benchmark from 'benchmark' -import { Test as ProtonsTest } from './protons/bench.js' + import { encodeTest as pbjsEncodeTest } from './pbjs/bench.js' import { Test as ProtobufjsTest } from './protobufjs/bench.js' +import { Test as ProtonsTest } from './protons/bench.js' const message = { meh: { diff --git a/packages/protons-benchmark/src/index.ts b/packages/protons-benchmark/src/index.ts index ef2fb16..760d892 100644 --- a/packages/protons-benchmark/src/index.ts +++ b/packages/protons-benchmark/src/index.ts @@ -5,12 +5,14 @@ $ node dist/src/index.js $ npx playwright-test dist/src/index.js --runner benchmark */ -import Benchmark from 'benchmark' import { expect } from 'aegir/chai' -import { Test as ProtonsTest } from './protons/bench.js' + +import Benchmark from 'benchmark' + import { encodeTest as pbjsEncodeTest, decodeTest as pbjsDecodeTest } from './pbjs/bench.js' -import { Test as ProtobufjsTest } from './protobufjs/bench.js' import { Test as ProtobufTsTest } from './protobuf-ts/bench.js' +import { Test as ProtobufjsTest } from './protobufjs/bench.js' +import { Test as ProtonsTest } from './protons/bench.js' const message = { meh: { diff --git a/packages/protons-benchmark/src/protons/bench.ts b/packages/protons-benchmark/src/protons/bench.ts index 8347fd5..5353cdb 100644 --- a/packages/protons-benchmark/src/protons/bench.ts +++ b/packages/protons-benchmark/src/protons/bench.ts @@ -4,8 +4,8 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ import { encodeMessage, decodeMessage, message, enumeration } from 'protons-runtime' -import type { Uint8ArrayList } from 'uint8arraylist' import type { Codec } from 'protons-runtime' +import type { Uint8ArrayList } from 'uint8arraylist' export interface Foo { baz?: number diff --git a/packages/protons-benchmark/src/protons/rpc.ts b/packages/protons-benchmark/src/protons/rpc.ts index 75781fd..2d60349 100644 --- a/packages/protons-benchmark/src/protons/rpc.ts +++ b/packages/protons-benchmark/src/protons/rpc.ts @@ -4,8 +4,8 @@ /* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */ import { encodeMessage, decodeMessage, message, writer } from 'protons-runtime' -import type { Uint8ArrayList } from 'uint8arraylist' import type { Codec } from 'protons-runtime' +import type { Uint8ArrayList } from 'uint8arraylist' export interface RPC { subscriptions: RPC.SubOpts[] diff --git a/packages/protons-benchmark/src/rpc.ts b/packages/protons-benchmark/src/rpc.ts index 1cd33cf..fa9dc5e 100644 --- a/packages/protons-benchmark/src/rpc.ts +++ b/packages/protons-benchmark/src/rpc.ts @@ -5,10 +5,12 @@ $ node dist/src/index.js $ npx playwright-test dist/src/index.js --runner benchmark */ +import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' + import Benchmark from 'benchmark' -import { RPC as ProtonsRPC } from './protons/rpc.js' + import { RPC as ProtobufjsRPC } from './protobufjs/rpc.js' -import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' +import { RPC as ProtonsRPC } from './protons/rpc.js' const rpc = { subscriptions: [], diff --git a/packages/protons-runtime/src/decode.ts b/packages/protons-runtime/src/decode.ts index 3d9356b..bd395ac 100644 --- a/packages/protons-runtime/src/decode.ts +++ b/packages/protons-runtime/src/decode.ts @@ -1,4 +1,5 @@ import type { Uint8ArrayList } from 'uint8arraylist' + import type { Codec } from './codec.js' import { reader } from './utils.js' diff --git a/packages/protons-runtime/src/utils.ts b/packages/protons-runtime/src/utils.ts index 9c75ba2..d125d64 100644 --- a/packages/protons-runtime/src/utils.ts +++ b/packages/protons-runtime/src/utils.ts @@ -3,11 +3,12 @@ import ReaderClass from 'protobufjs/src/reader.js' // @ts-expect-error no types import ReaderBufferClass from 'protobufjs/src/reader_buffer.js' // @ts-expect-error no types +import util from 'protobufjs/src/util/minimal.js' +// @ts-expect-error no types import WriterClass from 'protobufjs/src/writer.js' // @ts-expect-error no types import WriterBufferClass from 'protobufjs/src/writer_buffer.js' -// @ts-expect-error no types -import util from 'protobufjs/src/util/minimal.js' + import type { Reader, Writer } from './index.js' function configure (): void { diff --git a/packages/protons/bin/protons.ts b/packages/protons/bin/protons.ts index 23ceee2..55e6615 100644 --- a/packages/protons/bin/protons.ts +++ b/packages/protons/bin/protons.ts @@ -1,6 +1,7 @@ #! /usr/bin/env node import meow from 'meow' + import { generate } from '../src/index.js' async function main (): Promise { diff --git a/packages/protons/src/index.ts b/packages/protons/src/index.ts index d26c19f..4f71681 100644 --- a/packages/protons/src/index.ts +++ b/packages/protons/src/index.ts @@ -1,9 +1,10 @@ /* eslint-disable max-depth */ -import { main as pbjs } from 'protobufjs-cli/pbjs.js' +import fs from 'fs/promises' import path from 'path' import { promisify } from 'util' -import fs from 'fs/promises' + +import { main as pbjs } from 'protobufjs-cli/pbjs.js' export enum CODEC_TYPES { VARINT = 0, @@ -686,29 +687,37 @@ export async function generate (source: string, flags: Flags): Promise { const moduleDef = defineModule(def) - let lines = [ + const ignores = [ '/* eslint-disable import/export */', '/* eslint-disable complexity */', '/* eslint-disable @typescript-eslint/no-namespace */', '/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */', - '/* eslint-disable @typescript-eslint/no-empty-interface */', - '' + '/* eslint-disable @typescript-eslint/no-empty-interface */' ] + const imports = [] + if (moduleDef.imports.size > 0) { - lines.push(`import { ${Array.from(moduleDef.imports).join(', ')} } from 'protons-runtime'`) + imports.push(`import { ${Array.from(moduleDef.imports).join(', ')} } from 'protons-runtime'`) } if (moduleDef.imports.has('encodeMessage')) { - lines.push("import type { Uint8ArrayList } from 'uint8arraylist'") + imports.push("import type { Uint8ArrayList } from 'uint8arraylist'") } if (moduleDef.importedTypes.size > 0) { - lines.push(`import type { ${Array.from(moduleDef.importedTypes).join(', ')} } from 'protons-runtime'`) + imports.push(`import type { ${Array.from(moduleDef.importedTypes).join(', ')} } from 'protons-runtime'`) } - lines = [ - ...lines, + const lines = [ + ...ignores, + '', + ...imports.sort((a, b) => { + const aModule = a.split("from '")[1].toString() + const bModule = b.split("from '")[1].toString() + + return aModule.localeCompare(bModule) + }), '', ...moduleDef.compiled ] diff --git a/packages/protons/test/fixtures/basic.ts b/packages/protons/test/fixtures/basic.ts index e629eee..3981ee1 100644 --- a/packages/protons/test/fixtures/basic.ts +++ b/packages/protons/test/fixtures/basic.ts @@ -5,8 +5,8 @@ /* eslint-disable @typescript-eslint/no-empty-interface */ import { encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Uint8ArrayList } from 'uint8arraylist' import type { Codec } from 'protons-runtime' +import type { Uint8ArrayList } from 'uint8arraylist' export interface Basic { foo?: string diff --git a/packages/protons/test/fixtures/circuit.ts b/packages/protons/test/fixtures/circuit.ts index a0134c4..77239b0 100644 --- a/packages/protons/test/fixtures/circuit.ts +++ b/packages/protons/test/fixtures/circuit.ts @@ -5,8 +5,8 @@ /* eslint-disable @typescript-eslint/no-empty-interface */ import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Uint8ArrayList } from 'uint8arraylist' import type { Codec } from 'protons-runtime' +import type { Uint8ArrayList } from 'uint8arraylist' export interface CircuitRelay { type?: CircuitRelay.Type diff --git a/packages/protons/test/fixtures/daemon.ts b/packages/protons/test/fixtures/daemon.ts index 96b0eb2..e450c73 100644 --- a/packages/protons/test/fixtures/daemon.ts +++ b/packages/protons/test/fixtures/daemon.ts @@ -5,8 +5,8 @@ /* eslint-disable @typescript-eslint/no-empty-interface */ import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Uint8ArrayList } from 'uint8arraylist' import type { Codec } from 'protons-runtime' +import type { Uint8ArrayList } from 'uint8arraylist' export interface Request { type: Request.Type diff --git a/packages/protons/test/fixtures/dht.ts b/packages/protons/test/fixtures/dht.ts index f692c0c..5bc2a26 100644 --- a/packages/protons/test/fixtures/dht.ts +++ b/packages/protons/test/fixtures/dht.ts @@ -5,8 +5,8 @@ /* eslint-disable @typescript-eslint/no-empty-interface */ import { encodeMessage, decodeMessage, message, enumeration } from 'protons-runtime' -import type { Uint8ArrayList } from 'uint8arraylist' import type { Codec } from 'protons-runtime' +import type { Uint8ArrayList } from 'uint8arraylist' export interface Record { key?: Uint8Array diff --git a/packages/protons/test/fixtures/maps.ts b/packages/protons/test/fixtures/maps.ts index 8bd8a50..0459c3a 100644 --- a/packages/protons/test/fixtures/maps.ts +++ b/packages/protons/test/fixtures/maps.ts @@ -5,8 +5,8 @@ /* eslint-disable @typescript-eslint/no-empty-interface */ import { encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Uint8ArrayList } from 'uint8arraylist' import type { Codec } from 'protons-runtime' +import type { Uint8ArrayList } from 'uint8arraylist' export interface SubMessage { foo: string diff --git a/packages/protons/test/fixtures/noise.ts b/packages/protons/test/fixtures/noise.ts index 86e0417..4e75e28 100644 --- a/packages/protons/test/fixtures/noise.ts +++ b/packages/protons/test/fixtures/noise.ts @@ -5,8 +5,8 @@ /* eslint-disable @typescript-eslint/no-empty-interface */ import { encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Uint8ArrayList } from 'uint8arraylist' import type { Codec } from 'protons-runtime' +import type { Uint8ArrayList } from 'uint8arraylist' export interface pb {} diff --git a/packages/protons/test/fixtures/optional.ts b/packages/protons/test/fixtures/optional.ts index 91ff353..47bb5ea 100644 --- a/packages/protons/test/fixtures/optional.ts +++ b/packages/protons/test/fixtures/optional.ts @@ -5,8 +5,8 @@ /* eslint-disable @typescript-eslint/no-empty-interface */ import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Uint8ArrayList } from 'uint8arraylist' import type { Codec } from 'protons-runtime' +import type { Uint8ArrayList } from 'uint8arraylist' export enum OptionalEnum { NO_VALUE = 'NO_VALUE', diff --git a/packages/protons/test/fixtures/peer.ts b/packages/protons/test/fixtures/peer.ts index a55f9eb..f714516 100644 --- a/packages/protons/test/fixtures/peer.ts +++ b/packages/protons/test/fixtures/peer.ts @@ -5,8 +5,8 @@ /* eslint-disable @typescript-eslint/no-empty-interface */ import { encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Uint8ArrayList } from 'uint8arraylist' import type { Codec } from 'protons-runtime' +import type { Uint8ArrayList } from 'uint8arraylist' export interface Peer { addresses: Address[] diff --git a/packages/protons/test/fixtures/singular.ts b/packages/protons/test/fixtures/singular.ts index ff3a65d..3244a5a 100644 --- a/packages/protons/test/fixtures/singular.ts +++ b/packages/protons/test/fixtures/singular.ts @@ -5,8 +5,8 @@ /* eslint-disable @typescript-eslint/no-empty-interface */ import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Uint8ArrayList } from 'uint8arraylist' import type { Codec } from 'protons-runtime' +import type { Uint8ArrayList } from 'uint8arraylist' export enum SingularEnum { NO_VALUE = 'NO_VALUE', diff --git a/packages/protons/test/fixtures/test.ts b/packages/protons/test/fixtures/test.ts index 670d7c5..2e2a553 100644 --- a/packages/protons/test/fixtures/test.ts +++ b/packages/protons/test/fixtures/test.ts @@ -5,8 +5,8 @@ /* eslint-disable @typescript-eslint/no-empty-interface */ import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime' -import type { Uint8ArrayList } from 'uint8arraylist' import type { Codec } from 'protons-runtime' +import type { Uint8ArrayList } from 'uint8arraylist' export enum AnEnum { HERP = 'HERP', diff --git a/packages/protons/test/index.spec.ts b/packages/protons/test/index.spec.ts index 7ad8c56..778a876 100644 --- a/packages/protons/test/index.spec.ts +++ b/packages/protons/test/index.spec.ts @@ -1,16 +1,19 @@ /* eslint-env mocha */ +import fs from 'fs' + import { expect } from 'aegir/chai' + +import Long from 'long' import pbjs from 'pbjs' -import { Basic, Empty } from './fixtures/basic.js' -import { AllTheTypes, AnEnum } from './fixtures/test.js' -import fs from 'fs' import protobufjs, { Type as PBType } from 'protobufjs' -import { Peer } from './fixtures/peer.js' + +import { Basic, Empty } from './fixtures/basic.js' import { CircuitRelay } from './fixtures/circuit.js' -import Long from 'long' import { Optional, OptionalEnum } from './fixtures/optional.js' +import { Peer } from './fixtures/peer.js' import { Singular, SingularEnum } from './fixtures/singular.js' +import { AllTheTypes, AnEnum } from './fixtures/test.js' function longifyBigInts (obj: any): any { const output = { diff --git a/packages/protons/test/maps.spec.ts b/packages/protons/test/maps.spec.ts index fdf004b..c73eb77 100644 --- a/packages/protons/test/maps.spec.ts +++ b/packages/protons/test/maps.spec.ts @@ -1,9 +1,11 @@ /* eslint-env mocha */ import { expect } from 'aegir/chai' -import { MapTypes, SubMessage } from './fixtures/maps.js' -import protobufjs from 'protobufjs' + import Long from 'long' +import protobufjs from 'protobufjs' + +import { MapTypes, SubMessage } from './fixtures/maps.js' function longifyBigInts (obj: any): any { const output = { diff --git a/packages/protons/test/unsupported.spec.ts b/packages/protons/test/unsupported.spec.ts index 7f29154..216198e 100644 --- a/packages/protons/test/unsupported.spec.ts +++ b/packages/protons/test/unsupported.spec.ts @@ -1,6 +1,7 @@ /* eslint-env mocha */ import { expect } from 'aegir/chai' + import { generate } from '../src/index.js' describe('unsupported', () => {