Skip to content

Commit

Permalink
Chore: Apply fixes from MegaLinter reports
Browse files Browse the repository at this point in the history
  • Loading branch information
refucktor committed Nov 1, 2024
1 parent feb33b9 commit 6901ffc
Show file tree
Hide file tree
Showing 16 changed files with 282 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .linters/.checkov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
compact: true # For the CLI output, do not display code blocks
quiet: true # For the CLI output, display only failed checks. Also disables progress bars
evaluate-variables: true
24 changes: 24 additions & 0 deletions .linters/.cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"language": "en",
"noConfigSearch": true,
"words": ["megalinter", "oxsecurity"],
"dictionaries": ["project-dict", "go", "filetypes", "softwareTerms", "misc"],
"dictionaryDefinitions": [
{
"name": "project-dict",
"path": "./project-dict.txt",
"useCompounds": true
}
],
"ignorePaths": [
"**/node_modules/**",
"**/vscode-extension/**",
"**/.git/**",
"**/.pnpm-lock.json",
".vscode",
"megalinter",
"package-lock.json",
"report",
".ml-reports/**"
]
}
31 changes: 31 additions & 0 deletions .linters/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Visit https://golangci-lint.run/ for usage documentation
# and information on other useful linters
issues:
max-issues-per-linter: 30
max-same-issues: 0
exclude-rules:
- path: '(.+)_test\.go'
linters:
- unparam
- forcetypeassert

linters:
disable-all: true
enable:
- durationcheck
- errcheck
- forcetypeassert
- godot
- gofmt
- gosimple
- govet
- ineffassign
- makezero
- misspell
- nilerr
- predeclared
- staticcheck
- tenv
- unconvert
- unparam
- unused
20 changes: 20 additions & 0 deletions .linters/.jscpd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"threshold": 20,
"minLines": 15,
"reporters": ["html", "markdown"],
"ignore": [
"**/node_modules/**",
"**/.git/**",
"**/.rbenv/**",
"**/.venv/**",
"**/*cache*/**",
"**/.github/**",
"**/.idea/**",
"**/report/**",
"**/.ml-reports/**",
"**/*.svg",
"**/*_test.go",
"./examples/**",
"./docs/**"
]
}
8 changes: 8 additions & 0 deletions .linters/.markdown-link-check.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"ignorePatterns": [
{ "pattern": "^#.+" }
],
"retryOn429": true,
"retryCount": 3,
"aliveStatusCodes": [200, 203]
}
30 changes: 30 additions & 0 deletions .linters/.markdownlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Default state for all rules
default: true

# MD007/ul-indent - Unordered list indentation
MD007:
# Spaces for indent
indent: 2

# MD013/line-length - Line length
MD013:
line_length: 120
tables: false
code_blocks: false

# MD026/no-trailing-punctuation - Trailing punctuation in heading
MD026:
# Punctuation characters
punctuation: ".,;:!。,;:!"

# MD029/ol-prefix - Ordered list item prefix
MD029: false

# MD033/no-inline-html - Inline HTML
MD033: false

# MD036/no-emphasis-as-heading/no-emphasis-as-header - Emphasis used instead of a heading
MD036: false

# MD041/first-line-heading/first-line-h1 - First line in a file should be a top-level heading
MD041: false
31 changes: 31 additions & 0 deletions .linters/.revive.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
ignoreGeneratedHeader = false
severity = "warning"
confidence = 0.8
errorCode = 0
warningCode = 0

[rule.blank-imports]
[rule.context-as-argument]
[rule.context-keys-type]
[rule.dot-imports]
[rule.error-return]
[rule.error-strings]
[rule.error-naming]
[rule.increment-decrement]
[rule.var-naming]
[rule.var-declaration]
[rule.range]
[rule.receiver-naming]
[rule.time-naming]
[rule.unexported-return]
[rule.indent-error-flow]
[rule.errorf]
[rule.empty-block]
[rule.superfluous-else]
[rule.unused-parameter]
[rule.unreachable-code]
[rule.redefines-builtin-id]

