Skip to content

Commit 76215d1

Browse files
committed
Improve variable/struct naming
1 parent ed4a71c commit 76215d1

File tree

9 files changed

+91
-91
lines changed

9 files changed

+91
-91
lines changed

internal/configs/config_build.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ import (
2424
// file-level invariants validated. If the returned diagnostics contains errors,
2525
// the returned module tree may be incomplete but can still be used carefully
2626
// for static analysis.
27-
func BuildConfig(root *Module, walker ModuleWalker, loader MockDataLoader) (*Config, hcl.Diagnostics, *WorkspaceDeprecationInfo) {
27+
func BuildConfig(root *Module, walker ModuleWalker, loader MockDataLoader) (*Config, hcl.Diagnostics, *DirectoryDeprecationInfo) {
2828
var diags hcl.Diagnostics
29-
var modDeprecations []*ModuleDeprecationInfo
29+
var modDeprecations []*ModuleVersionDeprecationInfo
3030
cfg := &Config{
3131
Module: root,
3232
}
3333
cfg.Root = cfg // Root module is self-referential.
3434
cfg.Children, diags, modDeprecations = buildChildModules(cfg, walker)
35-
workspaceDeprecations := &WorkspaceDeprecationInfo{
36-
ModuleDeprecationInfos: modDeprecations,
35+
workspaceDeprecations := &DirectoryDeprecationInfo{
36+
ModuleVersionDeprecationInfos: modDeprecations,
3737
}
3838
diags = append(diags, buildTestModules(cfg, walker)...)
3939

@@ -146,9 +146,9 @@ func buildTestModules(root *Config, walker ModuleWalker) hcl.Diagnostics {
146146
return diags
147147
}
148148

149-
func buildChildModules(parent *Config, walker ModuleWalker) (map[string]*Config, hcl.Diagnostics, []*ModuleDeprecationInfo) {
149+
func buildChildModules(parent *Config, walker ModuleWalker) (map[string]*Config, hcl.Diagnostics, []*ModuleVersionDeprecationInfo) {
150150
var diags hcl.Diagnostics
151-
modDeprecations := []*ModuleDeprecationInfo{}
151+
modDeprecations := []*ModuleVersionDeprecationInfo{}
152152
ret := map[string]*Config{}
153153

154154
calls := parent.Module.ModuleCalls
@@ -191,10 +191,10 @@ func buildChildModules(parent *Config, walker ModuleWalker) (map[string]*Config,
191191
return ret, diags, modDeprecations
192192
}
193193

194-
func loadModule(root *Config, req *ModuleRequest, walker ModuleWalker) (*Config, hcl.Diagnostics, *ModuleDeprecationInfo) {
194+
func loadModule(root *Config, req *ModuleRequest, walker ModuleWalker) (*Config, hcl.Diagnostics, *ModuleVersionDeprecationInfo) {
195195
var diags hcl.Diagnostics
196-
var modDeprecation *ModuleDeprecationInfo
197-
var childModDeprecations []*ModuleDeprecationInfo
196+
var modDeprecation *ModuleVersionDeprecationInfo
197+
var childModDeprecations []*ModuleVersionDeprecationInfo
198198

199199
mod, ver, modDiags, modDeprecation := walker.LoadModule(req)
200200
diags = append(diags, modDiags...)
@@ -280,15 +280,15 @@ type ModuleWalker interface {
280280
// ensure that the basic file- and module-validations performed by the
281281
// LoadConfigDir function (valid syntax, no namespace collisions, etc) have
282282
// been performed before returning a module.
283-
LoadModule(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics, *ModuleDeprecationInfo)
283+
LoadModule(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics, *ModuleVersionDeprecationInfo)
284284
}
285285

286286
// ModuleWalkerFunc is an implementation of ModuleWalker that directly wraps
287287
// a callback function, for more convenient use of that interface.
288-
type ModuleWalkerFunc func(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics, *ModuleDeprecationInfo)
288+
type ModuleWalkerFunc func(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics, *ModuleVersionDeprecationInfo)
289289

290290
// LoadModule implements ModuleWalker.
291-
func (f ModuleWalkerFunc) LoadModule(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics, *ModuleDeprecationInfo) {
291+
func (f ModuleWalkerFunc) LoadModule(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics, *ModuleVersionDeprecationInfo) {
292292
return f(req)
293293
}
294294

@@ -348,7 +348,7 @@ type ModuleRequest struct {
348348
var DisabledModuleWalker ModuleWalker
349349

350350
func init() {
351-
DisabledModuleWalker = ModuleWalkerFunc(func(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics, *ModuleDeprecationInfo) {
351+
DisabledModuleWalker = ModuleWalkerFunc(func(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics, *ModuleVersionDeprecationInfo) {
352352
return nil, nil, hcl.Diagnostics{
353353
{
354354
Severity: hcl.DiagError,

internal/configs/config_build_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestBuildConfig(t *testing.T) {
3030

3131
versionI := 0
3232
cfg, diags, _ := BuildConfig(mod, ModuleWalkerFunc(
33-
func(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics, *ModuleDeprecationInfo) {
33+
func(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics, *ModuleVersionDeprecationInfo) {
3434
// For the sake of this test we're going to just treat our
3535
// SourceAddr as a path relative to our fixture directory.
3636
// A "real" implementation of ModuleWalker should accept the
@@ -89,7 +89,7 @@ func TestBuildConfigDiags(t *testing.T) {
8989

9090
versionI := 0
9191
cfg, diags, _ := BuildConfig(mod, ModuleWalkerFunc(
92-
func(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics, *ModuleDeprecationInfo) {
92+
func(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics, *ModuleVersionDeprecationInfo) {
9393
// For the sake of this test we're going to just treat our
9494
// SourceAddr as a path relative to our fixture directory.
9595
// A "real" implementation of ModuleWalker should accept the
@@ -136,7 +136,7 @@ func TestBuildConfigChildModuleBackend(t *testing.T) {
136136
}
137137

138138
cfg, diags, _ := BuildConfig(mod, ModuleWalkerFunc(
139-
func(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics, *ModuleDeprecationInfo) {
139+
func(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics, *ModuleVersionDeprecationInfo) {
140140
// For the sake of this test we're going to just treat our
141141
// SourceAddr as a path relative to our fixture directory.
142142
// A "real" implementation of ModuleWalker should accept the
@@ -217,7 +217,7 @@ func TestBuildConfigInvalidModules(t *testing.T) {
217217
expectedWarnings := readDiags(ioutil.ReadFile(filepath.Join(testDir, name, "warnings")))
218218

219219
_, buildDiags, _ := BuildConfig(mod, ModuleWalkerFunc(
220-
func(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics, *ModuleDeprecationInfo) {
220+
func(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics, *ModuleVersionDeprecationInfo) {
221221
// for simplicity, these tests will treat all source
222222
// addresses as relative to the root module
223223
sourcePath := filepath.Join(path, req.SourceAddr.String())
@@ -369,7 +369,7 @@ func TestBuildConfig_WithNestedTestModules(t *testing.T) {
369369
}
370370

371371
cfg, diags, _ := BuildConfig(mod, ModuleWalkerFunc(
372-
func(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics, *ModuleDeprecationInfo) {
372+
func(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics, *ModuleVersionDeprecationInfo) {
373373

374374
// Bit of a hack to get the test working, but we know all the source
375375
// addresses in this test are locals, so we can just treat them as
@@ -452,7 +452,7 @@ func TestBuildConfig_WithTestModule(t *testing.T) {
452452
}
453453

454454
cfg, diags, _ := BuildConfig(mod, ModuleWalkerFunc(
455-
func(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics, *ModuleDeprecationInfo) {
455+
func(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics, *ModuleVersionDeprecationInfo) {
456456
// For the sake of this test we're going to just treat our
457457
// SourceAddr as a path relative to our fixture directory.
458458
// A "real" implementation of ModuleWalker should accept the

internal/configs/configload/loader_load.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (l *Loader) LoadExternalMockData(provider *configs.Provider) (*configs.Mock
6363

6464
// moduleWalkerLoad is a configs.ModuleWalkerFunc for loading modules that
6565
// are presumed to have already been installed.
66-
func (l *Loader) moduleWalkerLoad(req *configs.ModuleRequest) (*configs.Module, *version.Version, hcl.Diagnostics, *configs.ModuleDeprecationInfo) {
66+
func (l *Loader) moduleWalkerLoad(req *configs.ModuleRequest) (*configs.Module, *version.Version, hcl.Diagnostics, *configs.ModuleVersionDeprecationInfo) {
6767
// Since we're just loading here, we expect that all referenced modules
6868
// will be already installed and described in our manifest. However, we
6969
// do verify that the manifest and the configuration are in agreement

internal/configs/configload/loader_snapshot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func (s *Snapshot) moduleManifest() modsdir.Manifest {
134134
// source files from the referenced modules into the given snapshot.
135135
func (l *Loader) makeModuleWalkerSnapshot(snap *Snapshot) configs.ModuleWalker {
136136
return configs.ModuleWalkerFunc(
137-
func(req *configs.ModuleRequest) (*configs.Module, *version.Version, hcl.Diagnostics, *configs.ModuleDeprecationInfo) {
137+
func(req *configs.ModuleRequest) (*configs.Module, *version.Version, hcl.Diagnostics, *configs.ModuleVersionDeprecationInfo) {
138138
mod, v, diags, _ := l.moduleWalkerLoad(req)
139139
if diags.HasErrors() {
140140
return mod, v, diags, nil

internal/configs/module_deprecations.go renamed to internal/configs/module_version_deprecations.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,49 +11,49 @@ import (
1111
"github.com/mitchellh/colorstring"
1212
)
1313

14-
type WorkspaceDeprecationInfo struct {
15-
ModuleDeprecationInfos []*ModuleDeprecationInfo
14+
type DirectoryDeprecationInfo struct {
15+
ModuleVersionDeprecationInfos []*ModuleVersionDeprecationInfo
1616
}
1717

18-
type ModuleDeprecationInfo struct {
18+
type ModuleVersionDeprecationInfo struct {
1919
SourceName string
20-
RegistryDeprecation *RegistryModuleDeprecation
21-
ExternalDependencies []*ModuleDeprecationInfo
20+
RegistryDeprecation *RegistryModuleVersionDeprecation
21+
ExternalDependencies []*ModuleVersionDeprecationInfo
2222
}
2323

24-
type RegistryModuleDeprecation struct {
24+
type RegistryModuleVersionDeprecation struct {
2525
Version string
2626
Link string
2727
Message string
2828
}
2929

30-
type ModuleDeprecationDiagnosticExtra struct {
31-
MessageCode string `json:"message_code"`
32-
Deprecations []*ModuleDeprecationDiagnosticExtraDeprecationItem `json:"deprecations"`
30+
type ModuleVersionDeprecationDiagnosticExtra struct {
31+
MessageCode string `json:"message_code"`
32+
Deprecations []*ModuleVersionDeprecationDiagnosticExtraDeprecationItem `json:"deprecations"`
3333
}
3434

35-
func (m *ModuleDeprecationDiagnosticExtra) IsPublic() {}
35+
func (m *ModuleVersionDeprecationDiagnosticExtra) IsPublic() {}
3636

37-
type ModuleDeprecationDiagnosticExtraDeprecationItem struct {
37+
type ModuleVersionDeprecationDiagnosticExtraDeprecationItem struct {
3838
Version string `json:"version"`
3939
SourceName string `json:"source_name"`
4040
DeprecationMessage string `json:"deprecation_message"`
4141
Link string `json:"link"`
4242
}
4343

44-
func (i *WorkspaceDeprecationInfo) HasDeprecations() bool {
45-
if i == nil || i.ModuleDeprecationInfos == nil {
44+
func (i *DirectoryDeprecationInfo) HasDeprecations() bool {
45+
if i == nil || i.ModuleVersionDeprecationInfos == nil {
4646
return false
4747
}
48-
for _, deprecationInfo := range i.ModuleDeprecationInfos {
48+
for _, deprecationInfo := range i.ModuleVersionDeprecationInfos {
4949
if deprecationInfo != nil && deprecationInfo.hasDeprecations() {
5050
return true
5151
}
5252
}
5353
return false
5454
}
5555

56-
func (i *ModuleDeprecationInfo) hasDeprecations() bool {
56+
func (i *ModuleVersionDeprecationInfo) hasDeprecations() bool {
5757
if i.RegistryDeprecation != nil {
5858
return true
5959
}
@@ -67,15 +67,15 @@ func (i *ModuleDeprecationInfo) hasDeprecations() bool {
6767

6868
// Deprecation info is placed as an string in the Diagnostic Detail for console view,
6969
// as well as placed in the Diagnostic Extra for parsing for the SRO view in HCP Terraform
70-
func (i *WorkspaceDeprecationInfo) BuildDeprecationWarning() *hcl.Diagnostic {
71-
modDeprecationStrings := []string{}
70+
func (i *DirectoryDeprecationInfo) BuildDeprecationWarning() *hcl.Diagnostic {
71+
modDeprecations := []string{}
7272
color := colorstring.Colorize{
7373
Colors: colorstring.DefaultColors,
7474
Disable: false,
7575
Reset: true,
7676
}
77-
deprecationList := make([]*ModuleDeprecationDiagnosticExtraDeprecationItem, 0, len(i.ModuleDeprecationInfos))
78-
for _, modDeprecationInfo := range i.ModuleDeprecationInfos {
77+
deprecationList := make([]*ModuleVersionDeprecationDiagnosticExtraDeprecationItem, 0, len(i.ModuleVersionDeprecationInfos))
78+
for _, modDeprecationInfo := range i.ModuleVersionDeprecationInfos {
7979
if modDeprecationInfo != nil && modDeprecationInfo.RegistryDeprecation != nil {
8080
msg := color.Color("[reset][bold]Version %s of %s[reset]")
8181
modDeprecation := fmt.Sprintf(msg, modDeprecationInfo.RegistryDeprecation.Version, modDeprecationInfo.SourceName)
@@ -86,39 +86,39 @@ func (i *WorkspaceDeprecationInfo) BuildDeprecationWarning() *hcl.Diagnostic {
8686
if modDeprecationInfo.RegistryDeprecation.Link != "" {
8787
modDeprecation = modDeprecation + fmt.Sprintf("\n\nLink for more information: %s", modDeprecationInfo.RegistryDeprecation.Link)
8888
}
89-
deprecationList = append(deprecationList, &ModuleDeprecationDiagnosticExtraDeprecationItem{
89+
deprecationList = append(deprecationList, &ModuleVersionDeprecationDiagnosticExtraDeprecationItem{
9090
Version: modDeprecationInfo.RegistryDeprecation.Version,
9191
SourceName: modDeprecationInfo.SourceName,
9292
DeprecationMessage: modDeprecationInfo.RegistryDeprecation.Message,
9393
Link: modDeprecationInfo.RegistryDeprecation.Link,
9494
})
95-
modDeprecationStrings = append(modDeprecationStrings, modDeprecation)
95+
modDeprecations = append(modDeprecations, modDeprecation)
9696
}
9797
deprecationStrings, deprecationStructs := buildChildModuleDeprecations(modDeprecationInfo.ExternalDependencies, []string{modDeprecationInfo.SourceName})
9898
deprecationList = append(deprecationList, deprecationStructs...)
99-
modDeprecationStrings = append(modDeprecationStrings, deprecationStrings...)
99+
modDeprecations = append(modDeprecations, deprecationStrings...)
100100
}
101-
deprecationsMessage := strings.Join(modDeprecationStrings, "\n\n")
101+
deprecationsMessage := strings.Join(modDeprecations, "\n\n")
102102

103103
return &hcl.Diagnostic{
104104
Severity: hcl.DiagWarning,
105105
Summary: "Deprecated modules found, consider installing updated versions. The following are affected:",
106106
Detail: deprecationsMessage,
107-
Extra: &ModuleDeprecationDiagnosticExtra{
107+
Extra: &ModuleVersionDeprecationDiagnosticExtra{
108108
MessageCode: "module_deprecation_warning",
109109
Deprecations: deprecationList,
110110
},
111111
}
112112
}
113113

114-
func buildChildModuleDeprecations(modDeprecations []*ModuleDeprecationInfo, parentMods []string) ([]string, []*ModuleDeprecationDiagnosticExtraDeprecationItem) {
114+
func buildChildModuleDeprecations(modDeprecations []*ModuleVersionDeprecationInfo, parentMods []string) ([]string, []*ModuleVersionDeprecationDiagnosticExtraDeprecationItem) {
115115
color := colorstring.Colorize{
116116
Colors: colorstring.DefaultColors,
117117
Disable: false,
118118
Reset: true,
119119
}
120120
modDeprecationStrings := []string{}
121-
var deprecationList []*ModuleDeprecationDiagnosticExtraDeprecationItem
121+
var deprecationList []*ModuleVersionDeprecationDiagnosticExtraDeprecationItem
122122
for _, deprecation := range modDeprecations {
123123
if deprecation.RegistryDeprecation != nil {
124124
msg := color.Color("[reset][bold]Version %s of %s %s[reset]")
@@ -132,7 +132,7 @@ func buildChildModuleDeprecations(modDeprecations []*ModuleDeprecationInfo, pare
132132
}
133133
modDeprecationStrings = append(modDeprecationStrings, modDeprecation)
134134
}
135-
deprecationList = append(deprecationList, &ModuleDeprecationDiagnosticExtraDeprecationItem{
135+
deprecationList = append(deprecationList, &ModuleVersionDeprecationDiagnosticExtraDeprecationItem{
136136
Version: deprecation.RegistryDeprecation.Version,
137137
SourceName: deprecation.SourceName,
138138
DeprecationMessage: deprecation.RegistryDeprecation.Message,

0 commit comments

Comments
 (0)