Skip to content
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

aio + docs/api: implement content checks #22759

Closed

Conversation

petebacondarwin
Copy link
Member

@petebacondarwin petebacondarwin commented Mar 14, 2018

This PR adds a new dgeni processor checkContentRules, which will enable us to write rules about how the content should appear. We then implement two actual rules:

  • prevent any headings in @description blocks and only allow h3 headings in @usageNotes blocks
  • prevent single character parameter names

Since this produces a large number of errors the checkContentRules.failOnContentErrors is not set to true. But we can do this later once the documentation content has been cleaned up.

Further we can add or adjust these rules going forward to ensure more documentation consistency.

Closes #22137
Closes #22682

@petebacondarwin petebacondarwin added action: review The PR is still awaiting reviews from at least one requested reviewer comp: aio target: major This PR is targeted for the next major release labels Mar 14, 2018
@mary-poppins
Copy link

You can preview 01b2a5e at https://pr22759-01b2a5e.ngbuilds.io/.

* To creeate a rule that will only allow level 3 headings:
*
* ```
* const rule = createrNoMarkdownHeadingRule(1, 2, '4,');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

@petebacondarwin petebacondarwin added this to REVIEW in docs-infra Mar 14, 2018
@mary-poppins
Copy link

You can preview 19e89ba at https://pr22759-19e89ba.ngbuilds.io/.

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about non-markdown headings (e.g. <h1>Haxx</h1>)?

if (!disallowedHeadings.length) {
disallowedHeadings.push('#{1,}');
}
const regex = new RegExp(`^ ?(${disallowedHeadings.join('|')}) +.*$`, 'mg');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there are 2+ leading whitespaces?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, good question. According to the CommonMark spec:

The opening # character may be indented 0-3 spaces.

I will fix this.

*
* The processor will run each rule function against each matching property of each matching doc.
*
* An example rule might look like:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"A totally made-up example..." 😛

* [property]: Array<(doc: Document, property: string, value: any) => string|undefined>
* }
* }
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

$runBefore: ['processing-docs'],
$process(docs) {
const errors = [];
// Ensure that we have ruleFns for all regex rules
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what this comment refers to 😕

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh! From a previous incarnation of the algorithm, which I abandoned.

@petebacondarwin
Copy link
Member Author

petebacondarwin commented Mar 14, 2018

What about non-markdown headings (e.g. <h1>Haxx</h1>)?

My view is that we let the authors override anything by using HTML directly.
This is the backdoor that stops us having to change the rules every time some DevRel person insists that we allow them to do a "one-off" :-)

This processor will enable us to write rules about
how the content should appear, such as:

* no headings in markdown content
* only one sentence per line
* no single character parameter names
* etc.
This content rule can check what markdown headings
appear in content properties.
* No headings are allowed in `description` and `shortDescription`
* Only heading level 3 is allowed in `usageNotes`
This rule can be used to ensure that properties contain a minimum
number of characters.
@mary-poppins
Copy link

You can preview d64e868 at https://pr22759-d64e868.ngbuilds.io/.

@petebacondarwin
Copy link
Member Author

@gkalpak PTAL

Copy link
Contributor

@IgorMinar IgorMinar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't tell from this code if this will results in warnings or errors, but since the build is green, I assume warnings. If that's the case then this LGTM.

@@ -0,0 +1,8 @@
module.exports = function createMinLengthRule(minLength) {
minLength = minLength || 2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should consider being a bit more aggressive and require at least 3 or 4 characters. I can't think of any variables that should be less than 4 chars, but we should test and see. I suggest we start with 4 and if we find legit usecases for variable names of length 3 then we can decrease it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about url :-P This occurs "lots" of times.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Others that occur in the current code:

  • p
  • req
  • fn
  • key
  • k
  • v
  • ctx
  • obj
  • id
  • el
  • cd
  • dir
  • c
  • cb
  • max
  • min
  • res
  • err
  • cdr
  • sw

I would say that setting the minimum size to 3 chars would be a reasonable compromise.

@IgorMinar IgorMinar added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Apr 12, 2018
@IgorMinar IgorMinar closed this in e0ae74d Apr 12, 2018
IgorMinar pushed a commit that referenced this pull request Apr 12, 2018
This content rule can check what markdown headings
appear in content properties.

PR Close #22759
IgorMinar pushed a commit that referenced this pull request Apr 12, 2018
* No headings are allowed in `description` and `shortDescription`
* Only heading level 3 is allowed in `usageNotes`

PR Close #22759
IgorMinar pushed a commit that referenced this pull request Apr 12, 2018
This rule can be used to ensure that properties contain a minimum
number of characters.

PR Close #22759
@petebacondarwin
Copy link
Member Author

Yes we can set the checkContentRules.failOnContentErrors flag to true to fail the build.

@petebacondarwin petebacondarwin deleted the aio-api-check-headings branch April 12, 2018 07:13
@petebacondarwin petebacondarwin removed this from REVIEW in docs-infra Apr 12, 2018
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 13, 2018
This processor will enable us to write rules about
how the content should appear, such as:

* no headings in markdown content
* only one sentence per line
* no single character parameter names
* etc.

PR Close angular#22759
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 13, 2018
This content rule can check what markdown headings
appear in content properties.

PR Close angular#22759
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 13, 2018
…2759)

* No headings are allowed in `description` and `shortDescription`
* Only heading level 3 is allowed in `usageNotes`

PR Close angular#22759
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 13, 2018
This rule can be used to ensure that properties contain a minimum
number of characters.

PR Close angular#22759
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 13, 2018
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 13, 2018
This processor will enable us to write rules about
how the content should appear, such as:

* no headings in markdown content
* only one sentence per line
* no single character parameter names
* etc.

PR Close angular#22759
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 13, 2018
This content rule can check what markdown headings
appear in content properties.

PR Close angular#22759
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 13, 2018
…2759)

* No headings are allowed in `description` and `shortDescription`
* Only heading level 3 is allowed in `usageNotes`

PR Close angular#22759
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 13, 2018
This rule can be used to ensure that properties contain a minimum
number of characters.

PR Close angular#22759
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 13, 2018
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 13, 2018
This processor will enable us to write rules about
how the content should appear, such as:

* no headings in markdown content
* only one sentence per line
* no single character parameter names
* etc.

PR Close angular#22759
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 13, 2018
This content rule can check what markdown headings
appear in content properties.

PR Close angular#22759
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 13, 2018
…2759)

* No headings are allowed in `description` and `shortDescription`
* Only heading level 3 is allowed in `usageNotes`

PR Close angular#22759
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 13, 2018
This rule can be used to ensure that properties contain a minimum
number of characters.

PR Close angular#22759
wKoza pushed a commit to wKoza/angular that referenced this pull request Apr 13, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

docs(api): avoid headings in decorators aio + docs/api: remove single character param names
5 participants