# disabled from the recommended rules
# [rule.package-comments]
# [rule.exported]
18 changes: 18 additions & 0 deletions .linters/.yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
extends: default
rules:
empty-lines:
max: 1
max-start: 0
max-end: 0
new-lines:
level: warning
type: unix
line-length:
max: 150
comments:
min-spaces-from-content: 1
document-start: false
document-end: false
new-line-at-end-of-file: enable
truthy:
check-keys: false
43 changes: 43 additions & 0 deletions .linters/project-dict.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
basetypes
coverprofile
datasource
durationcheck
errcheck
exportloopref
forcetypeassert
goarch
gofmt
GOLANGCI
golangci
gomod
goreleaser
gosimple
govet
ineffassign
inventium
knownvalue
ldflags
makezero
MARKDOWNLINT
markdownlint
megalinter
nilerr
oxsecurity
predeclared
providerserver
refucktor
sonarcloud
sonarsource
statecheck
staticcheck
stringvalidator
tenv
terraformterraform
tflog
tfplugindocs
tfprotov
tfversion
trimpath
unconvert
unparam
venv
55 changes: 55 additions & 0 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Configuration file for MegaLinter
#
# See all available variables at https://megalinter.io/latest/config-file/ and in linters documentation

# all, none, or list of linter keys
APPLY_FIXES: # all, none, or list of linter keys
- JSON_PRETTIER
- YAML_YAMLLINT
ENABLE_LINTERS: # If you use ENABLE_LINTERS variable, all other linters will be disabled by default
- COPYPASTE_JSCPD # https://megalinter.io/latest/descriptors/copypaste_jscpd/
# - GO_GOLANGCI_LINT # https://megalinter.io/latest/descriptors/go_golangci_lint/ # missing support for Go 1.23
- GO_REVIVE # https://megalinter.io/latest/descriptors/go_revive/
- JSON_PRETTIER # https://megalinter.io/latest/descriptors/json_prettier/
- MARKDOWN_MARKDOWN_LINK_CHECK # https://megalinter.io/latest/descriptors/markdown_markdown_link_check/
- MARKDOWN_MARKDOWNLINT # https://megalinter.io/latest/descriptors/markdown_markdownlint/
- REPOSITORY_CHECKOV # https://megalinter.io/latest/descriptors/repository_checkov/
- SPELL_CSPELL # https://megalinter.io/latest/descriptors/spell_cspell/
- YAML_YAMLLINT # https://megalinter.io/latest/descriptors/yaml_yamllint/

CLEAR_REPORT_FOLDER: true
CONFIG_PROPERTIES_TO_APPEND:
- ADDITIONAL_EXCLUDED_DIRECTORIES
CONFIG_REPORTER: false
FAIL_IF_MISSING_LINTER_IN_FLAVOR: true
FORMATTERS_DISABLE_ERRORS: false
IGNORE_GENERATED_FILES: true
LINTER_RULES_PATH: .linters
PRINT_ALPACA: false
REPORT_OUTPUT_FOLDER: /tmp/lint/.ml-reports
SHOW_ELAPSED_TIME: true
UPDATED_SOURCES_REPORTER: false

ADDITIONAL_EXCLUDED_DIRECTORIES:
- '.archived'
- 'docs'
- 'examples'
- '.git'
- '.linters'
- '.vscode'
- '.idea'

# MARKDOWN_MARKDOWNLINT variables
MARKDOWN_MARKDOWNLINT_CONFIG_FILE: .markdownlint.yml

# YAML_YAMLLINT variables
YAML_YAMLLINT_CONFIG_FILE: .yamllint.yml

# JSON_PRETTIER variables
JSON_PRETTIER_CONFIG_FILE: .prettierrc.yml

# GO_REVIVE
GO_REVIVE_CONFIG_FILE: .revive.toml

# GO_GOLANGCI_LINT
GO_GOLANGCI_LINT_CONFIG_FILE: .golangci.yml
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
![Golang][shield-golang]
![Terraform][shield-terraform]

![🛠️ Build Workflow][badge-gh-action-build][link-gh-action-build]
![🔎 MegaLinter][badge-gh-action-megalinter][link-gh-action-megalinter]
![❇️ CodeQL][badge-gh-action-codeql][link-gh-action-codeql]
[![🛠️ Build Workflow][badge-gh-action-build]][link-gh-action-build]
[![🔎 MegaLinter][badge-gh-action-megalinter]][link-gh-action-megalinter]
[![❇️ CodeQL][badge-gh-action-codeql]][link-gh-action-codeql]

