Skip to content

Commit 9bde283

Browse files
committed
Return boolean variable values directly from functions
Since the variables already contain the value that needs to be returned, the if statement only adds unnecessary verbosity.
1 parent 2c29553 commit 9bde283

File tree

5 files changed

+10
-44
lines changed

5 files changed

+10
-44
lines changed

project/library/library.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ var headerFileValidExtensions = map[string]struct{}{
1717
// HasHeaderFileValidExtension returns whether the file at the given path has a valid library header file extension.
1818
func HasHeaderFileValidExtension(filePath *paths.Path) bool {
1919
_, hasHeaderFileValidExtension := headerFileValidExtensions[filePath.Ext()]
20-
if hasHeaderFileValidExtension {
21-
return true
22-
}
23-
return false
20+
return hasHeaderFileValidExtension
2421
}
2522

2623
// See: https://arduino.github.io/arduino-cli/latest/library-specification/#library-metadata

project/packageindex/packageindex.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ var validExtensions = map[string]struct{}{
2020
// HasValidExtension returns whether the file at the given path has a valid package index extension.
2121
func HasValidExtension(filePath *paths.Path) bool {
2222
_, hasValidExtension := validExtensions[filePath.Ext()]
23-
if hasValidExtension {
24-
return true
25-
}
26-
return false
23+
return hasValidExtension
2724
}
2825

2926
// Regular expressions for official and non-official package index filenames

project/platform/platform.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ var configurationFilenames = map[string]struct{}{
2121
// IsConfigurationFile returns whether the file at the given path has a boards platform configuration file filename.
2222
func IsConfigurationFile(filePath *paths.Path) bool {
2323
_, isConfigurationFile := configurationFilenames[filePath.Base()]
24-
if isConfigurationFile {
25-
return true
26-
}
27-
return false
24+
return isConfigurationFile
2825
}
2926

3027
var requiredConfigurationFilenames = map[string]struct{}{
@@ -35,10 +32,7 @@ var requiredConfigurationFilenames = map[string]struct{}{
3532
// IsRequiredConfigurationFile returns whether the file at the given path has the filename of a required boards platform configuration file.
3633
func IsRequiredConfigurationFile(filePath *paths.Path) bool {
3734
_, isRequiredConfigurationFile := requiredConfigurationFilenames[filePath.Base()]
38-
if isRequiredConfigurationFile {
39-
return true
40-
}
41-
return false
35+
return isRequiredConfigurationFile
4236
}
4337

4438
// See: https://arduino.github.io/arduino-cli/latest/platform-specification/#platform-bundled-libraries

project/project.go

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,7 @@ func isSketch(potentialProjectPath *paths.Path) bool {
185185
}
186186

187187
func isSketchIndicatorFile(filePath *paths.Path) bool {
188-
if sketch.HasMainFileValidExtension(filePath) {
189-
return true
190-
}
191-
return false
188+
return sketch.HasMainFileValidExtension(filePath)
192189
}
193190

194191
// isLibrary determines if a path is an Arduino library.
@@ -236,19 +233,11 @@ func isPlatform(potentialProjectPath *paths.Path) bool {
236233
}
237234

238235
func isPlatformIndicatorFile(filePath *paths.Path) bool {
239-
if platform.IsConfigurationFile(filePath) {
240-
return true
241-
}
242-
243-
return false
236+
return platform.IsConfigurationFile(filePath)
244237
}
245238

246239
func isStrictPlatformIndicatorFile(filePath *paths.Path) bool {
247-
if platform.IsRequiredConfigurationFile(filePath) {
248-
return true
249-
}
250-
251-
return false
240+
return platform.IsRequiredConfigurationFile(filePath)
252241
}
253242

254243
// isPackageIndex determines if a path contains an Arduino package index.
@@ -266,17 +255,9 @@ func isPackageIndex(potentialProjectPath *paths.Path) bool {
266255
}
267256

268257
func isPackageIndexIndicatorFile(filePath *paths.Path) bool {
269-
if packageindex.HasValidExtension(filePath) {
270-
return true
271-
}
272-
273-
return false
258+
return packageindex.HasValidExtension(filePath)
274259
}
275260

276261
func isStrictPackageIndexIndicatorFile(filePath *paths.Path) bool {
277-
if packageindex.HasValidFilename(filePath, true) {
278-
return true
279-
}
280-
281-
return false
262+
return packageindex.HasValidFilename(filePath, true)
282263
}

project/sketch/sketch.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,5 @@ import (
1313
// Sketches may contain source files with other extensions (e.g., .h, .cpp), but they are required to have at least one file with a main extension.
1414
func HasMainFileValidExtension(filePath *paths.Path) bool {
1515
_, hasMainFileValidExtension := globals.MainFileValidExtensions[filePath.Ext()]
16-
if hasMainFileValidExtension {
17-
return true
18-
}
19-
return false
16+
return hasMainFileValidExtension
2017
}

0 commit comments

Comments
 (0)