Skip to content

Commit

Permalink
check: Verify deprecated sidebar_current frontmatter is not present
Browse files Browse the repository at this point in the history
Closes #23
  • Loading branch information
bflad committed Dec 17, 2019
1 parent 38f5f11 commit 008c76c
Show file tree
Hide file tree
Showing 27 changed files with 241 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v0.3.0

ENHANCEMENTS

* check: Verify deprecated `sidebar_current` frontmatter is not present

# v0.2.0

ENHANCEMENTS
Expand Down
14 changes: 10 additions & 4 deletions check/frontmatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ type FrontMatterCheck struct {

// FrontMatterData represents the YAML frontmatter of Terraform Provider documentation.
type FrontMatterData struct {
Description *string `yaml:"description,omitempty"`
Layout *string `yaml:"layout,omitempty"`
PageTitle *string `yaml:"page_title,omitempty"`
Subcategory *string `yaml:"subcategory,omitempty"`
Description *string `yaml:"description,omitempty"`
Layout *string `yaml:"layout,omitempty"`
PageTitle *string `yaml:"page_title,omitempty"`
SidebarCurrent *string `yaml:"sidebar_current,omitempty"`
Subcategory *string `yaml:"subcategory,omitempty"`
}

// FrontMatterOptions represents configuration options for FrontMatter.
Expand All @@ -24,6 +25,7 @@ type FrontMatterOptions struct {
NoDescription bool
NoLayout bool
NoPageTitle bool
NoSidebarCurrent bool
NoSubcategory bool
RequireDescription bool
RequireLayout bool
Expand Down Expand Up @@ -63,6 +65,10 @@ func (check *FrontMatterCheck) Run(src []byte) error {
return fmt.Errorf("YAML frontmatter should not contain page_title")
}

if check.Options.NoSidebarCurrent && frontMatter.SidebarCurrent != nil {
return fmt.Errorf("YAML frontmatter should not contain sidebar_current")
}

if check.Options.NoSubcategory && frontMatter.Subcategory != nil {
return fmt.Errorf("YAML frontmatter should not contain subcategory")
}
Expand Down
15 changes: 15 additions & 0 deletions check/frontmatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@ subcategory: Example Subcategory
},
ExpectError: true,
},
{
Name: "no sidebar_current option",
Source: `
description: |-
Example description
layout: "example"
page_title: Example Page Title
sidebar_current: "example_resource"
subcategory: Example Subcategory
`,
Options: &FrontMatterOptions{
NoSidebarCurrent: true,
},
ExpectError: true,
},
{
Name: "no subcategory option",
Source: `
Expand Down
1 change: 1 addition & 0 deletions check/legacy_data_source_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func NewLegacyDataSourceFileCheck(opts *LegacyDataSourceFileOptions) *LegacyData
check.Options.FrontMatter = &FrontMatterOptions{}
}

check.Options.FrontMatter.NoSidebarCurrent = true
check.Options.FrontMatter.RequireDescription = true
check.Options.FrontMatter.RequireLayout = true
check.Options.FrontMatter.RequirePageTitle = true
Expand Down
6 changes: 6 additions & 0 deletions check/legacy_data_source_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ func TestLegacyDataSourceFileCheck(t *testing.T) {
Path: "data_source_invalid_frontmatter.html.markdown",
ExpectError: true,
},
{
Name: "invalid frontmatter with sidebar_current",
BasePath: "testdata/invalid-legacy-files",
Path: "data_source_with_sidebar_current.html.markdown",
ExpectError: true,
},
{
Name: "invalid frontmatter without layout",
BasePath: "testdata/invalid-legacy-files",
Expand Down
1 change: 1 addition & 0 deletions check/legacy_guide_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func NewLegacyGuideFileCheck(opts *LegacyGuideFileOptions) *LegacyGuideFileCheck
check.Options.FrontMatter = &FrontMatterOptions{}
}

check.Options.FrontMatter.NoSidebarCurrent = true
check.Options.FrontMatter.RequireDescription = true
check.Options.FrontMatter.RequireLayout = true
check.Options.FrontMatter.RequirePageTitle = true
Expand Down
6 changes: 6 additions & 0 deletions check/legacy_guide_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ func TestLegacyGuideFileCheck(t *testing.T) {
Path: "guide_invalid_frontmatter.html.markdown",
ExpectError: true,
},
{
Name: "invalid frontmatter with sidebar_current",
BasePath: "testdata/invalid-legacy-files",
Path: "guide_with_sidebar_current.html.markdown",
ExpectError: true,
},
{
Name: "invalid frontmatter without layout",
BasePath: "testdata/invalid-legacy-files",
Expand Down
1 change: 1 addition & 0 deletions check/legacy_index_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func NewLegacyIndexFileCheck(opts *LegacyIndexFileOptions) *LegacyIndexFileCheck
check.Options.FrontMatter = &FrontMatterOptions{}
}

check.Options.FrontMatter.NoSidebarCurrent = true
check.Options.FrontMatter.NoSubcategory = true
check.Options.FrontMatter.RequireDescription = true
check.Options.FrontMatter.RequireLayout = true
Expand Down
6 changes: 6 additions & 0 deletions check/legacy_index_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func TestLegacyIndexFileCheck(t *testing.T) {
Path: "index_with_subcategory.html.markdown",
ExpectError: true,
},
{
Name: "invalid frontmatter with sidebar_current",
BasePath: "testdata/invalid-legacy-files",
Path: "index_with_sidebar_current.html.markdown",
ExpectError: true,
},
{
Name: "invalid frontmatter without layout",
BasePath: "testdata/invalid-legacy-files",
Expand Down
1 change: 1 addition & 0 deletions check/legacy_resource_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func NewLegacyResourceFileCheck(opts *LegacyResourceFileOptions) *LegacyResource
check.Options.FrontMatter = &FrontMatterOptions{}
}

check.Options.FrontMatter.NoSidebarCurrent = true
check.Options.FrontMatter.RequireDescription = true
check.Options.FrontMatter.RequireLayout = true
check.Options.FrontMatter.RequirePageTitle = true
Expand Down
6 changes: 6 additions & 0 deletions check/legacy_resource_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ func TestLegacyResourceFileCheck(t *testing.T) {
Path: "resource_invalid_frontmatter.html.markdown",
ExpectError: true,
},
{
Name: "invalid frontmatter with sidebar_current",
BasePath: "testdata/invalid-legacy-files",
Path: "resource_with_sidebar_current.html.markdown",
ExpectError: true,
},
{
Name: "invalid frontmatter without layout",
BasePath: "testdata/invalid-legacy-files",
Expand Down
1 change: 1 addition & 0 deletions check/registry_data_source_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func NewRegistryDataSourceFileCheck(opts *RegistryDataSourceFileOptions) *Regist
}

check.Options.FrontMatter.NoLayout = true
check.Options.FrontMatter.NoSidebarCurrent = true

return check
}
Expand Down
6 changes: 6 additions & 0 deletions check/registry_data_source_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func TestRegistryDataSourceFileCheck(t *testing.T) {
Path: "data_source_with_layout.md",
ExpectError: true,
},
{
Name: "invalid frontmatter with sidebar_current",
BasePath: "testdata/invalid-registry-files",
Path: "data_source_with_sidebar_current.md",
ExpectError: true,
},
}

for _, testCase := range testCases {
Expand Down
1 change: 1 addition & 0 deletions check/registry_guide_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func NewRegistryGuideFileCheck(opts *RegistryGuideFileOptions) *RegistryGuideFil
}

check.Options.FrontMatter.NoLayout = true
check.Options.FrontMatter.NoSidebarCurrent = true
check.Options.FrontMatter.RequirePageTitle = true

return check
Expand Down
6 changes: 6 additions & 0 deletions check/registry_guide_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func TestRegistryGuideFileCheck(t *testing.T) {
Path: "guide_with_layout.md",
ExpectError: true,
},
{
Name: "invalid frontmatter with sidebar_current",
BasePath: "testdata/invalid-registry-files",
Path: "guide_with_sidebar_current.md",
ExpectError: true,
},
}

for _, testCase := range testCases {
Expand Down
1 change: 1 addition & 0 deletions check/registry_index_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func NewRegistryIndexFileCheck(opts *RegistryIndexFileOptions) *RegistryIndexFil
}

check.Options.FrontMatter.NoLayout = true
check.Options.FrontMatter.NoSidebarCurrent = true
check.Options.FrontMatter.NoSubcategory = true

return check
Expand Down
6 changes: 6 additions & 0 deletions check/registry_index_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func TestRegistryIndexFileCheck(t *testing.T) {
Path: "index_with_layout.md",
ExpectError: true,
},
{
Name: "invalid frontmatter with sidebar_current",
BasePath: "testdata/invalid-registry-files",
Path: "index_with_sidebar_current.md",
ExpectError: true,
},
{
Name: "invalid frontmatter with subcategory",
BasePath: "testdata/invalid-registry-files",
Expand Down
1 change: 1 addition & 0 deletions check/registry_resource_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func NewRegistryResourceFileCheck(opts *RegistryResourceFileOptions) *RegistryRe
}

check.Options.FrontMatter.NoLayout = true
check.Options.FrontMatter.NoSidebarCurrent = true

return check
}
Expand Down
6 changes: 6 additions & 0 deletions check/registry_resource_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func TestRegistryResourceFileCheck(t *testing.T) {
Path: "resource_with_layout.md",
ExpectError: true,
},
{
Name: "invalid frontmatter with sidebar_current",
BasePath: "testdata/invalid-registry-files",
Path: "resource_with_sidebar_current.md",
ExpectError: true,
},
}

for _, testCase := range testCases {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
subcategory: "Example"
sidebar_current: "example_thing"
layout: "example"
page_title: "Example: example_thing"
description: |-
Example description.
---

# Data Source: example_thing

Byline.

## Example Usage

```hcl
data "example_thing" "example" {
name = "example"
}
```

## Argument Reference

* `name` - (Required) Name of thing.

## Attribute Reference

* `id` - Name of thing.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
subcategory: "Example"
sidebar_current: "example"
layout: "example"
page_title: "Example Guide"
description: |-
Example description.
---

# Example Guide

Example contents.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
sidebar_current: "example"
layout: "example"
page_title: "Example Provider"
description: |-
Example description.
---

# Example Provider

Example contents.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
subcategory: "Example"
sidebar_current: "example_thing"
layout: "example"
page_title: "Example: example_thing"
description: |-
Example description.
---

# Resource: example_thing

Byline.

## Example Usage

```hcl
resource "example_thing" "example" {
name = "example"
}
```

## Argument Reference

* `name` - (Required) Name of thing.

## Attribute Reference

* `id` - Name of thing.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
subcategory: "Example"
sidebar_current: "example_thing"
page_title: "Example: example_thing"
description: |-
Example description.
---

# Data Source: example_thing

Byline.

## Example Usage

```hcl
data "example_thing" "example" {
name = "example"
}
```

## Argument Reference

* `name` - (Required) Name of thing.

## Attribute Reference

* `id` - Name of thing.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
subcategory: "Example"
sidebar_current: "example"
page_title: "Example: example_thing"
description: |-
Example description.
---

# Example Guide

Example contents.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
sidebar_current: "example"
page_title: "Example Provider"
description: |-
Example description.
---

# Example Provider

Example contents.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
subcategory: "Example"
sidebar_current: "example_thing"
page_title: "Example: example_thing"
description: |-
Example description.
---

# Resource: example_thing

Byline.

## Example Usage

```hcl
resource "example_thing" "example" {
name = "example"
}
```

## Argument Reference

* `name` - (Required) Name of thing.

## Attribute Reference

* `id` - Name of thing.

0 comments on commit 008c76c

Please sign in to comment.