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[] = [] public docs: string[] = []
private fileName: string = '' private fileName: string = ''
private contractPath: string = '' private contractPath: string = ''
constructor() { constructor() {
super() super()
this.eventEmitter = new EventEmitter() this.eventEmitter = new EventEmitter()
@ -30,7 +30,7 @@ export class DocGenClient extends PluginClient {
async setListeners() { async setListeners() {
this.currentTheme = await this.call('theme', 'currentTheme') this.currentTheme = await this.call('theme', 'currentTheme')
this.on('theme', 'themeChanged', (theme: any) => { this.on('theme', 'themeChanged', (theme: any) => {
this.currentTheme = theme this.currentTheme = theme
this.eventEmitter.emit('themeChanged', this.currentTheme) this.eventEmitter.emit('themeChanged', this.currentTheme)
@ -50,7 +50,7 @@ export class DocGenClient extends PluginClient {
} }
const segmentedPathList = normalizeContractPath(fileName) const segmentedPathList = normalizeContractPath(fileName)
this.fileName = segmentedPathList[segmentedPathList.length - 1] this.fileName = segmentedPathList[segmentedPathList.length - 1]
this.contractPath = segmentedPathList[0] this.contractPath = segmentedPathList[0]
this.eventEmitter.emit('compilationFinished', this.build, this.fileName) 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 { export function signature ({ item }: DocItemContext): string | undefined {
switch (item.nodeType) { switch (item.nodeType) {
case 'ContractDefinition': case 'ContractDefinition':
return undefined; return undefined;
case 'FunctionDefinition': { case 'FunctionDefinition': {
const { kind, name } = item; const { kind, name } = item;
const params = item.parameters.parameters; const params = item.parameters.parameters;
const returns = item.returnParameters.parameters; const returns = item.returnParameters.parameters;
const head = (kind === 'function' || kind === 'freeFunction') ? [kind, name].join(' ') : kind; const head = (kind === 'function' || kind === 'freeFunction') ? [kind, name].join(' ') : kind;
const res = [ const res = [
`${head}(${params.map(formatVariable).join(', ')})`, `${head}(${params.map(formatVariable).join(', ')})`,
item.visibility, item.visibility,
]; ];
if (item.stateMutability !== 'nonpayable') { if (item.stateMutability !== 'nonpayable') {
res.push(item.stateMutability); res.push(item.stateMutability);
}
if (item.virtual) {
res.push('virtual');
}
if (returns.length > 0) {
res.push(`returns (${returns.map(formatVariable).join(', ')})`);
}
return res.join(' ');
} }
if (item.virtual) {
case 'EventDefinition': { res.push('virtual');
const params = item.parameters.parameters;
return `event ${item.name}(${params.map(formatVariable).join(', ')})`;
} }
if (returns.length > 0) {
case 'ErrorDefinition': { res.push(`returns (${returns.map(formatVariable).join(', ')})`);
const params = item.parameters.parameters;
return `error ${item.name}(${params.map(formatVariable).join(', ')})`;
} }
return res.join(' ');
}
case 'ModifierDefinition': { case 'EventDefinition': {
const params = item.parameters.parameters; const params = item.parameters.parameters;
return `modifier ${item.name}(${params.map(formatVariable).join(', ')})`; 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': case 'VariableDeclaration':
return formatVariable(item); return formatVariable(item);
} }
} }

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

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

@ -34,10 +34,10 @@ export function parseNatspec(item: DocItemWithContext): NatSpec {
const docString = docSource !== undefined const docString = docSource !== undefined
? cleanUpDocstringFromSource(docSource) ? cleanUpDocstringFromSource(docSource)
: 'documentation' in item && item.documentation : 'documentation' in item && item.documentation
? typeof item.documentation === 'string' ? typeof item.documentation === 'string'
? item.documentation ? item.documentation
: cleanUpDocstringFromSolc(item.documentation.text) : cleanUpDocstringFromSolc(item.documentation.text)
: ''; : '';
const tagMatches = execAll( const tagMatches = execAll(
/^(?:@(\w+|custom:[a-z][a-z-]*) )?((?:(?!^@(?:\w+|custom:[a-z][a-z-]*) )[^])*)/m, /^(?:@(\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] const filename = paths[paths.length - 1]
let folders = '' let folders = ''
for (let i = 0; i < paths.length - 1; i++) { for (let i = 0; i < paths.length - 1; i++) {
if(i !== paths.length -1) { if (i !== paths.length -1) {
folders += `${paths[i]}/` folders += `${paths[i]}/`
} }
} }

Loading…
Cancel
Save