Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Add feature to raise error for undocumented definitions #31

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ <h1>Facebook\HHAPIDoc\DocumentationBuilderContext::__construct()</h1>
Facebook\HHAPIDoc\Index $index,
IPathProvider</span><span class="hs-MarkupSuffix"><span class="hs-LessThanQuestionToken">&lt;?</span></span></span><span class="hs-ExpressionStatement"><span class="hs-BinaryExpression"><span class="hs-NameToken">string</span><span class="hs-GreaterThanToken">&gt; </span><span class="hs-VariableExpression"><span class="hs-VariableToken">$pathProvider</span></span></span></span><span class="hs-ExpressionStatement"><span class="hs-CommaToken">,
</span></span><span class="hs-ExpressionStatement"><span class="hs-NameToken"> bool </span></span><span class="hs-ExpressionStatement"><span class="hs-VariableExpression"><span class="hs-VariableToken">$syntaxHighlightingOn</span></span></span><span class="hs-ExpressionStatement"><span class="hs-CommaToken">,
</span></span><span class="hs-ExpressionStatement"><span class="hs-NameToken"> bool </span></span><span class="hs-ExpressionStatement"><span class="hs-VariableExpression"><span class="hs-VariableToken">$raiseErrorOnUndocumentedDefinitions</span></span></span><span class="hs-ExpressionStatement"><span class="hs-CommaToken">,
</span><span class="hs-SemicolonToken">);</span></span><span class="hs-EndOfFile"><span class="hs-EndOfFileToken"></span></span></span></code></pre>

<h2>Parameters</h2>
Expand All @@ -50,6 +51,7 @@ <h2>Parameters</h2>
<li><code>IPathProvider&lt;?string&gt; $pathProvider</code> a path provider that returns paths for documentables
that exist, or null for ones that don't.</li>
<li><code>bool $syntaxHighlightingOn</code></li>
<li><code>bool $raiseErrorOnUndocumentedDefinitions</code></li>
</ul>

</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ <h2>Interface Synopsis</h2>
<h3>Public Methods</h3>
<ul>
<li><a href="class.Facebook.HHAPIDoc.DocumentationBuilderContext.IsSyntaxHighlightingOn.html"><code>-&gt;IsSyntaxHighlightingOn(): bool</code></a></li>
<li><a href="class.Facebook.HHAPIDoc.DocumentationBuilderContext.__construct.html"><code>-&gt;__construct(OutputFormat $format, Index $index, \IPathProvider&lt;?string&gt; $pathProvider, bool $syntaxHighlightingOn)</code></a><br />
<li><a href="class.Facebook.HHAPIDoc.DocumentationBuilderContext.__construct.html"><code>-&gt;__construct(OutputFormat $format, Index $index, \IPathProvider&lt;?string&gt; $pathProvider, bool $syntaxHighlightingOn, bool $raiseErrorOnUndocumentedDefinitions)</code></a><br />
Create an instance</li>
<li><a href="class.Facebook.HHAPIDoc.DocumentationBuilderContext.getIndex.html"><code>-&gt;getIndex(): Index</code></a></li>
<li><a href="class.Facebook.HHAPIDoc.DocumentationBuilderContext.getOutputFormat.html"><code>-&gt;getOutputFormat(): OutputFormat</code></a></li>
<li><a href="class.Facebook.HHAPIDoc.DocumentationBuilderContext.getPathProvider.html"><code>-&gt;getPathProvider(): \IPathProvider&lt;?string&gt;</code></a></li>
<li><a href="class.Facebook.HHAPIDoc.DocumentationBuilderContext.shouldRaiseErrorOnUndocumentedDefinitions.html"><code>-&gt;shouldRaiseErrorOnUndocumentedDefinitions(): bool</code></a></li>
</ul>

</body>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<html>
<head>
<title>Facebook\HHAPIDoc\DocumentationBuilderContext::shouldRaiseErrorOnUndocumentedDefinitions</title>
<style>
/* Keywords */

.hs-FunctionToken,
.hs-NamespaceToken {
color: #c678dd;
}

/* Types */