![GitHub language count][shield-lang-count]
![GitHub Actions Workflow Status][shield-gh-action-status]
Expand All @@ -25,15 +25,15 @@

# 🧰 Terraform Provider: Helpers Functions

This is a Terraform Provider only for Helper functions. The main idea is to extend the built-in functionalities of
This is a Terraform Provider only for Helper functions. The main idea is to extend the built-in functionalities of
Terraform with some functions that are not available by default and can be useful in some scenarios.

For a detailed examples and documentation check inside the [docs](./docs/index.md) folder or directly in the
For a detailed examples and documentation check inside the [docs](./docs/index.md) folder or directly in the
Terraform Registry.

## Available Functions

- [object_set_value](./docs/functions/object_set_value.md)
* [object_set_value](./docs/functions/object_set_value.md)

## Example Usage

Expand Down Expand Up @@ -68,7 +68,6 @@ output "write_all_operation" {
style="height: 60px !important;width: 217px !important;">
</a>


<!-- MARKDOWN LINKS & IMAGES -->
[shield-golang]: <https://img.shields.io/badge/-Golang-black?style=for-the-badge&logoColor=white&logo=go&color=00ADD8>
[shield-terraform]: <https://img.shields.io/badge/-Terraform-black?style=for-the-badge&logoColor=white&logo=terraform&color=844FBA>
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/object_set_value_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ func NewObjectSetValueFunction() function.Function {
return &ObjectSetValueFunction{}
}

func (c ObjectSetValueFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) {
func (c ObjectSetValueFunction) Metadata(_ context.Context, _ function.MetadataRequest, resp *function.MetadataResponse) {
resp.Name = "object_set_value"
}

func (c ObjectSetValueFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) {
func (c ObjectSetValueFunction) Definition(_ context.Context, _ function.DefinitionRequest, resp *function.DefinitionResponse) {
resp.Definition = function.Definition{
Summary: "Sets a value in an Object or creates a new key with the value",
Parameters: []function.Parameter{
Expand Down
13 changes: 7 additions & 6 deletions internal/provider/object_set_value_function_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package provider

import (
"fmt"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
"github.com/hashicorp/terraform-plugin-testing/statecheck"
Expand All @@ -21,7 +20,7 @@ func (m mockTFObjectPartial) modify(t *testing.T, key string, value knownvalue.C
return result
}

func TestObjectSetValueFunction_Run(t *testing.T) {
func TestObjectSetValueFunction(t *testing.T) {
t.Parallel()

mockObject := mockTFObjectPartial{
Expand All @@ -31,7 +30,9 @@ func TestObjectSetValueFunction_Run(t *testing.T) {
"key4": knownvalue.StringExact(""),
"key5": knownvalue.Null(),
}
mockObjectString := `{ key1 = "value1", key2 = true, key3 = 3, key4 = "", key5 = null }`
mockTerraformLocalsTestObject := `locals {
test_object = { key1 = "value1", key2 = true, key3 = 3, key4 = "", key5 = null }
`

resource.UnitTest(t, resource.TestCase{
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
Expand All @@ -42,7 +43,7 @@ func TestObjectSetValueFunction_Run(t *testing.T) {
{
// test "write_all" operation mode
Config: `` +
fmt.Sprintf("locals { test_object = %s }\n", mockObjectString) + `
mockTerraformLocalsTestObject + `
output "expect_value_change" { value = provider::helpers::object_set_value(local.test_object, "key1", "new_value", "write_all") }
Expand All @@ -58,7 +59,7 @@ func TestObjectSetValueFunction_Run(t *testing.T) {
{
// test "write_value" operation mode
Config: `` +
fmt.Sprintf("locals { test_object = %s }\n", mockObjectString) + `
mockTerraformLocalsTestObject + `
output "expect_value_change" { value = provider::helpers::object_set_value(local.test_object, "key1", "new_value", "write_value") }
Expand All @@ -74,7 +75,7 @@ func TestObjectSetValueFunction_Run(t *testing.T) {
{
// test "write_safe" operation mode
Config: `` +
fmt.Sprintf("locals { test_object = %s }\n", mockObjectString) + `
mockTerraformLocalsTestObject + `
output "expect_value_change_1" { value = provider::helpers::object_set_value(local.test_object, "key4", "new_value", "write_safe") }
Expand Down
Loading

0 comments on commit 6901ffc

Please sign in to comment.