Skip to content

Commit

Permalink
style: enforce import ordering (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoGlastra authored Jun 9, 2021
1 parent cba4be1 commit 2c92410
Show file tree
Hide file tree
Showing 177 changed files with 757 additions and 446 deletions.
16 changes: 16 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ module.exports = {
parser: '@typescript-eslint/parser',
extends: [
'eslint:recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and displays prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
settings: {
'import/extensions': ['.js', '.ts'],
},
plugins: ['@typescript-eslint'],
rules: {
// Type is enforced by callers. Not entirely, but it's good enough.
Expand All @@ -17,12 +22,23 @@ module.exports = {
'no-console': 'error',
// Because of early development, we only warn on ts-ignore. In future we want to move to error
'@typescript-eslint/ban-ts-comment': 'warn',
'import/order': [
'error',
{
groups: [['builtin', 'external'], 'parent', 'sibling', 'index'],
alphabetize: {
order: 'asc',
},
'newlines-between': 'always',
},
],
},
overrides: [
{
files: ['*.test.*'],
rules: {
'no-console': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
},
},
{
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
"class-validator": "^0.13.1",
"events": "^3.3.0",
"js-sha256": "^0.9.0",
"make-error": "^1.3.6",
"multibase": "4.0.2",
"multihashes": "^4.0.2",
"make-error": "^1.3.6",
"node-fetch": "^2.6.1",
"object-inspect": "^1.10.3",
"react-native-fs": "^2.18.0",
Expand All @@ -62,6 +62,7 @@
"dotenv": "^8.2.0",
"eslint": "^7.21.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-prettier": "^3.3.1",
"express": "^4.17.1",
"husky": "^5.1.3",
Expand Down
4 changes: 3 additions & 1 deletion src/__tests__/agents.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Subject } from 'rxjs'

import { Agent } from '..'
import { SubjectInboundTransporter, SubjectOutboundTransporter, waitForBasicMessage, getBaseConfig } from './helpers'
import { ConnectionRecord } from '../modules/connections'

import { SubjectInboundTransporter, SubjectOutboundTransporter, waitForBasicMessage, getBaseConfig } from './helpers'

const aliceConfig = getBaseConfig('Agents Alice')
const bobConfig = getBaseConfig('Agents Bob')

Expand Down
21 changes: 12 additions & 9 deletions src/__tests__/credentials.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { Subject } from 'rxjs'
import { Agent, ConnectionRecord } from '..'

import { Agent } from '../agent/Agent'
import { ConnectionRecord } from '../modules/connections'
import {
CredentialRecord,
CredentialState,
CredentialPreview,
CredentialPreviewAttribute,
} from '../modules/credentials'
import { JsonTransformer } from '../utils/JsonTransformer'

import {
ensurePublicDidIsOnLedger,
makeConnection,
Expand All @@ -11,14 +21,6 @@ import {
genesisPath,
getBaseConfig,
} from './helpers'
import {
CredentialRecord,
CredentialState,
CredentialPreview,
CredentialPreviewAttribute,
} from '../modules/credentials'
import { JsonTransformer } from '../utils/JsonTransformer'

import testLogger from './logger'

const faberConfig = getBaseConfig('Faber Credentials', {
Expand Down Expand Up @@ -86,6 +88,7 @@ describe('credentials', () => {
credDefId = credentialDefinition.id

const publicDid = faberAgent.publicDid?.did

await ensurePublicDidIsOnLedger(faberAgent, publicDid!)
const { agentAConnection, agentBConnection } = await makeConnection(faberAgent, aliceAgent)
faberConnection = agentAConnection
Expand Down
12 changes: 7 additions & 5 deletions src/__tests__/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import type { Schema, CredDef, Did } from 'indy-sdk'
import indy from 'indy-sdk'
import path from 'path'
import { Subject } from 'rxjs'

import { Agent, InboundTransporter, OutboundTransporter } from '..'
import { InitConfig, OutboundPackage, WireMessage } from '../types'
import { BasicMessage, BasicMessageEventTypes, BasicMessageReceivedEvent } from '../modules/basic-messages'
import {
ConnectionInvitationMessage,
ConnectionRecord,
Expand All @@ -13,18 +14,19 @@ import {
DidCommService,
DidDoc,
} from '../modules/connections'
import { ProofEventTypes, ProofRecord, ProofState, ProofStateChangedEvent } from '../modules/proofs'
import { SchemaTemplate, CredentialDefinitionTemplate } from '../modules/ledger'
import {
CredentialRecord,
CredentialOfferTemplate,
CredentialStateChangedEvent,
CredentialState,
CredentialEventTypes,
} from '../modules/credentials'
import { BasicMessage, BasicMessageEventTypes, BasicMessageReceivedEvent } from '../modules/basic-messages'
import testLogger from './logger'
import { SchemaTemplate, CredentialDefinitionTemplate } from '../modules/ledger'
import { ProofEventTypes, ProofRecord, ProofState, ProofStateChangedEvent } from '../modules/proofs'
import { NodeFileSystem } from '../storage/fs/NodeFileSystem'
import { InitConfig, OutboundPackage, WireMessage } from '../types'

import testLogger from './logger'

export const genesisPath = process.env.GENESIS_TXN_PATH
? path.resolve(process.env.GENESIS_TXN_PATH)
Expand Down
4 changes: 3 additions & 1 deletion src/__tests__/ledger.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { promises } from 'fs'
import indy from 'indy-sdk'
import type { SchemaId } from 'indy-sdk'

import { Agent } from '..'
import { DID_IDENTIFIER_REGEX, VERKEY_REGEX, isFullVerkey, isAbbreviatedVerkey } from '../utils/did'

import { genesisPath, getBaseConfig, sleep } from './helpers'
import testLogger from './logger'
import { promises } from 'fs'

const faberConfig = getBaseConfig('Faber Ledger', { genesisPath })

Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/logger.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { appendFileSync } from 'fs'
import { ILogObject, Logger } from 'tslog'

import { LogLevel } from '../logger'
import { BaseLogger } from '../logger/BaseLogger'
import { appendFileSync } from 'fs'

function logToTransport(logObject: ILogObject) {
appendFileSync('logs.txt', JSON.stringify(logObject) + '\n')
Expand Down
26 changes: 14 additions & 12 deletions src/__tests__/proofs.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
import type { CredDefId } from 'indy-sdk'
import { Subject } from 'rxjs'

import { Agent } from '..'
import { ConnectionRecord } from '../modules/connections'
import { CredentialPreview, CredentialPreviewAttribute } from '../modules/credentials'
import {
PredicateType,
PresentationPreview,
PresentationPreviewAttribute,
PresentationPreviewPredicate,
ProofState,
ProofAttributeInfo,
AttributeFilter,
ProofPredicateInfo,
} from '../modules/proofs'

import {
ensurePublicDidIsOnLedger,
makeConnection,
Expand All @@ -13,18 +27,6 @@ import {
waitForProofRecord,
getBaseConfig,
} from './helpers'
import { CredentialPreview, CredentialPreviewAttribute } from '../modules/credentials'
import {
PredicateType,
PresentationPreview,
PresentationPreviewAttribute,
PresentationPreviewPredicate,
ProofState,
ProofAttributeInfo,
AttributeFilter,
ProofPredicateInfo,
} from '../modules/proofs'
import { ConnectionRecord } from '../modules/connections'
import testLogger from './logger'

const faberConfig = getBaseConfig('Faber Proofs', { genesisPath })
Expand Down
27 changes: 14 additions & 13 deletions src/agent/Agent.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import { container as baseContainer, DependencyContainer } from 'tsyringe'

import { Logger } from '../logger'
import { InitConfig } from '../types'
import { IndyWallet } from '../wallet/IndyWallet'
import { MessageReceiver } from './MessageReceiver'
import { MessageSender } from './MessageSender'
import { InboundTransporter } from '../transport/InboundTransporter'
import { OutboundTransporter } from '../transport/OutboundTransporter'
import { MessageRepository } from '../storage/MessageRepository'
import { IndyStorageService } from '../storage/IndyStorageService'
import { AgentConfig } from './AgentConfig'
import { Wallet } from '../wallet/Wallet'
import { BasicMessagesModule } from '../modules/basic-messages/BasicMessagesModule'
import { ConnectionsModule } from '../modules/connections/ConnectionsModule'
import { CredentialsModule } from '../modules/credentials/CredentialsModule'
import { LedgerModule } from '../modules/ledger/LedgerModule'
import { ProofsModule } from '../modules/proofs/ProofsModule'
import { RoutingModule } from '../modules/routing/RoutingModule'
import { BasicMessagesModule } from '../modules/basic-messages/BasicMessagesModule'
import { LedgerModule } from '../modules/ledger/LedgerModule'
import { InMemoryMessageRepository } from '../storage/InMemoryMessageRepository'
import { IndyStorageService } from '../storage/IndyStorageService'
import { MessageRepository } from '../storage/MessageRepository'
import { Symbols } from '../symbols'
import { TransportSession } from './TransportService'
import { InboundTransporter } from '../transport/InboundTransporter'
import { OutboundTransporter } from '../transport/OutboundTransporter'
import { InitConfig } from '../types'
import { IndyWallet } from '../wallet/IndyWallet'
import { Wallet } from '../wallet/Wallet'

import { AgentConfig } from './AgentConfig'
import { EventEmitter } from './EventEmitter'
import { AgentEventTypes, AgentMessageReceivedEvent } from './Events'
import { MessageReceiver } from './MessageReceiver'
import { MessageSender } from './MessageSender'
import { TransportSession } from './TransportService'

export class Agent {
protected agentConfig: AgentConfig
Expand Down
1 change: 1 addition & 0 deletions src/agent/AgentConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ConsoleLogger, Logger, LogLevel } from '../logger'
import { InitConfig, InboundConnection, DidCommMimeType } from '../types'

import { DID_COMM_TRANSPORT_QUEUE } from './TransportService'

export class AgentConfig {
Expand Down
13 changes: 7 additions & 6 deletions src/agent/AgentMessage.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Compose } from '../utils/mixins'
import { ThreadDecorated } from '../decorators/thread/ThreadDecoratorExtension'
import { AckDecorated } from '../decorators/ack/AckDecoratorExtension'
import { AttachmentDecorated } from '../decorators/attachment/AttachmentExtension'
import { L10nDecorated } from '../decorators/l10n/L10nDecoratorExtension'
import { TransportDecorated } from '../decorators/transport/TransportDecoratorExtension'
import { ThreadDecorated } from '../decorators/thread/ThreadDecoratorExtension'
import { TimingDecorated } from '../decorators/timing/TimingDecoratorExtension'
import { BaseMessage } from './BaseMessage'
import { TransportDecorated } from '../decorators/transport/TransportDecoratorExtension'
import { JsonTransformer } from '../utils/JsonTransformer'
import { AckDecorated } from '../decorators/ack/AckDecoratorExtension'
import { AttachmentDecorated } from '../decorators/attachment/AttachmentExtension'
import { Compose } from '../utils/mixins'

import { BaseMessage } from './BaseMessage'

const DefaultDecorators = [
ThreadDecorated,
Expand Down
2 changes: 1 addition & 1 deletion src/agent/BaseMessage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Expose } from 'class-transformer'
import { Matches } from 'class-validator'

import { uuid } from '../utils/uuid'
import { Constructor } from '../utils/mixins'
import { uuid } from '../utils/uuid'

export const MessageIdRegExp = /[-_./a-zA-Z0-9]{8,64}/
export const MessageTypeRegExp = /(.*?)([a-z0-9._-]+)\/(\d[^/]*)\/([a-z0-9._-]+)$/
Expand Down
10 changes: 6 additions & 4 deletions src/agent/Dispatcher.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Lifecycle, scoped } from 'tsyringe'

import { ReturnRouteTypes } from '../decorators/transport/TransportDecorator'
import { AriesFrameworkError } from '../error/AriesFrameworkError'
import { OutboundMessage, OutboundPackage } from '../types'

import { AgentMessage } from './AgentMessage'
import { Handler } from './Handler'
import { MessageSender } from './MessageSender'
import { AgentMessage } from './AgentMessage'
import { InboundMessageContext } from './models/InboundMessageContext'
import { ReturnRouteTypes } from '../decorators/transport/TransportDecorator'
import { TransportService } from './TransportService'
import { AriesFrameworkError } from '../error/AriesFrameworkError'
import { InboundMessageContext } from './models/InboundMessageContext'

@scoped(Lifecycle.ContainerScoped)
class Dispatcher {
Expand Down
8 changes: 5 additions & 3 deletions src/agent/EnvelopeService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { inject, scoped, Lifecycle } from 'tsyringe'

import { Logger } from '../logger'
import { ForwardMessage } from '../modules/routing/messages'
import { Symbols } from '../symbols'
import { OutboundMessage, UnpackedMessageContext } from '../types'
import { Wallet } from '../wallet/Wallet'
import { ForwardMessage } from '../modules/routing/messages'

import { AgentConfig } from './AgentConfig'
import { Logger } from '../logger'
import { Symbols } from '../symbols'

@scoped(Lifecycle.ContainerScoped)
class EnvelopeService {
Expand Down
3 changes: 2 additions & 1 deletion src/agent/EventEmitter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Lifecycle, scoped } from 'tsyringe'
import { EventEmitter as NativeEventEmitter } from 'events'
import { Lifecycle, scoped } from 'tsyringe'

import { BaseEvent } from './Events'

@scoped(Lifecycle.ContainerScoped)
Expand Down
1 change: 1 addition & 0 deletions src/agent/Handler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { OutboundMessage } from '../types'

import { AgentMessage } from './AgentMessage'
import { InboundMessageContext } from './models/InboundMessageContext'

Expand Down
19 changes: 10 additions & 9 deletions src/agent/MessageReceiver.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { Lifecycle, scoped } from 'tsyringe'

import { AgentConfig } from './AgentConfig'
import { Dispatcher } from './Dispatcher'
import { EnvelopeService } from './EnvelopeService'
import { UnpackedMessageContext, UnpackedMessage } from '../types'
import { InboundMessageContext } from './models/InboundMessageContext'
import { RoutingMessageType as MessageType } from '../modules/routing'
import { AriesFrameworkError } from '../error'
import { Logger } from '../logger'
import { ConnectionService } from '../modules/connections'
import { AgentMessage } from './AgentMessage'
import { RoutingMessageType as MessageType } from '../modules/routing'
import { UnpackedMessageContext, UnpackedMessage } from '../types'
import { JsonTransformer } from '../utils/JsonTransformer'
import { Logger } from '../logger'
import { replaceLegacyDidSovPrefixOnMessage } from '../utils/messageType'

import { AgentConfig } from './AgentConfig'
import { AgentMessage } from './AgentMessage'
import { Dispatcher } from './Dispatcher'
import { EnvelopeService } from './EnvelopeService'
import { TransportSession, TransportService } from './TransportService'
import { AriesFrameworkError } from '../error'
import { InboundMessageContext } from './models/InboundMessageContext'

@scoped(Lifecycle.ContainerScoped)
export class MessageReceiver {
Expand Down
9 changes: 5 additions & 4 deletions src/agent/MessageSender.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { inject, Lifecycle, scoped } from 'tsyringe'

import { OutboundMessage, OutboundPackage } from '../types'
import { OutboundTransporter } from '../transport/OutboundTransporter'
import { EnvelopeService } from './EnvelopeService'
import { TransportService } from './TransportService'
import { AriesFrameworkError } from '../error'
import { Logger } from '../logger'
import { Symbols } from '../symbols'
import { OutboundTransporter } from '../transport/OutboundTransporter'
import { OutboundMessage, OutboundPackage } from '../types'

import { EnvelopeService } from './EnvelopeService'
import { TransportService } from './TransportService'

@scoped(Lifecycle.ContainerScoped)
export class MessageSender {
Expand Down
4 changes: 2 additions & 2 deletions src/agent/TransportService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Lifecycle, scoped, inject } from 'tsyringe'

import { AriesFrameworkError } from '../error'
import { Logger } from '../logger'
import { ConnectionRecord } from '../modules/connections/repository'
import { ConnectionRole } from '../modules/connections/models'
import { ConnectionRecord } from '../modules/connections/repository'
import { Symbols } from '../symbols'
import { AriesFrameworkError } from '../error'

export const DID_COMM_TRANSPORT_QUEUE = 'didcomm:transport/queue'

Expand Down
Loading

0 comments on commit 2c92410

Please sign in to comment.