.hs-SimpleTypeSpecifier .hs-StringToken {
color: #e5c07b;
}

.hs-ClassDeclaration .hs-NameToken {
color: #e5c07b;
}

/* Functions */

.hs-FunctionDeclaration .hs-NameToken {
color: #61afef;
}

/* Variables */

.hs-VariableToken {
color: #e06c75;
}
</style>
</head>
<body>
<h1>Facebook\HHAPIDoc\DocumentationBuilderContext::shouldRaiseErrorOnUndocumentedDefinitions()</h1>
<pre><code class="language-Hack"><span class="hs-Script"><span class="hs-MarkupSection"></span><span class="hs-ExpressionStatement"><span class="hs-NameToken">public </span></span><span class="hs-FunctionDeclaration"><span class="hs-FunctionDeclarationHeader"><span class="hs-FunctionToken">function </span><span class="hs-NameToken">shouldRaiseErrorOnUndocumentedDefinitions</span><span class="hs-LeftParenToken">(</span><span class="hs-RightParenToken">)</span><span class="hs-ColonToken">: </span><span class="hs-SimpleTypeSpecifier"><span class="hs-BoolToken">bool</span></span></span><span class="hs-SemicolonToken">;</span></span><span class="hs-EndOfFile"><span class="hs-EndOfFileToken"></span></span></span></code></pre>

<h2>Returns</h2>
<ul>
<li><code>bool</code></li>
</ul>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<html>
<head>
<title>Facebook\HHAPIDoc\Exceptions\UndocumentedDefinitionException::__construct</title>
<style>
/* Keywords */

.hs-FunctionToken,
.hs-NamespaceToken {
color: #c678dd;
}

/* Types */

.hs-SimpleTypeSpecifier .hs-StringToken {
color: #e5c07b;
}

.hs-ClassDeclaration .hs-NameToken {
color: #e5c07b;
}

/* Functions */

.hs-FunctionDeclaration .hs-NameToken {
color: #61afef;
}

/* Variables */

.hs-VariableToken {
color: #e06c75;
}
</style>
</head>
<body>
<h1>Facebook\HHAPIDoc\Exceptions\UndocumentedDefinitionException::__construct()</h1>
<pre><code class="language-Hack"><span class="hs-Script"><span class="hs-MarkupSection"></span><span class="hs-ExpressionStatement"><span class="hs-NameToken">public </span></span><span class="hs-FunctionDeclaration"><span class="hs-FunctionDeclarationHeader"><span class="hs-FunctionToken">function </span><span class="hs-ConstructToken">__construct</span><span class="hs-LeftParenToken">(
</span><span class="hs-ListItem"><span class="hs-ParameterDeclaration"><span class="hs-SimpleTypeSpecifier"><span class="hs-StringToken"> string </span></span><span class="hs-VariableToken">$fieldname</span></span><span class="hs-CommaToken">,
</span></span><span class="hs-ListItem"><span class="hs-ParameterDeclaration"><span class="hs-SimpleTypeSpecifier"><span class="hs-StringToken"> string </span></span><span class="hs-VariableToken">$fileName</span></span><span class="hs-CommaToken">,
</span></span><span class="hs-RightParenToken">)</span></span><span class="hs-SemicolonToken">;</span></span><span class="hs-EndOfFile"><span class="hs-EndOfFileToken"></span></span></span></code></pre>

<h2>Parameters</h2>
<ul>
<li><code>string $fieldname</code></li>
<li><code>string $fileName</code></li>
</ul>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<html>
<head>
<title>Facebook\HHAPIDoc\Exceptions\UndocumentedDefinitionException::getMessage</title>
<style>
/* Keywords */

.hs-FunctionToken,
.hs-NamespaceToken {
color: #c678dd;
}

/* Types */

.hs-SimpleTypeSpecifier .hs-StringToken {
color: #e5c07b;
}

.hs-ClassDeclaration .hs-NameToken {
color: #e5c07b;
}

/* Functions */

.hs-FunctionDeclaration .hs-NameToken {
color: #61afef;
}

/* Variables */

