UNPKG

prettier-plugin-solidity

Version:

A Prettier Plugin for automatically formatting your Solidity code.

39 lines (26 loc) 1.21 kB
import { doc } from 'prettier'; import { NonterminalKind } from '@nomicfoundation/slang/cst'; import { sortFunctionAttributes } from '../slang-utils/sort-function-attributes.js'; import { getNodeMetadata, updateMetadata } from '../slang-utils/metadata.js'; import { FunctionTypeAttribute } from './FunctionTypeAttribute.js'; import type * as ast from '@nomicfoundation/slang/ast'; import type { AstPath, Doc } from 'prettier'; import type { PrintFunction, SlangNode } from '../types.d.ts'; const { line } = doc.builders; export class FunctionTypeAttributes implements SlangNode { readonly kind = NonterminalKind.FunctionTypeAttributes; comments; loc; items: FunctionTypeAttribute[]; constructor(ast: ast.FunctionTypeAttributes) { let metadata = getNodeMetadata(ast, true); this.items = ast.items.map((item) => new FunctionTypeAttribute(item)); metadata = updateMetadata(metadata, [this.items]); this.comments = metadata.comments; this.loc = metadata.loc; this.items = this.items.sort(sortFunctionAttributes); } print(path: AstPath<FunctionTypeAttributes>, print: PrintFunction): Doc { return path.map(print, 'items').map((item) => [line, item]); } }