Skip to content

Commit d03e4f8

Browse files
committed
Fixed all lint warnings
1 parent 47c634b commit d03e4f8

File tree

11 files changed

+64
-82
lines changed

11 files changed

+64
-82
lines changed

legacy/builder/builder_utils/utils.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,7 @@ func unescapeDep(s string) string {
371371
}
372372

373373
func removeEndingBackSlash(s string) string {
374-
if strings.HasSuffix(s, "\\") {
375-
s = s[:len(s)-1]
376-
}
377-
return s
374+
return strings.TrimSuffix(s, "\\")
378375
}
379376

380377
func nonEmptyString(s string) bool {

legacy/builder/create_cmake_rule.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ type ExportProjectCMake struct {
4040
SketchError bool
4141
}
4242

43+
var lineMatcher = regexp.MustCompile(`^#line\s\d+\s"`)
44+
4345
func (s *ExportProjectCMake) Run(ctx *types.Context) error {
4446
if s.SketchError || !canExportCmakeProject(ctx) {
4547
return nil
@@ -139,7 +141,7 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
139141
lines := strings.Split(string(input), "\n")
140142

141143
for i, line := range lines {
142-
if lineToRemove, _ := regexp.MatchString(`^#line\s\d+\s"`, line); lineToRemove == true {
144+
if lineMatcher.MatchString(line) {
143145
lines[i] = ""
144146
}
145147
}

legacy/builder/ctags/ctags_has_issues.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
func (p *CTagsParser) FixCLinkageTagsDeclarations(tags []*types.CTag) {
2727

2828
linesMap := p.FindCLinkageLines(tags)
29-
for i, _ := range tags {
29+
for i := range tags {
3030

3131
if sliceContainsInt(linesMap[tags[i].Filename], tags[i].Line) &&
3232
!strings.Contains(tags[i].PrototypeModifiers, EXTERN) {
@@ -51,7 +51,7 @@ func (p *CTagsParser) prototypeAndCodeDontMatch(tag *types.CTag) bool {
5151

5252
code := removeSpacesAndTabs(tag.Code)
5353

54-
if strings.Index(code, ")") == -1 {
54+
if !strings.Contains(code, ")") {
5555
// Add to code non-whitespace non-comments tokens until we find a closing round bracket
5656
file, err := os.Open(tag.Filename)
5757
if err == nil {
@@ -70,7 +70,7 @@ func (p *CTagsParser) prototypeAndCodeDontMatch(tag *types.CTag) bool {
7070
temp := ""
7171

7272
code, multilinecomment = removeComments(scanner.Text(), multilinecomment)
73-
for scanner.Scan() && line < (tag.Line+10) && strings.Index(temp, ")") == -1 {
73+
for scanner.Scan() && line < (tag.Line+10) && !strings.Contains(temp, ")") {
7474
temp, multilinecomment = removeComments(scanner.Text(), multilinecomment)
7575
code += temp
7676
}
@@ -189,13 +189,13 @@ func getFunctionProtoWithNPreviousCharacters(tag *types.CTag, code string, n int
189189

190190
func removeComments(text string, multilinecomment bool) (string, bool) {
191191
// Remove C++ style comments
192-
if strings.Index(text, "//") != -1 {
192+
if strings.Contains(text, "//") {
193193
text = text[0:strings.Index(text, "//")]
194194
}
195195

196196
// Remove C style comments
197-
if strings.Index(text, "*/") != -1 {
198-
if strings.Index(text, "/*") != -1 {
197+
if strings.Contains(text, "*/") {
198+
if strings.Contains(text, "/*") {
199199
// C style comments on the same line
200200
text = text[0:strings.Index(text, "/*")] + text[strings.Index(text, "*/")+1:len(text)-1]
201201
} else {
@@ -205,7 +205,7 @@ func removeComments(text string, multilinecomment bool) (string, bool) {
205205
}
206206

207207
if multilinecomment {
208-
if strings.Index(text, "/*") != -1 {
208+
if strings.Contains(text, "/*") {
209209
text = text[0:strings.Index(text, "/*")]
210210
multilinecomment = false
211211
} else {
@@ -267,7 +267,7 @@ func (p *CTagsParser) FindCLinkageLines(tags []*types.CTag) map[string][]int {
267267
}
268268

269269
// check if we are on the first non empty line after externCDecl in case 3
270-
if enteringScope == true {
270+
if enteringScope {
271271
enteringScope = false
272272
}
273273

@@ -279,13 +279,13 @@ func (p *CTagsParser) FindCLinkageLines(tags []*types.CTag) map[string][]int {
279279
enteringScope = true
280280
}
281281
}
282-
if inScope == true {
282+
if inScope {
283283
lines[tag.Filename] = append(lines[tag.Filename], line)
284284
}
285285
indentLevels += strings.Count(str, "{") - strings.Count(str, "}")
286286

287287
// Bail out if indentLevel is zero and we are not in case 3
288-
if indentLevels == 0 && enteringScope == false {
288+
if indentLevels == 0 && !enteringScope {
289289
inScope = false
290290
}
291291
}

legacy/builder/ctags/ctags_parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func addPrototype(tag *types.CTag) {
9090
}
9191

9292
tag.PrototypeModifiers = ""
93-
if strings.Index(tag.Code, STATIC+" ") != -1 {
93+
if strings.Contains(tag.Code, STATIC+" ") {
9494
tag.PrototypeModifiers = tag.PrototypeModifiers + " " + STATIC
9595
}
9696

@@ -121,7 +121,7 @@ func (p *CTagsParser) skipDuplicates() {
121121
definedPrototypes := make(map[string]bool)
122122

123123
for _, tag := range p.tags {
124-
if !definedPrototypes[tag.Prototype] && tag.SkipMe == false {
124+
if !definedPrototypes[tag.Prototype] && !tag.SkipMe {
125125
definedPrototypes[tag.Prototype] = true
126126
} else {
127127
tag.SkipMe = true

legacy/builder/ctags/ctags_to_prototypes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ func (p *CTagsParser) firstFunctionPointerUsedAsArgument() int {
5555

5656
func functionNameUsedAsFunctionPointerIn(tag *types.CTag, functionTags []*types.CTag) bool {
5757
for _, functionTag := range functionTags {
58-
if tag.Line != functionTag.Line && strings.Index(tag.Code, "&"+functionTag.FunctionName) != -1 {
58+
if tag.Line != functionTag.Line && strings.Contains(tag.Code, "&"+functionTag.FunctionName) {
5959
return true
6060
}
61-
if tag.Line != functionTag.Line && strings.Index(strings.TrimSpace(tag.Code), "("+functionTag.FunctionName+")") != -1 {
61+
if tag.Line != functionTag.Line && strings.Contains(tag.Code, "("+functionTag.FunctionName+")") {
6262
return true
6363
}
6464
}

legacy/builder/filter_sketch_source.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ type FilterSketchSource struct {
3434
func (s *FilterSketchSource) Run(ctx *types.Context) error {
3535
fileNames := paths.NewPathList()
3636
fileNames.Add(ctx.Sketch.MainFile)
37-
for _, file := range ctx.Sketch.OtherSketchFiles {
38-
fileNames = append(fileNames, file)
39-
}
37+
fileNames.AddAll(ctx.Sketch.OtherSketchFiles)
4038

4139
inSketch := false
4240
filtered := ""

legacy/builder/includes_finder_with_regexp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func findIncludeForOldCompilers(source string) string {
3434
lines := strings.Split(source, "\n")
3535
for _, line := range lines {
3636
splittedLine := strings.Split(line, ":")
37-
for i, _ := range splittedLine {
37+
for i := range splittedLine {
3838
if strings.Contains(splittedLine[i], "fatal error") {
3939
return strings.TrimSpace(splittedLine[i+1])
4040
}

legacy/builder/test/helper_tools_downloader.go

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -70,66 +70,66 @@ type Core struct {
7070

7171
func DownloadCoresAndToolsAndLibraries(t *testing.T) {
7272
cores := []Core{
73-
Core{Maintainer: "arduino", Arch: "avr", Version: "1.6.10"},
74-
Core{Maintainer: "arduino", Arch: "sam", Version: "1.6.7"},
73+
{Maintainer: "arduino", Arch: "avr", Version: "1.6.10"},
74+
{Maintainer: "arduino", Arch: "sam", Version: "1.6.7"},
7575
}
7676

7777
boardsManagerCores := []Core{
78-
Core{Maintainer: "arduino", Arch: "samd", Version: "1.6.5"},
78+
{Maintainer: "arduino", Arch: "samd", Version: "1.6.5"},
7979
}
8080

8181
boardsManagerRedBearCores := []Core{
82-
Core{Maintainer: "RedBearLab", Arch: "avr", Version: "1.0.0", Url: "https://redbearlab.github.io/arduino/Blend/blend_boards.zip"},
82+
{Maintainer: "RedBearLab", Arch: "avr", Version: "1.0.0", Url: "https://redbearlab.github.io/arduino/Blend/blend_boards.zip"},
8383
}
8484

8585
toolsMultipleVersions := []Tool{
86-
Tool{Name: "bossac", Version: "1.6.1-arduino"},
87-
Tool{Name: "bossac", Version: "1.5-arduino"},
86+
{Name: "bossac", Version: "1.6.1-arduino"},
87+
{Name: "bossac", Version: "1.5-arduino"},
8888
}
8989

9090
tools := []Tool{
91-
Tool{Name: "avrdude", Version: "6.0.1-arduino5"},
92-
Tool{Name: "avr-gcc", Version: "4.8.1-arduino5"},
93-
Tool{Name: "arm-none-eabi-gcc", Version: "4.8.3-2014q1"},
94-
Tool{Name: "ctags", Version: "5.8-arduino11",
91+
{Name: "avrdude", Version: "6.0.1-arduino5"},
92+
{Name: "avr-gcc", Version: "4.8.1-arduino5"},
93+
{Name: "arm-none-eabi-gcc", Version: "4.8.3-2014q1"},
94+
{Name: "ctags", Version: "5.8-arduino11",
9595
OsUrls: []OsUrl{
96-
OsUrl{Os: "i686-pc-linux-gnu", Url: "http://downloads.arduino.cc/tools/ctags-5.8-arduino11-i686-pc-linux-gnu.tar.bz2"},
97-
OsUrl{Os: "x86_64-pc-linux-gnu", Url: "http://downloads.arduino.cc/tools/ctags-5.8-arduino11-x86_64-pc-linux-gnu.tar.bz2"},
98-
OsUrl{Os: "i686-mingw32", Url: "http://downloads.arduino.cc/tools/ctags-5.8-arduino11-i686-mingw32.zip"},
99-
OsUrl{Os: "x86_64-apple-darwin", Url: "http://downloads.arduino.cc/tools/ctags-5.8-arduino11-x86_64-apple-darwin.zip"},
100-
OsUrl{Os: "arm-linux-gnueabihf", Url: "http://downloads.arduino.cc/tools/ctags-5.8-arduino11-armv6-linux-gnueabihf.tar.bz2"},
101-
OsUrl{Os: "aarch64-linux-gnu", Url: "http://downloads.arduino.cc/tools/ctags-5.8-arduino11-aarch64-linux-gnu.tar.bz2"},
96+
{Os: "i686-pc-linux-gnu", Url: "http://downloads.arduino.cc/tools/ctags-5.8-arduino11-i686-pc-linux-gnu.tar.bz2"},
97+
{Os: "x86_64-pc-linux-gnu", Url: "http://downloads.arduino.cc/tools/ctags-5.8-arduino11-x86_64-pc-linux-gnu.tar.bz2"},
98+
{Os: "i686-mingw32", Url: "http://downloads.arduino.cc/tools/ctags-5.8-arduino11-i686-mingw32.zip"},
99+
{Os: "x86_64-apple-darwin", Url: "http://downloads.arduino.cc/tools/ctags-5.8-arduino11-x86_64-apple-darwin.zip"},
100+
{Os: "arm-linux-gnueabihf", Url: "http://downloads.arduino.cc/tools/ctags-5.8-arduino11-armv6-linux-gnueabihf.tar.bz2"},
101+
{Os: "aarch64-linux-gnu", Url: "http://downloads.arduino.cc/tools/ctags-5.8-arduino11-aarch64-linux-gnu.tar.bz2"},
102102
},
103103
},
104-
Tool{Name: "arduino-preprocessor", Version: "0.1.5",
104+
{Name: "arduino-preprocessor", Version: "0.1.5",
105105
OsUrls: []OsUrl{
106-
OsUrl{Os: "i686-pc-linux-gnu", Url: "https://github.com/arduino/arduino-preprocessor/releases/download/0.1.5/arduino-preprocessor-0.1.5-i686-pc-linux-gnu.tar.bz2"},
107-
OsUrl{Os: "x86_64-pc-linux-gnu", Url: "https://github.com/arduino/arduino-preprocessor/releases/download/0.1.5/arduino-preprocessor-0.1.5-x86_64-pc-linux-gnu.tar.bz2"},
108-
OsUrl{Os: "i686-mingw32", Url: "https://github.com/arduino/arduino-preprocessor/releases/download/0.1.5/arduino-preprocessor-0.1.5-i686-w64-mingw32.tar.bz2"},
109-
OsUrl{Os: "x86_64-apple-darwin", Url: "https://github.com/arduino/arduino-preprocessor/releases/download/0.1.5/arduino-preprocessor-0.1.5-x86_64-apple-darwin11.tar.bz2"},
110-
OsUrl{Os: "arm-linux-gnueabihf", Url: "https://github.com/arduino/arduino-preprocessor/releases/download/0.1.5/arduino-preprocessor-0.1.5-arm-linux-gnueabihf.tar.bz2"},
111-
OsUrl{Os: "aarch64-linux-gnu", Url: "https://github.com/arduino/arduino-preprocessor/releases/download/0.1.5/arduino-preprocessor-0.1.5-aarch64-linux-gnu.tar.bz2"},
106+
{Os: "i686-pc-linux-gnu", Url: "https://github.com/arduino/arduino-preprocessor/releases/download/0.1.5/arduino-preprocessor-0.1.5-i686-pc-linux-gnu.tar.bz2"},
107+
{Os: "x86_64-pc-linux-gnu", Url: "https://github.com/arduino/arduino-preprocessor/releases/download/0.1.5/arduino-preprocessor-0.1.5-x86_64-pc-linux-gnu.tar.bz2"},
108+
{Os: "i686-mingw32", Url: "https://github.com/arduino/arduino-preprocessor/releases/download/0.1.5/arduino-preprocessor-0.1.5-i686-w64-mingw32.tar.bz2"},
109+
{Os: "x86_64-apple-darwin", Url: "https://github.com/arduino/arduino-preprocessor/releases/download/0.1.5/arduino-preprocessor-0.1.5-x86_64-apple-darwin11.tar.bz2"},
110+
{Os: "arm-linux-gnueabihf", Url: "https://github.com/arduino/arduino-preprocessor/releases/download/0.1.5/arduino-preprocessor-0.1.5-arm-linux-gnueabihf.tar.bz2"},
111+
{Os: "aarch64-linux-gnu", Url: "https://github.com/arduino/arduino-preprocessor/releases/download/0.1.5/arduino-preprocessor-0.1.5-aarch64-linux-gnu.tar.bz2"},
112112
},
113113
},
114114
}
115115

116116
boardsManagerTools := []Tool{
117-
Tool{Name: "openocd", Version: "0.9.0-arduino", Package: "arduino"},
118-
Tool{Name: "CMSIS", Version: "4.0.0-atmel", Package: "arduino"},
117+
{Name: "openocd", Version: "0.9.0-arduino", Package: "arduino"},
118+
{Name: "CMSIS", Version: "4.0.0-atmel", Package: "arduino"},
119119
}
120120

121121
boardsManagerRFduinoTools := []Tool{
122-
Tool{Name: "arm-none-eabi-gcc", Version: "4.8.3-2014q1", Package: "RFduino"},
122+
{Name: "arm-none-eabi-gcc", Version: "4.8.3-2014q1", Package: "RFduino"},
123123
}
124124

125125
libraries := []Library{
126-
Library{Name: "Audio", Version: "1.0.4"},
127-
Library{Name: "Adafruit PN532", Version: "1.0.0"},
128-
Library{Name: "Bridge", Version: "1.6.1"},
129-
Library{Name: "CapacitiveSensor", Version: "0.5.0", VersionInLibProperties: "0.5"},
130-
Library{Name: "Ethernet", Version: "1.1.1"},
131-
Library{Name: "Robot IR Remote", Version: "2.0.0"},
132-
Library{Name: "FastLED", Version: "3.1.0"},
126+
{Name: "Audio", Version: "1.0.4"},
127+
{Name: "Adafruit PN532", Version: "1.0.0"},
128+
{Name: "Bridge", Version: "1.6.1"},
129+
{Name: "CapacitiveSensor", Version: "0.5.0", VersionInLibProperties: "0.5"},
130+
{Name: "Ethernet", Version: "1.1.1"},
131+
{Name: "Robot IR Remote", Version: "2.0.0"},
132+
{Name: "FastLED", Version: "3.1.0"},
133133
}
134134

135135
download(t, cores, boardsManagerCores, boardsManagerRedBearCores, tools, toolsMultipleVersions, boardsManagerTools, boardsManagerRFduinoTools, libraries)

legacy/builder/test/unused_compiled_libraries_remover_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestUnusedCompiledLibrariesRemover(t *testing.T) {
3636

3737
ctx := &types.Context{}
3838
ctx.LibrariesBuildPath = temp
39-
ctx.ImportedLibraries = []*libraries.Library{&libraries.Library{Name: "Bridge"}}
39+
ctx.ImportedLibraries = []*libraries.Library{{Name: "Bridge"}}
4040

4141
cmd := builder.UnusedCompiledLibrariesRemover{}
4242
err = cmd.Run(ctx)
@@ -56,7 +56,7 @@ func TestUnusedCompiledLibrariesRemover(t *testing.T) {
5656
func TestUnusedCompiledLibrariesRemoverLibDoesNotExist(t *testing.T) {
5757
ctx := &types.Context{}
5858
ctx.LibrariesBuildPath = paths.TempDir().Join("test")
59-
ctx.ImportedLibraries = []*libraries.Library{&libraries.Library{Name: "Bridge"}}
59+
ctx.ImportedLibraries = []*libraries.Library{{Name: "Bridge"}}
6060

6161
cmd := builder.UnusedCompiledLibrariesRemover{}
6262
err := cmd.Run(ctx)

legacy/builder/test/utils_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ func TestQuoteCppString(t *testing.T) {
6767
}
6868

6969
func TestParseCppString(t *testing.T) {
70-
str, rest, ok := utils.ParseCppString(`foo`)
70+
_, _, ok := utils.ParseCppString(`foo`)
7171
require.Equal(t, false, ok)
7272

73-
str, rest, ok = utils.ParseCppString(`"foo`)
73+
_, _, ok = utils.ParseCppString(`"foo`)
7474
require.Equal(t, false, ok)
7575

76-
str, rest, ok = utils.ParseCppString(`"foo"`)
76+
str, rest, ok := utils.ParseCppString(`"foo"`)
7777
require.Equal(t, true, ok)
7878
require.Equal(t, `foo`, str)
7979
require.Equal(t, ``, rest)

0 commit comments

Comments
 (0)