From 2b0281684a5247fcece134928319bd98af02d83b Mon Sep 17 00:00:00 2001 From: Defi Boy Date: Mon, 13 Jul 2020 13:24:48 +0100 Subject: [PATCH] prettier --- src/App.tsx | 2 +- src/AppContext.tsx | 7 +- src/utils/template.ts | 49 +++++++------ src/utils/utils.test.ts | 157 ++++++++++++++++++++-------------------- src/utils/utils.ts | 17 ++--- src/views/ErrorView.tsx | 5 +- 6 files changed, 117 insertions(+), 120 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 102620292f..757684ba68 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -47,7 +47,7 @@ const App = () => { await client.onload(); setClientInstance(client); console.log("Remix EthDoc Plugin has been loaded"); - await client.call('manager' as any, 'activatePlugin', "ethdoc-viewer") + await client.call("manager" as any, "activatePlugin", "ethdoc-viewer"); client.solidity.on( "compilationFinished", ( diff --git a/src/AppContext.tsx b/src/AppContext.tsx index 6e179ff2b5..05c17b5c90 100644 --- a/src/AppContext.tsx +++ b/src/AppContext.tsx @@ -1,10 +1,5 @@ import React from "react"; -import { - PluginApi, - IRemixApi, - Api, - PluginClient -} from "@remixproject/plugin"; +import { PluginApi, IRemixApi, Api, PluginClient } from "@remixproject/plugin"; import { ContractName, Documentation, PublishedSite } from "./types"; diff --git a/src/utils/template.ts b/src/utils/template.ts index a8c3b24d0b..7c5f472c94 100644 --- a/src/utils/template.ts +++ b/src/utils/template.ts @@ -23,7 +23,7 @@ export const htmlTemplate = (content: HTMLContent) => { ${content} -` +`; }; export const template = ( @@ -54,14 +54,14 @@ export const template = (
${ - functions.length === 0 - ? "No contract to display" - : renderHeader(name, contractDoc) - } + functions.length === 0 + ? "No contract to display" + : renderHeader(name, contractDoc) + } ${functions - .map( - (item) => ` + .map( + (item) => `
${item.name} - ${item.type}

${renderParameterDocumentation(item.inputs)} @@ -72,8 +72,8 @@ export const template = ( ${renderParameterDocumentation(item.outputs)} ` - ) - .join("\n")} + ) + .join("\n")}
`; @@ -82,7 +82,7 @@ const devMethodDocTemplate: Partial> = { author: (author: string) => `

Created By ${author}

`, details: (details: string) => `

${details}

`, return: (value: string) => `

Return : ${value}

`, - notice: (notice: string) => notice ? `

${notice}

` : '', + notice: (notice: string) => (notice ? `

${notice}

` : ""), // returns: () => '', // Implemented by getParams() params: () => "", // Implemented by getParams() }; @@ -93,7 +93,7 @@ export const renderHeader = ( ) => `

${name} ${ contractDoc.title ? `: ${contractDoc.title}` : "" - }

+} ${contractDoc.notice ? `

${contractDoc.notice}

` : ""} @@ -104,9 +104,10 @@ export const renderHeader = ( export const renderParameterDocumentation = ( parameters: ParameterDocumentation[] -) => `${ - parameters.length > 0 - ? ` +) => + `${ + parameters.length > 0 + ? `
@@ -115,25 +116,27 @@ export const renderParameterDocumentation = ( - ${parameters.map( - (output) => ` + ${parameters + .map( + (output) => `` - ).join("")} + ) + .join("")}
Name
${output.name} ${output.type} ${output.description}
` - : "

No parameters

" + : "

No parameters

" }`; export const getMethodDetails = (devMethod?: Partial) => { return !devMethod ? "

**Add Documentation for the method here**

" : Object.keys(devMethod) - .filter((key) => key !== "params") - .map((key) => { - return (devMethodDocTemplate as any)[key]((devMethod as any)[key]); - }) - .join("\n"); + .filter((key) => key !== "params") + .map((key) => { + return (devMethodDocTemplate as any)[key]((devMethod as any)[key]); + }) + .join("\n"); }; diff --git a/src/utils/utils.test.ts b/src/utils/utils.test.ts index 399a002a1b..144e248680 100644 --- a/src/utils/utils.test.ts +++ b/src/utils/utils.test.ts @@ -48,92 +48,89 @@ describe("Publisher tests", () => { expect(template).toBeDefined(); }); - test('getContractDoc', () => { - const template = getContractDoc( - 'Owner', - { - ...buildFakeArtifactWithComments(), - abi: [ - { - "inputs": [], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "oldOwner", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "newOwner", - "type": "address" - } - ], - "name": "OwnerSet", - "type": "event" + test("getContractDoc", () => { + const template = getContractDoc("Owner", { + ...buildFakeArtifactWithComments(), + abi: [ + { + inputs: [], + stateMutability: "nonpayable", + type: "constructor", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "oldOwner", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "newOwner", + type: "address", + }, + ], + name: "OwnerSet", + type: "event", + }, + { + inputs: [ + { + internalType: "address", + name: "newOwner", + type: "address", + }, + ], + name: "changeOwner", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "getOwner", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + ] as any, + devdoc: { + details: "Set & change owner", + methods: { + "changeOwner(address)": { + details: "Change owner", + params: { + newOwner: "address of new owner", + }, }, - { - "inputs": [ - { - "internalType": "address", - "name": "newOwner", - "type": "address" - } - ], - "name": "changeOwner", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" + constructor: { + details: "Set contract deployer as owner", }, - { - "inputs": [], - "name": "getOwner", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - } - ] as any, - devdoc: { - "details": "Set & change owner", - "methods": { - "changeOwner(address)": { - "details": "Change owner", - "params": { - "newOwner": "address of new owner" - } + "getOwner()": { + details: "Return owner address ", + returns: { + _0: "address of owner", }, - "constructor": { - "details": "Set contract deployer as owner" - }, - "getOwner()": { - "details": "Return owner address ", - "returns": { - "_0": "address of owner" - } - } }, - "title": "Owner" - } as any, - userdoc: { - "methods": {} - } as any - } - ) + }, + title: "Owner", + } as any, + userdoc: { + methods: {}, + } as any, + }); expect(template).toBeDefined(); - }) + }); }); describe("getFunctionDocumentation", () => { diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 3e02811e46..904ebf04c6 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -3,14 +3,10 @@ import { CompiledContract, FunctionDescription, ABIParameter, - ABIDescription + ABIDescription, } from "@remixproject/plugin"; -import { - FileName, - Documentation, - ContractName, -} from "../types"; +import { FileName, Documentation, ContractName } from "../types"; import { template } from "./template"; import { ContractDocumentation, @@ -42,8 +38,8 @@ export const getContractDoc = (name: string, contract: CompiledContract) => { const contractDoc: ContractDocumentation = getContractDocumentation(contract); const onlyFunctions = contract.abi.filter((item) => { - return item.type !== "event" - }) + return item.type !== "event"; + }); const functionsDocumentation = onlyFunctions.map((def: ABIDescription) => { if (def.type === "constructor") { @@ -51,7 +47,10 @@ export const getContractDoc = (name: string, contract: CompiledContract) => { // because "constructor" is a string and not a { notice } object for userdoc we need to do that const methodDoc = { ...(contract.devdoc.methods.constructor || {}), - notice: Object.keys(contract.userdoc.methods['constructor']).length > 0 ? contract.userdoc.methods['constructor'] as string : "", + notice: + Object.keys(contract.userdoc.methods.constructor).length > 0 + ? (contract.userdoc.methods.constructor as string) + : "", }; return getFunctionDocumentation(def, methodDoc); } else { diff --git a/src/views/ErrorView.tsx b/src/views/ErrorView.tsx index d85f965142..f1c4fdaf91 100644 --- a/src/views/ErrorView.tsx +++ b/src/views/ErrorView.tsx @@ -19,7 +19,10 @@ export const ErrorView: React.FC = () => {
Sorry, something unexpected happened.
Please raise an issue:{" "} - + Here