Skip to content

Commit

Permalink
Add more situations to the angle bracket test.
Browse files Browse the repository at this point in the history
Examples to demonstrate
bazelbuild#137.
  • Loading branch information
adam-azarchs authored and fmeum committed Jul 9, 2023
1 parent 9c597fc commit e3361ec
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 8 deletions.
62 changes: 59 additions & 3 deletions test/testdata/angle_bracket_test/golden.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@

Input file to test angle bracket bug (https://github.com/bazelbuild/skydoc/issues/186)

See https://github.com/bazelbuild/skydoc/issues/186,
https://github.com/bazelbuild/stardoc/issues/132,
and https://github.com/bazelbuild/stardoc/issues/137.

<Angle brackets> need to be escaped in some contexts.
They also need to _not_ be escaped when they're enclosed
in a `<code block>`.


<a id="my_anglebrac"></a>

## my_anglebrac

<pre>
my_anglebrac(<a href="#my_anglebrac-name">name</a>, <a href="#my_anglebrac-useless">useless</a>)
my_anglebrac(<a href="#my_anglebrac-name">name</a>, <a href="#my_anglebrac-also_useless">also_useless</a>, <a href="#my_anglebrac-useless">useless</a>)
</pre>

Rule with <brackets>
Expand All @@ -18,6 +27,7 @@ Rule with <brackets>
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="my_anglebrac-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="my_anglebrac-also_useless"></a>also_useless | Args with some formatted tags: <code>&lt;tag&gt;</code> | String | optional | `"1<<5"` |
| <a id="my_anglebrac-useless"></a>useless | Args with some tags: &lt;tag1&gt;, &lt;tag2&gt; | String | optional | `"Find <brackets>"` |


Expand Down Expand Up @@ -46,23 +56,69 @@ Information with <brackets>
## bracket_function

<pre>
bracket_function(<a href="#bracket_function-name">name</a>)
bracket_function(<a href="#bracket_function-param">param</a>, <a href="#bracket_function-md_string">md_string</a>)
</pre>

Dummy docstring with <brackets>.

This rule runs checks on <angle brackets>.

Sometimes, we have such things on their own, but they may
also appear in code blocks, like

```starlark
foo = "<thing>"
```


**PARAMETERS**


| Name | Description | Default Value |
| :------------- | :------------- | :------------- |
| <a id="bracket_function-name"></a>name | an arg with **formatted** docstring. | none |
| <a id="bracket_function-param"></a>param | an arg with **formatted** docstring, &lt;default&gt; by default. | `"<default>"` |
| <a id="bracket_function-md_string"></a>md_string | A markdown string. | `"`1<<10`"` |

**RETURNS**

some <angled> brackets

**DEPRECATED**

deprecated for <reasons> as well as `<reasons>`.


<a id="bracket_aspect"></a>

## bracket_aspect

<pre>
bracket_aspect(<a href="#bracket_aspect-name">name</a>, <a href="#bracket_aspect-brackets">brackets</a>)
</pre>

Aspect.

Sometimes, we want a code block like
```starlark
foo = "<brackets>"
```
which includes angle brackets.


**ASPECT ATTRIBUTES**


| Name | Type |
| :------------- | :------------- |
| deps| String |


**ATTRIBUTES**


| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="bracket_aspect-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="bracket_aspect-brackets"></a>brackets | Attribute with &lt;brackets&gt; | String | optional | `"<default>"` |


55 changes: 50 additions & 5 deletions test/testdata/angle_bracket_test/input.bzl
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
"""Input file to test angle bracket bug (https://github.com/bazelbuild/skydoc/issues/186)"""
"""Input file to test angle bracket bug (https://github.com/bazelbuild/skydoc/issues/186)
def bracket_function(name):
See https://github.com/bazelbuild/skydoc/issues/186,
https://github.com/bazelbuild/stardoc/issues/132,
and https://github.com/bazelbuild/stardoc/issues/137.
<Angle brackets> need to be escaped in some contexts.
They also need to _not_ be escaped when they're enclosed
in a `<code block>`.
"""

def bracket_function(param = "<default>", md_string = "`1<<10`"):
"""Dummy docstring with <brackets>.
This rule runs checks on <angle brackets>.
Sometimes, we have such things on their own, but they may
also appear in code blocks, like
```starlark
foo = "<thing>"
```
Args:
name: an arg with **formatted** docstring.
param: an arg with **formatted** docstring, <default> by default.
md_string: A markdown string.
Returns:
some <angled> brackets
Deprecated:
deprecated for <reasons> as well as `<reasons>`.
"""
_ignore = name # @unused
pass
return param or md_string

# buildifier: disable=unsorted-dict-items
bracketuse = provider(
Expand All @@ -37,5 +55,32 @@ my_anglebrac = rule(
doc = "Args with some tags: <tag1>, <tag2>",
default = "Find <brackets>",
),
"also_useless": attr.string(
doc = "Args with some formatted tags: `<tag>`",
default = "1<<5",
),
},
)

def _bracket_aspect_impl(ctx):
_ignore = [ctx] # @unused
return []

bracket_aspect = aspect(
implementation = _bracket_aspect_impl,
doc = """Aspect.
Sometimes, we want a code block like
```starlark
foo = "<brackets>"
```
which includes angle brackets.
""",
attr_aspects = ["deps"],
attrs = {
"brackets": attr.string(
doc = "Attribute with <brackets>",
default = "<default>",
),
},
)

0 comments on commit e3361ec

Please sign in to comment.