From a6abfa4c4012e4d611e3bce1f86efeb0bec41710 Mon Sep 17 00:00:00 2001 From: Alberto Lerda Date: Fri, 27 Oct 2023 13:12:40 +0100 Subject: [PATCH] fix: linting --- pkg/browser/package.json | 88 +++++++++++++++---------------- pkg/browser/public/index.html | 23 ++++---- pkg/browser/src/index.ts | 4 +- pkg/browser/test/index.ts | 4 +- pkg/browser/tests/example.spec.ts | 8 +-- pkg/core/src/plugin.ts | 1 - pkg/core/test/visitor.ts | 34 ++++++------ pkg/ethereum/src/visitor.ts | 9 ++-- pkg/ethereum/test/e2e.ts | 1 - pkg/http/src/parser.ts | 24 ++++++--- pkg/http/src/plugins.ts | 18 +++---- pkg/http/src/tokens.ts | 13 ++++- pkg/http/test/e2e.ts | 4 +- 13 files changed, 128 insertions(+), 103 deletions(-) diff --git a/pkg/browser/package.json b/pkg/browser/package.json index efa1ebc0..af88c249 100644 --- a/pkg/browser/package.json +++ b/pkg/browser/package.json @@ -1,46 +1,46 @@ { - "name": "@slangroom/browser", - "dependencies": { - "@slangroom/core": "workspace:*", - "@slangroom/http": "workspace:*" - }, - "version": "1.4.0", - "repository": "https://github.com/dyne/slangroom", - "license": "AGPL-3.0-only", - "type": "module", - "main": "./build/cjs/src/index.js", - "types": "./build/cjs/src/index.d.ts", - "exports": { - ".": { - "import": { - "types": "./build/esm/src/index.d.ts", - "default": "./build/esm/src/index.js" - }, - "require": { - "types": "./build/cjs/src/index.d.ts", - "default": "./build/cjs/src/index.js" - } - }, - "./*": { - "import": { - "types": "./build/esm/src/*.d.ts", - "default": "./build/esm/src/*.js" - }, - "require": { - "types": "./build/cjs/src/*.d.ts", - "default": "./build/cjs/src/*.js" - } - } - }, - "publishConfig": { - "access": "public" - }, - "devDependencies": { - "@playwright/test": "^1.39.0", - "@types/node": "^20.3.1", - "esbuild": "^0.18.4" - }, - "scripts": { - "build": "pnpm exec esbuild --bundle src/index.ts --outfile=public/slangroom.js --external:fs --external:path --external:crypto" - } + "name": "@slangroom/browser", + "dependencies": { + "@slangroom/core": "workspace:*", + "@slangroom/http": "workspace:*" + }, + "version": "1.4.0", + "repository": "https://github.com/dyne/slangroom", + "license": "AGPL-3.0-only", + "type": "module", + "main": "./build/cjs/src/index.js", + "types": "./build/cjs/src/index.d.ts", + "exports": { + ".": { + "import": { + "types": "./build/esm/src/index.d.ts", + "default": "./build/esm/src/index.js" + }, + "require": { + "types": "./build/cjs/src/index.d.ts", + "default": "./build/cjs/src/index.js" + } + }, + "./*": { + "import": { + "types": "./build/esm/src/*.d.ts", + "default": "./build/esm/src/*.js" + }, + "require": { + "types": "./build/cjs/src/*.d.ts", + "default": "./build/cjs/src/*.js" + } + } + }, + "publishConfig": { + "access": "public" + }, + "devDependencies": { + "@playwright/test": "^1.39.0", + "@types/node": "^20.3.1", + "esbuild": "^0.18.4" + }, + "scripts": { + "build": "pnpm exec esbuild --bundle src/index.ts --outfile=public/slangroom.js --external:fs --external:path --external:crypto" + } } diff --git a/pkg/browser/public/index.html b/pkg/browser/public/index.html index 341d1d6e..08ebd897 100644 --- a/pkg/browser/public/index.html +++ b/pkg/browser/public/index.html @@ -6,7 +6,7 @@

Test http

