Skip to content

Throw warning when applies_to is empty #1245

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions docs/syntax/applies.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ discontinued 9.2.0
all
```

`all` and empty string mean generally available for all active versions
`all` means generally available for all active versions

```yaml
applies_to:
serverless: all
```

`all` and empty string can also be specified at a version level
`all` can also be specified at a version level

```yaml
applies_to:
stack: beta all
serverless: beta
```

Both are equivalent, note `all` just means we won't be rendering the version portion in the html.
Note `all` just means we won't be rendering the version portion in the HTML.


## Structured model
Expand Down
13 changes: 8 additions & 5 deletions src/Elastic.Markdown/Myst/FrontMatter/ApplicableTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,17 @@ public class ApplicableToConverter : IYamlTypeConverter

public object? ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
{
var warnings = new List<string>();
var applicableTo = new ApplicableTo();

if (parser.TryConsume<Scalar>(out var value))
{
if (string.IsNullOrWhiteSpace(value.Value))
return ApplicableTo.All;
{
warnings.Add("The 'applies_to' field is present but empty. No applicability will be assumed.");
return null;
}

if (string.Equals(value.Value, "all", StringComparison.InvariantCultureIgnoreCase))
return ApplicableTo.All;
}
Expand All @@ -134,10 +141,6 @@ public class ApplicableToConverter : IYamlTypeConverter
if (deserialized is not Dictionary<object, object?> { Count: > 0 } dictionary)
return null;


var applicableTo = new ApplicableTo();
var warnings = new List<string>();

var keys = dictionary.Keys.OfType<string>().ToArray();
var oldStyleKeys = keys.Where(k => k.StartsWith(':')).ToList();
if (oldStyleKeys.Count > 0)
Expand Down
8 changes: 8 additions & 0 deletions tests/authoring/Applicability/AppliesToFrontMatter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,11 @@
Stack=AppliesCollection.op_Explicit "ga 9.1.0",
Product=AppliesCollection.op_Explicit "coming 9.5, discontinued 9.7"
))

type ``parses empty applies_to as null`` () =
static let markdown = frontMatter """
applies_to:
"""
[<Fact>]
let ``does not render label`` () =
markdown |> appliesTo null

Check failure on line 196 in tests/authoring/Applicability/AppliesToFrontMatter.fs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Nullness warning: The types 'ApplicableTo' and 'ApplicableTo | null' do not have compatible nullability.

Check failure on line 196 in tests/authoring/Applicability/AppliesToFrontMatter.fs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Nullness warning: The types 'ApplicableTo' and 'ApplicableTo | null' do not have compatible nullability.

Check failure on line 196 in tests/authoring/Applicability/AppliesToFrontMatter.fs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Nullness warning: The types 'ApplicableTo' and 'ApplicableTo | null' do not have compatible nullability.

Check failure on line 196 in tests/authoring/Applicability/AppliesToFrontMatter.fs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Nullness warning: The types 'ApplicableTo' and 'ApplicableTo | null' do not have compatible nullability.

Check failure on line 196 in tests/authoring/Applicability/AppliesToFrontMatter.fs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Nullness warning: The types 'ApplicableTo' and 'ApplicableTo | null' do not have compatible nullability.

Check failure on line 196 in tests/authoring/Applicability/AppliesToFrontMatter.fs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Nullness warning: The types 'ApplicableTo' and 'ApplicableTo | null' do not have compatible nullability.
Loading