Skip to content

Commit c4126cc

Browse files
authored
chore(contributing-guide): update contributing guide with latest philosophy on rosetta fixtures (#18838)
Updates the contributing guide with more information surrounding README example philosophy, since we recently turned on strict mode for all modules (thus all README examples must compile). ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 80ef69f commit c4126cc

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

CONTRIBUTING.md

+18-15
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ let us know if it's not up-to-date (even better, submit a PR with your correcti
2222
- [Step 5: Merge](#step-5-merge)
2323
- [Breaking Changes](#breaking-changes)
2424
- [Documentation](#documentation)
25-
- [rosetta](#rosetta)
25+
- [Rosetta](#rosetta)
2626
- [Tools](#tools)
2727
- [Linters](#linters)
2828
- [cfn2ts](#cfn2ts)
@@ -217,6 +217,8 @@ Work your magic. Here are some guidelines:
217217
Watch out for their error messages and adjust your code accordingly.
218218
* Every change requires a unit test
219219
* If you change APIs, make sure to update the module's README file
220+
* When you add new examples to the module's README file, you must also ensure they compile - the PR build will fail
221+
if they do not. To learn more about how to ensure that they compile, see [Documentation](#documentation).
220222
* Try to maintain a single feature/bugfix per pull request. It's okay to introduce a little bit of housekeeping
221223
changes along the way, but try to avoid conflating multiple features. Eventually, all these are going to go into a
222224
single commit, so you can use that to frame your scope.
@@ -508,7 +510,7 @@ the README for the `aws-ec2` module - https://docs.aws.amazon.com/cdk/api/latest
508510

509511
### Rosetta
510512

511-
The README file contains code snippets written as typescript code. Code snippets typed in fenced code blocks
513+
The README file contains code snippets written as typescript code. Code snippets typed in fenced code blocks
512514
(such as `` ```ts ``) will be automatically extracted, compiled and translated to other languages when the
513515
during the [pack](#pack) step. We call this feature 'rosetta'.
514516

@@ -541,11 +543,12 @@ When no fixture is specified, the fixture with the name
541543
`rosetta/default.ts-fixture` will be used if present. `nofixture` can be used to
542544
opt out of that behavior.
543545

544-
In an `@example` block, which is unfenced, the first line of the example can
545-
contain three slashes to achieve the same effect:
546+
In an `@example` block, which is unfenced, additional information pertaining to
547+
the example can be provided via the `@exampleMetadata` tag:
546548

547549
```
548550
/**
551+
* @exampleMetadata fixture=with-bucket
549552
* @example
550553
* /// fixture=with-bucket
551554
* bucket.addLifecycleTransition({ ...props });
@@ -582,21 +585,21 @@ cases where some of those do not apply - good judgement is to be applied):
582585
// ...rest of the example...
583586
```
584587

585-
- Within `.ts-fixture` files, make use of `declare` statements instead of
586-
writing a compatible value (this will make your fixtures more durable):
588+
- Make use of `declare` statements directly in examples for values that are
589+
necessary for compilation but unimportant to the example:
587590

588591
```ts
589-
// An hypothetical 'rosetta/default.ts-fixture' file in `@aws-cdk/core`
590-
import * as kms from '@aws-cdk/aws-kms';
591-
import * as s3 from '@aws-cdk/aws-s3';
592-
import { StackProps } from '@aws-cdk/core';
593-
594-
declare const kmsKey: kms.IKey;
595-
declare const bucket: s3.Bucket;
596-
597-
declare const props: StackProps;
592+
// An example about adding a stage to a pipeline in the @aws-cdk/pipelines library
593+
declare const pipeline: pipelines.CodePipeline;
594+
declare const myStage: Stage;
595+
pipeline.addStage(myStage);
598596
```
599597

598+
- Utilize the `default.ts-fixture` that already exists rather than writing new
599+
`.ts-fixture` files. This is because values stored in `.ts-fixture` files do
600+
not surface to the examples visible in the docs, so while they help successful
601+
compilation, they do not help users understand the example.
602+
600603
## Tools (Advanced)
601604

602605
### scripts/foreach.sh

0 commit comments

Comments
 (0)