diff --git a/pkg/browser/src/index.ts b/pkg/browser/src/index.ts index 06fd6cc5..599fbace 100644 --- a/pkg/browser/src/index.ts +++ b/pkg/browser/src/index.ts @@ -1,5 +1,5 @@ -import { Slangroom } from "@slangroom/core"; -import { httpPlugins } from "@slangroom/http"; +import { Slangroom } from '@slangroom/core'; +import { httpPlugins } from '@slangroom/http'; const slangroom = new Slangroom(httpPlugins); // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/pkg/browser/test/index.ts b/pkg/browser/test/index.ts index 8db1cd84..ddc62579 100644 --- a/pkg/browser/test/index.ts +++ b/pkg/browser/test/index.ts @@ -1,3 +1,3 @@ -import test from 'ava' +import test from 'ava'; -test("make ava happpy", (t) => t.truthy(true)); +test('make ava happpy', (t) => t.truthy(true)); diff --git a/pkg/browser/tests/example.spec.ts b/pkg/browser/tests/example.spec.ts index 2f9dde37..ba288940 100644 --- a/pkg/browser/tests/example.spec.ts +++ b/pkg/browser/tests/example.spec.ts @@ -1,8 +1,10 @@ import { test, expect } from '@playwright/test'; test('check results of slangroom', async ({ page }) => { - await page.goto('http://localhost:8080/'); + await page.goto('http://localhost:8080/'); - // Expects page to have a heading with the name of Installation. - await expect(page.locator('#test1')).toContainText("did:dyne:sandbox.test:pEn78CGNEKvMR7DJQ1yvUVUpAHKzsBz45mQw3zD2js9"); + // Expects page to have a heading with the name of Installation. + await expect(page.locator('#test1')).toContainText( + 'did:dyne:sandbox.test:pEn78CGNEKvMR7DJQ1yvUVUpAHKzsBz45mQw3zD2js9' + ); }); diff --git a/pkg/core/src/plugin.ts b/pkg/core/src/plugin.ts index 440f8cef..e3fbffe6 100644 --- a/pkg/core/src/plugin.ts +++ b/pkg/core/src/plugin.ts @@ -259,7 +259,6 @@ export class PluginContextTest implements PluginContext { return new this(connect, {}); } - /** * @constructor */ diff --git a/pkg/core/test/visitor.ts b/pkg/core/test/visitor.ts index dbe5d4f8..fba4ec9f 100644 --- a/pkg/core/test/visitor.ts +++ b/pkg/core/test/visitor.ts @@ -26,24 +26,24 @@ test('generated ast is correct', async (t) => { bindings: new Map(), }, "connect to 'foo' and send address 'addr' and send contract 'contract' and read the ethereum balance": - { - openconnect: 'foo', - phrase: 'read the ethereum balance', - bindings: new Map([ - ['address', 'addr'], - ['contract', 'contract'], - ]), - }, + { + openconnect: 'foo', + phrase: 'read the ethereum balance', + bindings: new Map([ + ['address', 'addr'], + ['contract', 'contract'], + ]), + }, "open 'foo' and send address 'addr' and send contract 'contract' and read the ethereum balance and output into 'var'": - { - openconnect: 'foo', - phrase: 'read the ethereum balance', - bindings: new Map([ - ['address', 'addr'], - ['contract', 'contract'], - ]), - into: 'var', - }, + { + openconnect: 'foo', + phrase: 'read the ethereum balance', + bindings: new Map([ + ['address', 'addr'], + ['contract', 'contract'], + ]), + into: 'var', + }, }; for (const [line, astWant] of Object.entries(cases)) { diff --git a/pkg/ethereum/src/visitor.ts b/pkg/ethereum/src/visitor.ts index 05cb914e..99a99376 100644 --- a/pkg/ethereum/src/visitor.ts +++ b/pkg/ethereum/src/visitor.ts @@ -6,10 +6,7 @@ import { type PhraseCst, } from '@slangroom/ethereum'; -import { - type CstNode, - type CstElement, -} from '@slangroom/deps/chevrotain'; +import { type CstNode, type CstElement } from '@slangroom/deps/chevrotain'; export enum EthereumRequestKind { EthereumNonce, @@ -80,7 +77,9 @@ class V extends CstVisitor { totalSupply() { return EthereumRequestKind.Erc20TotalSupply; } - id(ctx: any) { ctx; } + id(ctx: any) { + ctx; + } } const Visitor = new V(); diff --git a/pkg/ethereum/test/e2e.ts b/pkg/ethereum/test/e2e.ts index 26dd5522..37ad1ce3 100644 --- a/pkg/ethereum/test/e2e.ts +++ b/pkg/ethereum/test/e2e.ts @@ -93,5 +93,4 @@ Then print data } t.falsy(false); return; - }); diff --git a/pkg/http/src/parser.ts b/pkg/http/src/parser.ts index aeeb7bb5..f9a07372 100644 --- a/pkg/http/src/parser.ts +++ b/pkg/http/src/parser.ts @@ -1,5 +1,16 @@ import { CstParser, type IToken, type CstNode } from '@slangroom/deps/chevrotain'; -import { allTokens, Do, Get, Post, Patch, Put, Delete, Sequential, Parallel, Same } from '@slangroom/http'; +import { + allTokens, + Do, + Get, + Post, + Patch, + Put, + Delete, + Sequential, + Parallel, + Same, +} from '@slangroom/http'; export type PhraseCst = CstNode & { children: { @@ -13,11 +24,12 @@ export type KindCst = CstNode & { }; export type MethodCst = CstNode & { - children: { Get: [IToken] } - | { Post: [IToken] } - | { Patch: [IToken] } - | { Put: [IToken] } - | { Delete: [IToken] }; + children: + | { Get: [IToken] } + | { Post: [IToken] } + | { Patch: [IToken] } + | { Put: [IToken] } + | { Delete: [IToken] }; }; const Parser = new (class extends CstParser { diff --git a/pkg/http/src/plugins.ts b/pkg/http/src/plugins.ts index 706b009b..3baa28f2 100644 --- a/pkg/http/src/plugins.ts +++ b/pkg/http/src/plugins.ts @@ -39,12 +39,12 @@ export const execute = async ( const headers = ctx.get('headers'); if (kind === RequestKind.Default) { let error: any = null; - let requestData: AxiosRequestConfig = { + const requestData: AxiosRequestConfig = { url: url, method: method, data: ctx.get('object') as any, - } - if(headers) { + }; + if (headers) { requestData['headers'] = headers as any; } const req = await request(requestData).catch((e) => (error = e)); @@ -62,12 +62,12 @@ export const execute = async ( // JsonableObject) const objects = ctx.fetch('object') as JsonableArray; for (const [i, u] of urls.entries()) { - let requestData: AxiosRequestConfig = { + const requestData: AxiosRequestConfig = { url: u, method: method, data: objects[i], - } - if(headers) { + }; + if (headers) { requestData['headers'] = headers as any; } reqs.push(request(requestData)); @@ -76,12 +76,12 @@ export const execute = async ( // TODO: check type of body (needs to be JsonableObject) const object = ctx.fetch('object') as JsonableArray; for (const u of urls) { - let requestData: AxiosRequestConfig = { + const requestData: AxiosRequestConfig = { url: u, method: method, data: object, - } - if(headers) { + }; + if (headers) { requestData['headers'] = headers as any; } reqs.push(request(requestData)); diff --git a/pkg/http/src/tokens.ts b/pkg/http/src/tokens.ts index f4e6a173..f14f8293 100644 --- a/pkg/http/src/tokens.ts +++ b/pkg/http/src/tokens.ts @@ -46,4 +46,15 @@ export const Sequential = createToken({ pattern: /sequential/i, }); -export const allTokens = [Whitespace, Get, Post, Patch, Put, Delete, Parallel, Sequential, Same, Do]; +export const allTokens = [ + Whitespace, + Get, + Post, + Patch, + Put, + Delete, + Parallel, + Sequential, + Same, + Do, +]; diff --git a/pkg/http/test/e2e.ts b/pkg/http/test/e2e.ts index 632f2262..d99e4d16 100644 --- a/pkg/http/test/e2e.ts +++ b/pkg/http/test/e2e.ts @@ -74,8 +74,8 @@ Then print data data: { auth_url: 'http://localhost/auth-required', headers: { - authorization: 'Basic Auth test' - } + authorization: 'Basic Auth test', + }, }, }); t.deepEqual(