-
Notifications
You must be signed in to change notification settings - Fork 885
[docs] adds optional capability to provide code examples in rules' metadata #3602
Conversation
docs/_layouts/rule.html
Outdated
@@ -5,6 +5,15 @@ | |||
{% if page.descriptionDetails %} | |||
{{page.descriptionDetails | markdownify}} | |||
{% endif %} | |||
|
|||
{% if page.codeExamples %} | |||
<h3>Code examples: </h3> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Code examples (default config)"
src/rules/curlyRule.ts
Outdated
@@ -72,6 +73,17 @@ export class Rule extends Lint.Rules.AbstractRule { | |||
type: "functionality", | |||
typescriptOnly: false, | |||
hasFix: true, | |||
codeExamples: { | |||
pass: dedent` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this also needs to support multiple examples for different configurations / options.
codeExamples: {
default: {
pass: "...",
fail: "...",
},
"ignore-same-line": { ... },
}
Or maybe just an array with an optional description per object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my limited experience with the doc portion of the codebase, I think an array would be simplest. So
codeExamples?: {
config: string; /* Or... ? */
pass: string;
fail: string;
description?: string; /* Optional for cases like example below */
}[]
I think an explicit config example would be a good idea from the doc user's perspective, but will probably cause some metadata bloat in some rules.
{
"rules": { "no-console": true }
}
[edit] forgot to include description
@ajafff I think this one is ready for further consideration when you find time. |
How can I help and add examples to all rules? Should I wait on the merged request and then open a fork and make a branch, or should I make a fork of this current branch in the fork of @aervin? |
@Shinigami92 I'd hold off on adding examples to old rules as these updates are still subject to change. Eventually, I think it'd be great to update the old rules with code examples like you suggest. You will need Ruby to build the docs locally. With yarn compile && yarn docs && bundle exec jekyll serve to ensure that changes in the source metadata are reflected in the Jekyll data. |
I will try this when I'm back home. Thx |
Here is an installation and how to run the docs in Windows (10):
maybe this can be placed in a file in the project to help other devs ^^ helpfull link: https://jekyllrb.com/docs/windows/ |
I have started to create some examples. You can track my changes here: |
@aervin You should respect the code-style of the file: But I don't know why @palantirtech, @ajafff or someone else can check the branch now and make an approved review so then others can add examples to other rules :) |
@Shinigami92 Can you please clarify, I'm not sure what you mean by "You should respect the code-style of the file"? And the link doesn't take me to a file or anything. |
@aervin fixed the link: I mean the file |
@Shinigami92 I did not make those changes directly. I'm thinking it's from compiling/rebuilding the docs (there's probably a |
@Shinigami92 Once we get confirmation on these doc updates, I'll make that a top priority. |
@suchanlee or @johnwiseheart can we squeeze this one in? I'm happy to make changes. |
@aervin thanks for your patience. I'll try to review this as soon as I can. |
docs/_sass/_base.scss
Outdated
background: transparent; | ||
} | ||
} | ||
& .code-example.pass { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the code style in this file suggests that & .
should be &.
and that there should be a new line before each of the blocks. same for &:
(applies to all code changes in this file)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand about the new lines, but there's a difference between & .code-example
and &.code-example
, isn't there? Still, I think the &
s are unnecessary here (the way they're being used). I'll just remove them entirely.
docs/_sass/_base.scss
Outdated
} | ||
} | ||
& .code-example.pass { | ||
background-color: #f1fff1 !important; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is !important
needed here and below?
if they're required, please leave a comment on why they're required. If not, remove.
Also, it would be awesome to have the color as a comment (e.g. light red
or light green
)
@@ -148,7 +148,7 @@ function buildSingleModuleDocumentation(documentation: IDocumentation, modulePat | |||
// tslint:disable-next-line:no-var-requires | |||
const module = require(modulePath); | |||
const DocumentedItem = module[documentation.exportName] as Documented; | |||
if (DocumentedItem != null && DocumentedItem.metadata != null) { | |||
if (DocumentedItem !== null && DocumentedItem.metadata !== null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd prefer that it stay as !=
instead of !==
. != null
checks for both undefined and null whereas with !==
we specify for null, which may not be the desired behavior. But happy to revisit if there's a good reason to change to !==
!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this was changed as a result of the doc-building process (a pass with --fix
maybe?). Anyway, I would never make these sorts of changes deliberately (in a PR).
docs/_layouts/rule.html
Outdated
{{ codeExample.pass | markdownify }} | ||
</div> | ||
{% if codeExample.fail %} | ||
<h5 style="color: #d14;">Fails</h5> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id prefer all styles in css and outside of markup
docs/_layouts/rule.html
Outdated
<h4>{{ codeExample.description }}</h4> | ||
{{ codeExample.config | markdownify }} | ||
<h5>Passes</h5> | ||
<div class="code-example pass"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one class naming rule I like is for "decorating" class names, in this case pass
and below fail
, is to preface them with -
(e.g. -pass
, -fail
) so that css rules for pass
or fail
wouldn't apply. By prefacing decorator class names with dashes, you know that it wouldn't be affected by other styles since all other styles for prefaced class names would be scoped to a particular class name.
is the above screenshot up to date? in particular, is all the text still green? (doesn't seem to be that way in the code) update: looks like all the headers are green for tslint docs. But it looks funky with the green header for |
That picture above is out of date @suchanlee. The latest push looks something like this: |
src/rules/curlyRule.ts
Outdated
@@ -72,6 +72,58 @@ export class Rule extends Lint.Rules.AbstractRule { | |||
type: "functionality", | |||
typescriptOnly: false, | |||
hasFix: true, | |||
codeExamples: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These code examples are going to end up taking a lot of space in the source files (good!). What are your thoughts on starting a precedent of putting them in a ruleName.examples.ts
file that just exports an object with examples?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JoshuaKGoldberg I had a similar concern myself. I think the separate file approach makes sense 👍 and will update the curly rule example.
@@ -0,0 +1,238 @@ | |||
GEM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be checked in to the repo? I'm not familiar with gem/gemfile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@suchanlee It looks like the bundler docs suggest checking in the lock file. But full disclosure, I'm no Ruby expert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @aervin! Super stoked to get this in.
Thanks for your help @suchanlee 👍 |
Np! |
@Shinigami92 You did a lot of great work updating the docs on your fork--any interest in opening a PR with those changes? |
PR checklist
Overview of change:
Adds optional capability to provide code examples (passing and failing) for a given rule.