.hs-VariableToken {
color: #e06c75;
}
</style>
</head>
<body>
<h1>Facebook\HHAPIDoc\Exceptions\UndocumentedDefinitionException::getMessage()</h1>
<pre><code class="language-Hack"><span class="hs-Script"><span class="hs-MarkupSection"></span><span class="hs-ExpressionStatement"><span class="hs-NameToken">public </span></span><span class="hs-FunctionDeclaration"><span class="hs-FunctionDeclarationHeader"><span class="hs-FunctionToken">function </span><span class="hs-NameToken">getMessage</span><span class="hs-LeftParenToken">(</span><span class="hs-RightParenToken">)</span><span class="hs-ColonToken">: </span><span class="hs-SimpleTypeSpecifier"><span class="hs-StringToken">string</span></span></span><span class="hs-SemicolonToken">;</span></span><span class="hs-EndOfFile"><span class="hs-EndOfFileToken"></span></span></span></code></pre>

<h2>Returns</h2>
<ul>
<li><code>string</code></li>
</ul>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<html>
<head>
<title>Facebook\HHAPIDoc\Exceptions\UndocumentedDefinitionException</title>
<style>
/* Keywords */

.hs-FunctionToken,
.hs-NamespaceToken {
color: #c678dd;
}

/* Types */

.hs-SimpleTypeSpecifier .hs-StringToken {
color: #e5c07b;
}

.hs-ClassDeclaration .hs-NameToken {
color: #e5c07b;
}

/* Functions */

.hs-FunctionDeclaration .hs-NameToken {
color: #61afef;
}

/* Variables */

.hs-VariableToken {
color: #e06c75;
}
</style>
</head>
<body>
<h1>Facebook\HHAPIDoc\Exceptions\UndocumentedDefinitionException</h1>
<p>Exception thrown on undocumented definition</p>
<h2>Interface Synopsis</h2>
<pre><code class="language-Hack"><span class="hs-Script"><span class="hs-MarkupSection"></span><span class="hs-NamespaceDeclaration"><span class="hs-NamespaceToken">namespace </span><span class="hs-QualifiedName"><span class="hs-ListItem"><span class="hs-NameToken">Facebook</span><span class="hs-BackslashToken">\</span></span><span class="hs-ListItem"><span class="hs-NameToken">HHAPIDoc</span><span class="hs-BackslashToken">\</span></span><span class="hs-ListItem"><span class="hs-NameToken">Exceptions</span></span></span><span class="hs-NamespaceEmptyBody"><span class="hs-SemicolonToken">;
</span></span></span><span class="hs-ClassishDeclaration"><span class="hs-FinalToken">
final </span><span class="hs-ClassToken">class </span><span class="hs-NameToken">UndocumentedDefinitionException </span><span class="hs-ExtendsToken">extends </span><span class="hs-ListItem"><span class="hs-SimpleTypeSpecifier"><span class="hs-QualifiedName"><span class="hs-ListItem"><span class="hs-BackslashToken">\</span></span><span class="hs-ListItem"><span class="hs-NameToken">Exception </span></span></span></span></span><span class="hs-ClassishBody"><span class="hs-LeftBraceToken">{</span><span class="hs-ErrorSyntax"><span class="hs-DotDotDotToken">...</span></span><span class="hs-RightBraceToken">}</span></span></span><span class="hs-EndOfFile"><span class="hs-EndOfFileToken"></span></span></span></code></pre>

<h3>Public Methods</h3>
<ul>
<li><a href="class.Facebook.HHAPIDoc.Exceptions.UndocumentedDefinitionException.__construct.html"><code>-&gt;__construct(string $fieldname, string $fileName)</code></a></li>
<li><a href="class.Facebook.HHAPIDoc.Exceptions.UndocumentedDefinitionException.getMessage.html"><code>-&gt;getMessage(): string</code></a></li>
</ul>

