Skip to content

Commit

Permalink
fix: sort imports (#84)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
achingbrain committed Feb 2, 2023
1 parent 229afbc commit 6f796f1
Show file tree
Hide file tree
Showing 23 changed files with 62 additions and 38 deletions.
3 changes: 2 additions & 1 deletion packages/protons-benchmark/src/decode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
3 changes: 2 additions & 1 deletion packages/protons-benchmark/src/encode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
8 changes: 5 additions & 3 deletions packages/protons-benchmark/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion packages/protons-benchmark/src/protons/bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/protons-benchmark/src/protons/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
6 changes: 4 additions & 2 deletions packages/protons-benchmark/src/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down
1 change: 1 addition & 0 deletions packages/protons-runtime/src/decode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Uint8ArrayList } from 'uint8arraylist'

import type { Codec } from './codec.js'
import { reader } from './utils.js'

Expand Down
5 changes: 3 additions & 2 deletions packages/protons-runtime/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions packages/protons/bin/protons.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#! /usr/bin/env node

import meow from 'meow'

import { generate } from '../src/index.js'

async function main (): Promise<void> {
Expand Down
29 changes: 19 additions & 10 deletions packages/protons/src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -697,29 +698,37 @@ export async function generate (source: string, flags: Flags): Promise<void> {

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
]
Expand Down
2 changes: 1 addition & 1 deletion packages/protons/test/fixtures/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/protons/test/fixtures/circuit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/protons/test/fixtures/daemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/protons/test/fixtures/dht.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/protons/test/fixtures/maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/protons/test/fixtures/noise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
2 changes: 1 addition & 1 deletion packages/protons/test/fixtures/optional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion packages/protons/test/fixtures/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
2 changes: 1 addition & 1 deletion packages/protons/test/fixtures/singular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion packages/protons/test/fixtures/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
13 changes: 8 additions & 5 deletions packages/protons/test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
6 changes: 4 additions & 2 deletions packages/protons/test/maps.spec.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
1 change: 1 addition & 0 deletions packages/protons/test/unsupported.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-env mocha */

import { expect } from 'aegir/chai'

import { generate } from '../src/index.js'

describe('unsupported', () => {
Expand Down

0 comments on commit 6f796f1

Please sign in to comment.