Skip to content

Commit 61bd79d

Browse files
author
Abhijeet
authored
suppress and fix lint errors by unused (#754)
1 parent 8b8cb9c commit 61bd79d

File tree

10 files changed

+46
-27
lines changed

10 files changed

+46
-27
lines changed

.github/workflows/checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,4 @@ jobs:
102102
- name: Run golangci-lint
103103
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
104104
with:
105-
args: --enable-only=staticcheck
105+
args: --enable-only=staticcheck,unused # this is temporary until we can fix the other issues

.golangci.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) HashiCorp, Inc.
2+
# SPDX-License-Identifier: MPL-2.0
3+
4+
version: "2"
5+
issues:
6+
max-issues-per-linter: 0 # show all issues found by each linter
7+
max-same-issues: 0 # don't ignore same issues
8+
linters:
9+
exclusions:
10+
rules:
11+
- path: hclsyntax/scan_string_lit.go # generated file, ignore errors
12+
linters:
13+
- unused
14+
- staticcheck
15+
- path: hclsyntax/scan_tokens.go # generated file, ignore errors
16+
linters:
17+
- unused
18+
- staticcheck

ext/transform/transform_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
// Assert that deepWrapper implements Body
17-
var deepWrapperIsBody hcl.Body = deepWrapper{}
17+
var _ hcl.Body = deepWrapper{}
1818

1919
func TestDeep(t *testing.T) {
2020

gohcl/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ var victimBody hcl.Body
1414

1515
var exprType = reflect.TypeOf(&victimExpr).Elem()
1616
var bodyType = reflect.TypeOf(&victimBody).Elem()
17-
var blockType = reflect.TypeOf((*hcl.Block)(nil))
17+
1818
var attrType = reflect.TypeOf((*hcl.Attribute)(nil))
1919
var attrsType = reflect.TypeOf(hcl.Attributes(nil))

hclsyntax/scan_string_lit.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ func scanStringLit(data []byte, quoted bool) [][]byte {
172172
_lower := int(_keys)
173173
var _mid int
174174
_upper := int(_keys + _klen - 1)
175-
for _upper >= _lower {
175+
for {
176+
if _upper < _lower {
177+
break
178+
}
176179

177180
_mid = _lower + ((_upper - _lower) >> 1)
178181
switch {
@@ -194,7 +197,10 @@ func scanStringLit(data []byte, quoted bool) [][]byte {
194197
_lower := int(_keys)
195198
var _mid int
196199
_upper := int(_keys + (_klen << 1) - 2)
197-
for _upper >= _lower {
200+
for {
201+
if _upper < _lower {
202+
break
203+
}
198204

199205
_mid = _lower + (((_upper - _lower) >> 1) & ^1)
200206
switch {
@@ -290,7 +296,7 @@ func scanStringLit(data []byte, quoted bool) [][]byte {
290296
// be impossible (the scanner matches all bytes _somehow_) but we'll
291297
// tolerate it and let the caller deal with it.
292298
if cs < hclstrtok_first_final {
293-
ret = append(ret, data[p:])
299+
ret = append(ret, data[p:len(data)])
294300
}
295301

296302
return ret

hclsyntax/scan_tokens.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4323,7 +4323,10 @@ func scanTokens(data []byte, filename string, start hcl.Pos, mode scanMode) []To
43234323
_lower := int(_keys)
43244324
var _mid int
43254325
_upper := int(_keys + _klen - 1)
4326-
for _upper >= _lower {
4326+
for {
4327+
if _upper < _lower {
4328+
break
4329+
}
43274330

43284331
_mid = _lower + ((_upper - _lower) >> 1)
43294332
switch {
@@ -4345,7 +4348,11 @@ func scanTokens(data []byte, filename string, start hcl.Pos, mode scanMode) []To
43454348
_lower := int(_keys)
43464349
var _mid int
43474350
_upper := int(_keys + (_klen << 1) - 2)
4348-
for _upper >= _lower {
4351+
for {
4352+
if _upper < _lower {
4353+
break
4354+
}
4355+
43494356
_mid = _lower + (((_upper - _lower) >> 1) & ^1)
43504357
switch {
43514358
case data[p] < _hcltok_trans_keys[_mid]:

hclsyntax/structure.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type Body struct {
4242
}
4343

4444
// Assert that *Body implements hcl.Body
45-
var assertBodyImplBody hcl.Body = &Body{}
45+
var _ hcl.Body = &Body{}
4646

4747
func (b *Body) walkChildNodes(w internalWalkFunc) {
4848
w(b.Attributes)

hcltest/mock_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import (
1313
"github.com/zclconf/go-cty/cty"
1414
)
1515

16-
var mockBodyIsBody hcl.Body = mockBody{}
17-
var mockExprLiteralIsExpr hcl.Expression = mockExprLiteral{}
18-
var mockExprVariableIsExpr hcl.Expression = mockExprVariable("")
16+
// Assert mocks are compatible with the interfaces they implement.
17+
var _ hcl.Body = mockBody{}
18+
var _ hcl.Expression = mockExprLiteral{}
19+
var _ hcl.Expression = mockExprVariable("")
1920

2021
func TestMockBodyPartialContent(t *testing.T) {
2122
tests := map[string]struct {

hclwrite/ast.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ func (f *File) Bytes() []byte {
5454
type comments struct {
5555
leafNode
5656

57-
parent *node
5857
tokens Tokens
5958
}
6059

@@ -71,8 +70,7 @@ func (c *comments) BuildTokens(to Tokens) Tokens {
7170
type identifier struct {
7271
leafNode
7372

74-
parent *node
75-
token *Token
73+
token *Token
7674
}
7775

7876
func newIdentifier(token *Token) *identifier {
@@ -92,8 +90,7 @@ func (i *identifier) hasName(name string) bool {
9290
type number struct {
9391
leafNode
9492

95-
parent *node
96-
token *Token
93+
token *Token
9794
}
9895

9996
func newNumber(token *Token) *number {
@@ -109,7 +106,6 @@ func (n *number) BuildTokens(to Tokens) Tokens {
109106
type quoted struct {
110107
leafNode
111108

112-
parent *node
113109
tokens Tokens
114110
}
115111

json/parser.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,6 @@ func parseValue(p *peeker) (node, hcl.Diagnostics) {
101101
}
102102
}
103103

104-
func tokenCanStartValue(tok token) bool {
105-
switch tok.Type {
106-
case tokenBraceO, tokenBrackO, tokenNumber, tokenString, tokenKeyword:
107-
return true
108-
default:
109-
return false
110-
}
111-
}
112-
113104
func parseObject(p *peeker) (node, hcl.Diagnostics) {
114105
var diags hcl.Diagnostics
115106

0 commit comments

Comments
 (0)