</body>
</html>
1 change: 1 addition & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ <h2>Classes</h2>
<li><a href="class.Facebook.HHAPIDoc.DocBlock.DocBlock.html">Facebook\HHAPIDoc\DocBlock\DocBlock</a></li>
<li><a href="class.Facebook.HHAPIDoc.DocumentationBuilder.html">Facebook\HHAPIDoc\DocumentationBuilder</a></li>
<li><a href="class.Facebook.HHAPIDoc.DocumentationBuilderContext.html">Facebook\HHAPIDoc\DocumentationBuilderContext</a></li>
<li><a href="class.Facebook.HHAPIDoc.Exceptions.UndocumentedDefinitionException.html">Facebook\HHAPIDoc\Exceptions\UndocumentedDefinitionException</a></li>
<li><a href="class.Facebook.HHAPIDoc.GeneratorCLI.html">Facebook\HHAPIDoc\GeneratorCLI</a></li>
<li><a href="class.Facebook.HHAPIDoc.IndexDocumentBuilder.html">Facebook\HHAPIDoc\IndexDocumentBuilder</a></li>
<li><a href="class.Facebook.HHAPIDoc.IndexedPathProvider.html">Facebook\HHAPIDoc\IndexedPathProvider</a></li>
Expand Down
18 changes: 12 additions & 6 deletions src/DocumentationBuilder.hh
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,15 @@ class DocumentationBuilder {
protected function getDocumentationBody(
Documentable $documentable,
): string {
$docs = DocBlock\DocBlock::nullable(
$documentable['definition']->getDocComment(),
);
$ctx = $this->getContext();
$definition = $documentable['definition'];
$docs = DocBlock\DocBlock::nullable($definition->getDocComment());
if ($docs === null && $ctx->shouldRaiseErrorOnUndocumentedDefinitions()) {
throw new Exceptions\UndocumentedDefinitionException(
$definition->getName(),
$definition->getFileName(),
);
}
$md = $this->getPageSections()
|> Vec\map($$, $s ==> (new $s($ctx, $documentable, $docs))->getMarkdown())
|> Vec\filter_nulls($$)
Expand All @@ -118,7 +123,7 @@ class DocumentationBuilder {
$ast = Markdown\parse($parser_ctx, $md);

$render_ctx = (new MarkdownExt\RenderContext())
->setOutputFormat($this->getContext()->getOutputFormat())
->setOutputFormat($ctx->getOutputFormat())
->setDocumentable($documentable)
->setPathProvider(
new IndexedPathProvider(
Expand All @@ -130,9 +135,10 @@ class DocumentationBuilder {
new MarkdownExt\AutoLinkifyFilter(),
);
if ($ctx->IsSyntaxHighlightingOn()) {
$render_ctx = $render_ctx->appendFilters(new MarkdownExt\SyntaxHighlightingFilter());
$render_ctx =
$render_ctx->appendFilters(new MarkdownExt\SyntaxHighlightingFilter());
}
switch ($this->getContext()->getOutputFormat()) {
switch ($ctx->getOutputFormat()) {
case OutputFormat::MARKDOWN:
$renderer = new Markdown\MarkdownRenderer($render_ctx);
break;
Expand Down
6 changes: 6 additions & 0 deletions src/DocumentationBuilderContext.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class DocumentationBuilderContext {
private Index $index,
private IPathProvider<?string> $pathProvider,
private bool $syntaxHighlightingOn,
private bool $raiseErrorOnUndocumentedDefinitions,
) {
}

Expand All @@ -48,4 +49,9 @@ class DocumentationBuilderContext {
return $this->syntaxHighlightingOn;
}

/** @selfdocumenting */
public function shouldRaiseErrorOnUndocumentedDefinitions(): bool {
return $this->raiseErrorOnUndocumentedDefinitions;
}

}
35 changes: 35 additions & 0 deletions src/Exceptions/UndocumentedDefinitionException.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?hh // strict
/*
* Copyright (c) 2018-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

namespace Facebook\HHAPIDoc\Exceptions;

/**
* Exception thrown on undocumented definition
*/
final class UndocumentedDefinitionException extends \Exception {

<<__Override>>
public function __construct(
private string $fieldname,
private string $fileName,
) {
parent::__construct();
}

<<__Override>>
public function getMessage(): string {
return "Error while generating documentation: ".
"Undocumented definition '".
$this->fieldname.
"' found ".
"at path: ".
$this->fileName."\n";
}
}
Loading