prettier-plugin-solidity
Version:
A Prettier Plugin for automatically formatting your Solidity code.
42 lines (29 loc) • 1.31 kB
text/typescript
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 { ConstructorAttribute } from './ConstructorAttribute.js';
import type * as ast from '@nomicfoundation/slang/ast';
import type { AstPath, Doc, ParserOptions } from 'prettier';
import type { AstNode } from './types.d.ts';
import type { PrintFunction, SlangNode } from '../types.d.ts';
const { line } = doc.builders;
export class ConstructorAttributes implements SlangNode {
readonly kind = NonterminalKind.ConstructorAttributes;
comments;
loc;
items: ConstructorAttribute[];
constructor(ast: ast.ConstructorAttributes, options: ParserOptions<AstNode>) {
let metadata = getNodeMetadata(ast, true);
this.items = ast.items.map(
(item) => new ConstructorAttribute(item, options)
);
metadata = updateMetadata(metadata, [this.items]);
this.comments = metadata.comments;
this.loc = metadata.loc;
this.items = this.items.sort(sortFunctionAttributes);
}
print(path: AstPath<ConstructorAttributes>, print: PrintFunction): Doc {
return path.map(print, 'items').map((item) => [line, item]);
}
}