fixing linting for doc-gen

pull/4771/head
lianahus 7 months ago
parent e5be10a5d3
commit 866e58c099
  1. 6
      apps/doc-gen/src/app/docgen-client.ts
  2. 72
      apps/doc-gen/src/app/docgen/common/properties.ts
  3. 7
      apps/doc-gen/src/app/docgen/templates.ts
  4. 18
      apps/doc-gen/src/app/docgen/utils/memoized-getter.ts
  5. 8
      apps/doc-gen/src/app/docgen/utils/natspec.ts
  6. 2
      apps/doc-gen/src/app/docgen/utils/normalizeContractPath.ts

@ -17,7 +17,7 @@ export class DocGenClient extends PluginClient {
public docs: string[] = []
private fileName: string = ''
private contractPath: string = ''
constructor() {
super()
this.eventEmitter = new EventEmitter()
@ -30,7 +30,7 @@ export class DocGenClient extends PluginClient {
async setListeners() {
this.currentTheme = await this.call('theme', 'currentTheme')
this.on('theme', 'themeChanged', (theme: any) => {
this.currentTheme = theme
this.eventEmitter.emit('themeChanged', this.currentTheme)
@ -50,7 +50,7 @@ export class DocGenClient extends PluginClient {
}
const segmentedPathList = normalizeContractPath(fileName)
this.fileName = segmentedPathList[segmentedPathList.length - 1]
this.contractPath = segmentedPathList[0]
this.contractPath = segmentedPathList[0]
this.eventEmitter.emit('compilationFinished', this.build, this.fileName)
})
}

@ -36,47 +36,47 @@ export function fullName ({ item, contract }: DocItemContext): string {
export function signature ({ item }: DocItemContext): string | undefined {
switch (item.nodeType) {
case 'ContractDefinition':
return undefined;
case 'FunctionDefinition': {
const { kind, name } = item;
const params = item.parameters.parameters;
const returns = item.returnParameters.parameters;
const head = (kind === 'function' || kind === 'freeFunction') ? [kind, name].join(' ') : kind;
const res = [
`${head}(${params.map(formatVariable).join(', ')})`,
item.visibility,
];
if (item.stateMutability !== 'nonpayable') {
res.push(item.stateMutability);
}
if (item.virtual) {
res.push('virtual');
}
if (returns.length > 0) {
res.push(`returns (${returns.map(formatVariable).join(', ')})`);
}
return res.join(' ');
case 'ContractDefinition':
return undefined;
case 'FunctionDefinition': {
const { kind, name } = item;
const params = item.parameters.parameters;
const returns = item.returnParameters.parameters;
const head = (kind === 'function' || kind === 'freeFunction') ? [kind, name].join(' ') : kind;
const res = [
`${head}(${params.map(formatVariable).join(', ')})`,
item.visibility,
];
if (item.stateMutability !== 'nonpayable') {
res.push(item.stateMutability);
}
case 'EventDefinition': {
const params = item.parameters.parameters;
return `event ${item.name}(${params.map(formatVariable).join(', ')})`;
if (item.virtual) {
res.push('virtual');
}
case 'ErrorDefinition': {
const params = item.parameters.parameters;
return `error ${item.name}(${params.map(formatVariable).join(', ')})`;
if (returns.length > 0) {
res.push(`returns (${returns.map(formatVariable).join(', ')})`);
}
return res.join(' ');
}
case 'ModifierDefinition': {
const params = item.parameters.parameters;
return `modifier ${item.name}(${params.map(formatVariable).join(', ')})`;
}
case 'EventDefinition': {
const params = item.parameters.parameters;
return `event ${item.name}(${params.map(formatVariable).join(', ')})`;
}
case 'ErrorDefinition': {
const params = item.parameters.parameters;
return `error ${item.name}(${params.map(formatVariable).join(', ')})`;
}
case 'ModifierDefinition': {
const params = item.parameters.parameters;
return `modifier ${item.name}(${params.map(formatVariable).join(', ')})`;
}
case 'VariableDeclaration':
return formatVariable(item);
case 'VariableDeclaration':
return formatVariable(item);
}
}

@ -3,7 +3,7 @@ import { mapKeys } from './utils/map-keys';
import { DocItemContext } from './site';
import * as defaultProperties from './common/properties';
import * as themeHelpers from './themes/markdown/helpers'
import * as themeHelpers from './themes/markdown/helpers'
const common = require('./themes/markdown/common.hbs');
const contract = require('./themes/markdown/contract.hbs');
@ -45,7 +45,6 @@ export async function loadTemplates(defaultTheme: string, root: string, userTemp
properties: { ...defaultProperties },
};
// Add partials and helpers from all themes, prefixed with the theme name.
for (const [themeName, theme] of Object.entries(themes)) {
const addPrefix = (k: string) => `${themeName}/${k}`;
@ -86,7 +85,7 @@ async function readPartials() {
}
async function readHelpers(name: string) {
const helpers: Record<string, (...args: any[]) => any> = {};
for (const name in themeHelpers) {
@ -94,7 +93,7 @@ async function readHelpers(name: string) {
helpers[name] = themeHelpers[name];
}
}
return helpers;
}

@ -6,17 +6,17 @@ export function defineGetterMemoized<K extends keyof any, T, O extends { [k in K
enumerable: true,
get() {
switch (state) {
case 'done':
return value;
case 'done':
return value;
case 'doing':
throw new Error("Detected recursion");
case 'doing':
throw new Error("Detected recursion");
case 'todo':
state = 'doing';
value = getter();
state = 'done';
return value;
case 'todo':
state = 'doing';
value = getter();
state = 'done';
return value;
}
}
});

@ -34,10 +34,10 @@ export function parseNatspec(item: DocItemWithContext): NatSpec {
const docString = docSource !== undefined
? cleanUpDocstringFromSource(docSource)
: 'documentation' in item && item.documentation
? typeof item.documentation === 'string'
? item.documentation
: cleanUpDocstringFromSolc(item.documentation.text)
: '';
? typeof item.documentation === 'string'
? item.documentation
: cleanUpDocstringFromSolc(item.documentation.text)
: '';
const tagMatches = execAll(
/^(?:@(\w+|custom:[a-z][a-z-]*) )?((?:(?!^@(?:\w+|custom:[a-z][a-z-]*) )[^])*)/m,

@ -4,7 +4,7 @@ export function normalizeContractPath(contractPath: string): string[]{
const filename = paths[paths.length - 1]
let folders = ''
for (let i = 0; i < paths.length - 1; i++) {
if(i !== paths.length -1) {
if (i !== paths.length -1) {
folders += `${paths[i]}/`
}
}

Loading…
Cancel
Save