Skip to content

Commit fd78afb

Browse files
committed
Use simple documentation
1 parent fa6e593 commit fd78afb

File tree

5 files changed

+9
-11
lines changed

5 files changed

+9
-11
lines changed

packages/core/stylus/src/contract.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ test('contract with sorted traits', t => {
8080

8181
test('contract with documentation', t => {
8282
const Foo = new ContractBuilder('Foo');
83-
Foo.addDocumentationTag(`@custom:documentation`, 'some documentation');
83+
Foo.addDocumentation('Some documentation');
8484
t.snapshot(printContract(Foo));
8585
});
8686

packages/core/stylus/src/contract.test.ts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ Generated by [AVA](https://avajs.dev).
174174
175175
`// SPDX-License-Identifier: MIT␊
176176
// Compatible with OpenZeppelin Contracts for Stylus ^0.2.0-alpha.4␊
177-
// @custom:documentation some documentation␊
177+
//! Some documentation␊
178178
179179
#![cfg_attr(not(any(test, feature = "export-abi")), no_main)]␊
180180
extern crate alloc;␊
-5 Bytes
Binary file not shown.

packages/core/stylus/src/contract.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface Contract {
99
license: string;
1010
securityContact: string;
1111
name: Name;
12-
documentationTags: DocumentationTag[];
12+
documentations: string[];
1313
useClauses: UseClause[];
1414
implementedTraits: ImplementedTrait[];
1515
constants: Variable[];
@@ -82,7 +82,7 @@ export class ContractBuilder implements Contract {
8282
license = 'MIT';
8383
securityContact = '';
8484

85-
readonly documentationTags: DocumentationTag[] = [];
85+
readonly documentations: string[] = [];
8686

8787
private implementedTraitsMap: Map<string, ImplementedTrait> = new Map();
8888
private useClausesMap: Map<string, UseClause> = new Map();
@@ -210,10 +210,8 @@ export class ContractBuilder implements Contract {
210210
existingFn.attribute = attribute;
211211
}
212212

213-
addDocumentationTag(key: string, value: string) {
214-
// eslint-disable-next-line no-useless-escape
215-
if (!/^(@custom:)?[a-z][a-z\-]*$/.exec(key)) throw new Error(`Invalid documentation key: ${key}`);
216-
this.documentationTags.push({ key, value });
213+
addDocumentation(description: string) {
214+
this.documentations.push(description);
217215
}
218216

219217
addSecurityTag(securityContact: string) {

packages/core/stylus/src/print.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function printContract(contract: Contract): string {
1717
`// SPDX-License-Identifier: ${contract.license}`,
1818
`// Compatible with OpenZeppelin Contracts for Stylus ${compatibleContractsSemver}`,
1919
...(contract.securityContact ? ['', ...printSecurityTag(contract.securityContact)] : []),
20-
...printDocumentationTags(contract.documentationTags),
20+
...printDocumentation(contract.documentations),
2121
],
2222
[`#![cfg_attr(not(any(test, feature = "export-abi")), no_main)]`, `extern crate alloc;`],
2323
spaceBetween(
@@ -287,8 +287,8 @@ function printArgument(arg: Argument): string {
287287
}
288288
}
289289

290-
function printDocumentationTags(tags: DocumentationTag[]): string[] {
291-
return tags.map(({ key, value }) => `// ${key} ${value}`);
290+
function printDocumentation(documentations: string[]): string[] {
291+
return documentations.map(documentation => `//! ${documentation}`);
292292
}
293293

294294
function printSecurityTag(securityContact: string) {

0 commit comments

Comments
 (0)