Skip to content
Snippets Groups Projects
Commit a54c62f8 authored by Berend Sliedrecht's avatar Berend Sliedrecht
Browse files

fixed linting for ssi-abstraction


Signed-off-by: default avatarBerend Sliedrecht <sliedrecht@berend.io>
parent 1e2bfb43
No related branches found
No related tags found
2 merge requests!9feat(ssi): Establish a trusted connection with yourself,!8Project house-keeping, refactoring and reorganizing
Showing
with 88 additions and 83 deletions
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
ecmaVersion: 2021,
},
env: {
node: true,
},
plugins: ['prettier', '@typescript-eslint/eslint-plugin', 'jest'],
extends: [
'prettier',
'plugin:@typescript-eslint/recommended',
'plugin:jest/recommended',
],
ignorePatterns: ['.eslintrc.cjs', 'dist'],
overrides: [],
settings: {
jest: {
version: '29',
},
},
rules: {
'no-unused-vars': 0,
'@typescript-eslint/no-unused-vars': [1, { argsIgnorePattern: '^_' }],
},
overrides: [
{
files: [
'*.spec.ts',
'*.e2e-spec.ts',
'__mocks__/*.ts',
'__mocks__/**/*.ts',
],
rules: {
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-empty-function': 0,
'@typescript-eslint/ban-ts-comment': 0,
'@typescript-eslint/no-unused-vars': 0,
'jest/no-mocks-import': 0,
'jest/expect-expect': 0,
},
},
],
};
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'airbnb-base',
'airbnb-typescript/base'
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
......@@ -17,8 +17,8 @@
"start": "nest start",
"start:dev": "nest start --watch --preserveWatchOutput",
"start:docker": "pnpm prisma:generate && pnpm dbSchema && pnpm start",
"lint": "eslint --fix",
"lint:all": "npm run lint -- .",
"lint": "eslint .",
"lint:fix": "pnpm lint --fix",
"format": "prettier --write",
"format:all": "npm run format -- .",
"test": "jest",
......
......@@ -5,7 +5,6 @@ import { AgentService } from './agent.service.js';
export class AgentController {
public constructor(private agent: AgentService) {}
// eslint-disable-next-line class-methods-use-this
@Get('info')
async getWalletInfo() {
return {
......
......@@ -168,9 +168,7 @@ export class AgentService {
seed: publicDidSeed,
});
// eslint-disable-next-line no-restricted-syntax
for (const publicDidResponse of registeredPublicDidResponses) {
// eslint-disable-next-line no-await-in-loop
await this.agent.dids.import({
overwrite: true,
did: publicDidResponse.did,
......
......@@ -27,12 +27,8 @@ export const registerPublicDids = async ({
seed,
}: RegisterPublicDidOptions): Promise<Array<RegisterPublicDidResponse>> => {
const responses: Array<RegisterPublicDidResponse> = [];
// eslint-disable-next-line no-restricted-syntax
for (const ledgerId of ledgerIds) {
try {
// TODO: why does this fail?
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const ledgerRegisterUrl = NYM_URL[ledgerId];
const ledgerNamespace = ledgerNamespaces[ledgerId];
......@@ -42,7 +38,6 @@ export const registerPublicDids = async ({
seed,
};
// eslint-disable-next-line no-await-in-loop
const res = await new axios.Axios().post<RegisterPublicDidResponse>(
ledgerRegisterUrl,
body,
......
import { AxiosError } from 'axios';
import logger from '../../globalUtils/logger.js';
export function logAxiosError(err: any) {
export function logAxiosError(err: AxiosError) {
if (err.response) {
logger.error('Request made and server responded: ');
logger.error(`Data: ${err.response.data}`);
......
......@@ -4,7 +4,6 @@ describe('listener', () => {
it('should subscribe agent to available events', async () => {
const agent = {
events: {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
on: (eventName: string, cb: () => void) => {},
},
};
......@@ -21,7 +20,6 @@ describe('listener', () => {
.mockImplementation((eventName: string, cb: () => void) => {
lastCb = cb;
});
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
subscribe(agent, natsClient);
expect(spy).toHaveBeenCalled();
......
......@@ -2,37 +2,58 @@ import { BaseLogger, LogLevel } from '@aries-framework/core';
import logger from '../../globalUtils/logger.js';
export class AgentLogger extends BaseLogger {
public test(message: string, data?: Record<string, any> | undefined): void {
public test(
message: string,
data?: Record<string, unknown> | undefined,
): void {
if (!this.isEnabled(LogLevel.test)) return;
logger.verbose(message, data);
}
public trace(message: string, data?: Record<string, any> | undefined): void {
public trace(
message: string,
data?: Record<string, unknown> | undefined,
): void {
if (!this.isEnabled(LogLevel.trace)) return;
logger.info(message, data);
}
public debug(message: string, data?: Record<string, any> | undefined): void {
public debug(
message: string,
data?: Record<string, unknown> | undefined,
): void {
if (!this.isEnabled(LogLevel.debug)) return;
logger.info(message, data);
}
public info(message: string, data?: Record<string, any> | undefined): void {
public info(
message: string,
data?: Record<string, unknown> | undefined,
): void {
if (!this.isEnabled(LogLevel.info)) return;
logger.info(message, data);
}
public warn(message: string, data?: Record<string, any> | undefined): void {
public warn(
message: string,
data?: Record<string, unknown> | undefined,
): void {
if (!this.isEnabled(LogLevel.warn)) return;
logger.warn(message, data);
}
public error(message: string, data?: Record<string, any> | undefined): void {
public error(
message: string,
data?: Record<string, unknown> | undefined,
): void {
if (!this.isEnabled(LogLevel.error)) return;
logger.error(message, data);
}
public fatal(message: string, data?: Record<string, any> | undefined): void {
public fatal(
message: string,
data?: Record<string, unknown> | undefined,
): void {
if (!this.isEnabled(LogLevel.fatal)) return;
logger.error(message, data);
}
......
......@@ -29,7 +29,6 @@ import { AgentModule } from './agent/agent.module.js';
],
})
export class AppModule implements NestModule {
// eslint-disable-next-line class-methods-use-this
configure(consumer: MiddlewareConsumer) {
consumer.apply(AgentMid).forRoutes('agent', '*/agent');
}
......
......@@ -15,7 +15,7 @@ export class NatsClientService {
* @param eventName - the event name
* @param data - the data to be passed as payload of the event
*/
publish(eventName: string, data: any) {
publish<D = unknown>(eventName: string, data: D) {
logger.info(
`Publish nats event: ${NATSServices.SERVICE_NAME}/${eventName}`,
);
......
export interface ResponseType {
statusCode: number;
message: string;
data?: any;
error?: any;
data?: unknown;
error?: unknown;
}
......@@ -22,8 +22,6 @@ interface Config {
autoAcceptConnection: boolean;
autoAcceptCredential: AutoAcceptCredential;
idUnionKey: string;
basicUser: string;
basicPass: string;
};
}
......@@ -49,8 +47,6 @@ const config = (): Config => ({
autoAcceptCredential: process.env
.AGENT_AUTO_ACCEPT_CREDENTIAL as AutoAcceptCredential,
idUnionKey: process.env.AGENT_ID_UNION_KEY || '',
basicUser: process.env.BASIC_USER!,
basicPass: process.env.BASIC_PASS!,
},
});
......
......@@ -18,7 +18,7 @@ export class ExceptionHandler implements ExceptionFilter {
* @param exception - error
* @param host - the execution context for exceptions
*/
catch(exception: any, host: ArgumentsHost): void {
catch(exception: HttpException, host: ArgumentsHost): void {
// In certain situations `httpAdapter` might not be available in the
// constructor method, thus we should resolve it here.
const { httpAdapter } = this.httpAdapterHost;
......@@ -27,17 +27,10 @@ export class ExceptionHandler implements ExceptionFilter {
const response = ctx.getResponse();
let statusCode = HttpStatus.INTERNAL_SERVER_ERROR;
let message =
exception.message.error || exception.message || 'Something went wrong!';
const message = exception.message || 'Something went wrong!';
if (exception instanceof HttpException) {
const errorResponse = exception.getResponse();
statusCode = exception.getStatus();
message =
typeof errorResponse === 'object' && 'error' in errorResponse
? errorResponse.error
: errorResponse || message;
}
const responseBody: ResponseType = {
......
import winston, { Logger } from 'winston';
import ecsFormat from '@elastic/ecs-winston-format';
// import { ElasticsearchTransport } from 'winston-elasticsearch';
// const esTransportOpts = {
// clientOpts: { node: process.env.ECSURL },
// };
//
// const esTransport = new ElasticsearchTransport(esTransportOpts);
//
// esTransport.on('error', (error: any) => {
// console.error('Error in logger caught', error);
// });
const logger: Logger = winston.createLogger({
format: ecsFormat({ convertReqRes: true }),
transports: [
new winston.transports.Console(),
// esTransport,
],
transports: [new winston.transports.Console()],
});
logger.on('error', (error: Error) => {
// eslint-disable-next-line no-console
console.error('Error in logger caught', error);
});
......
......@@ -7,7 +7,6 @@ export class HealthController {
*
* @returns - OK (200) if app is running
*/
// eslint-disable-next-line class-methods-use-this
@Get()
getHealth() {
return {
......
......@@ -7,7 +7,6 @@ import { Request, NextFunction, Response } from 'express';
*/
@Injectable()
export class AgentMid implements NestMiddleware {
// eslint-disable-next-line class-methods-use-this
use(req: Request, res: Response, next: NextFunction) {
const [, prop] = req.url.split('/');
if (prop === 'info') {
......
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import request from 'supertest';
import AppModule from '@src/app.module';
import AppModule from '../src/app.module';
describe('DidCommController (e2e)', () => {
let app: INestApplication;
......
......@@ -11,5 +11,5 @@
"rootDir": "./src"
},
"include": ["src", "config"],
"exclude": ["node_modules", "./dist/**/*"]
"exclude": ["node_modules", "dist"]
}
......@@ -8,6 +8,7 @@
"connection:build": "pnpm -F connection-manager build",
"principal:build": "pnpm -F principal-manager build",
"proof:build": "pnpm -F proof-manager build",
"ssi:build": "pnpm -F ssi-abstraction build"
"ssi:build": "pnpm -F ssi-abstraction build",
"lint": "pnpm -r lint"
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment