-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docs: Extract code examples into separate files for linting #729
Comments
Hi Michael, first off thanks for opening an issue to discuss the proposal. I think this idea is valuable, I got bitten by this a few times already and having the same linting rules applied to the code snippets would help. I have a few questions though, mainly coming from my limited knowledge of MKDocs:
If the answer to number 2 is yes, then if we move forward with the idea, I'd prefer to have a separate PR for each utility: i.e. one PR that addresses all the examples in I've marked this as low priority because at the moment we are focusing on the other issues marked as high before we get to GA. With that said, after the points above have been discussed and agreed upon I'm open to review a PR from the community. |
It would be option 2, each example would have it’s own file. You might have shared examples, but a PR per page makes sense. |
@dreamorosi example PR is up #730 |
Thanks for the PR, but I still would like to clear all the other points before start to review:
Specifically I'd like to understand how/when we are going to actually lint these files. At the moment I don't have yet a clear picture aside from just splitting the files and if there's no linting then having multiple files just makes it harder to maintain. |
Linting would be hard if you are doing something too strict (like unused variables), but at least it should handle syntax errors, missing parameters etc.. |
@dreamorosi so far, i have already found a couple issues like the indents and the same yaml not being valid. One option could be to configure a more lenient tsconfig to focus on compile errors. However you might still run into errors like: |
Thanks for looking into it. I'd like to hear the opinion of the other maintainers as well since it seems that there's no clear-cut way and I'm not clear on whether the overhead of having many more files is worth the gain. Finally as I have mentioned in my first comment, this is a low priority ticket so please expect some delays in the responses. |
Sure, i get the delay, maybe discuss with the maintainers: The part that is frustrating to me is when an example does not have a valid syntax, or in the case of YAML not linted and has invalid indents. |
Thanks for opening this issue @michaelbrewer. This is an improvement that can potentially make sure our docs have better linted examples (which is a very good thing!). The team is currently busy with other units of work with higher priority for the short term (GA), and we'll discuss about this and get back to you once we have the padding. |
Sure thing already run a couple more issues in the docs. So i can either file issues for them or keep it fixed in the 1 PR #730 Bugs so far for Tracer docs:
|
Hi @michaelbrewer, I see value in the idea behind the proposal (extract the code snippet so we can apply some validation to them) and I agree with Sara, but at the moment we are extracting the files but I'm not seeing how do we actually lint/validate them. In a previous comment you mentioned that there could be an option to set up some lenient tsconfig:
If you're still interested in this, do you think you could make a proposal on how we should apply such linting? With that included in the PR we can see the results and close the circle (and so review/merge it). |
@dreamorosi I do have something for this locally, it will mean some small changes in the examples and for the |
Sure, the |
The issue is still current and a similar effort has been made in the Python's version of this library which might serve as inspiration. Before taking this on there are some points to discuss:
If anyone is interested in picking this up, please leave a comment here, then discuss your findings and proposed changes before opening a PR. |
And
@dreamorosi means
I agree to open new issues for
however to the issues the locations of the code snippets as separate files should be made explicit. Now for the location of the code snippets and where the eslint configuration for code snippets live i have some questions to make see below
@dreamorosi please note that the docs/snippets does not belong to the workspaces managed by monorepo . It would be an anti-pattern to use node_nodules and the eslint-config of the workspaces as file located here. Questions :
@dreamorosi if Questions 1,2 is an and also i agree with creating issues, concatenating the location of the files in the title (something like the following):
@dreamorosi if Questions 1,2 are NOT ok then
Please note Questions 1,2 are important because we need an other issue for improving the eslint configuration attributes which are See here background , lessons learned from the author of eslint himself: link to blog article The attributes like For the other points:
@dreamorosi for the rules i agree . I can use the same rules for code snippets that are used for the code under packages.
@dreamorosi ok i understand for the eslint rules. |
Correct.
Okay, I see your point. You are right.
It's okay, but please see my question below (*).
Yes. Question: should we make the new For example:
tracer.newFeature();
What do you think? Am I missing something? |
@dreamorosi yes , given in the Steps 1,2,3,4,5,6 described above in your comment, i understand that the lifetime of a code snippets follows the lifetime of the published code of workspace . And also i can reference in package.json the node_modules already installed for the workspace And also i can use the same eslint config file , located here that is used for the workspace . Please create the issues and mention explicit where the location of the code snippets should be for the following 4 PRs identified, so that i can start work on them:
|
@dreamorosi |
I have created two more issues:
The first one has already been taken care of and its corresponding PR merged (#1251). The second one is up for grabs once #1245 has also been merged. Once #1252's PR is merged, we can finally close this issue as complete. |
@dreamorosi new commit for #1245. When merged i can start with #1252 . |
It appears we had a regression when working on the Logger docs: #1253 Any chance you could fix it? |
@dreamorosi because we track in this issue the relative issues to code snippets there are some typescript compiler recommendations to improve the quality of code snippets. I have identified the following: where: import { MyCompanyLogFormatter } from './utils/formatters/MyCompanyLogFormatter'; can be solved by: // import { MyCompanyLogFormatter } from './utils/formatters/MyCompanyLogFormatter'; where: public async handler(_event: any, _context: any): Promise<void> {
// Persistent attributes added inside the handler will NOT be cached
// across invocations
if (event['special_key'] === '123456'){
...
}
...
} can be solved by: public async handler(_event: any, _context: any): Promise<void> {
// Persistent attributes added inside the handler will NOT be cached
// across invocations
if (_event['special_key'] === '123456'){
...
}
...
}
} where: export const handler = async (event: unknown, context: Context): Promise<void> => {
try {
...
} catch (err) {
...
// Example of returning an error response
return {
statusCode: 500,
body: `Internal Error - Please contact support and quote the following id: ${rootTraceId}`,
headers: { '_X_AMZN_TRACE_ID': rootTraceId },
};
}
}; can be solved by: export const handler = async (event: unknown, context: Context): Promise<INTRODUCE-SPECIFIC-TYPE>=> => {
try {
...
} catch (err) {
...
// Example of returning an error response
return {
statusCode: 500,
body: `Internal Error - Please contact support and quote the following id: ${rootTraceId}`,
headers: { '_X_AMZN_TRACE_ID': rootTraceId },
};
}
}; where: docs/snippets/tracer/disableCaptureResponseMethod.ts class Lambda implements LambdaInterface {
...
} can be solved by: import { LambdaInterface } from '@aws-lambda-powertools/commons'; where: export const handler = async (_event: any, _context: any): Promise<void> => {
const res; /* ... */
tracer.putMetadata('paymentResponse', res);
}; can be solved by: export const handler = async (_event: any, _context: any): Promise<void> => {
let res; /* ... */
tracer.putMetadata('paymentResponse', res);
}; |
With #1259 merged all the code snippets present in the documentation are now linted, this should help decrease the amount of typos/errors present in the docs. We can close this issue as complete. |
|
Description of the improvement
Summary of the proposal
Code examples should be extracted to allow for validation / linting to help prevent errors.
How, where did you look for information
See
Missing or unclear documentation
Improvement
docs/
folder, to allow for mkdocs to automatically pick it upRelated existing documentation
Related issues, RFCs
Example of documentation examples with errors in them:
The text was updated successfully, but these errors were encountered: