Skip to content

Commit 977048e

Browse files
committed
Add check for misspelled library.properties file name
1 parent 9a81479 commit 977048e

File tree

6 files changed

+50
-0
lines changed

6 files changed

+50
-0
lines changed

Diff for: check/checkconfigurations/checkconfigurations.go

+15
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ var configurations = []Type{
7171
ErrorModes: []checkmode.Type{checkmode.All},
7272
CheckFunction: checkfunctions.LibraryPropertiesFormat,
7373
},
74+
{
75+
ProjectType: projecttype.Library,
76+
Category: "library.properties",
77+
Subcategory: "general",
78+
ID: "",
79+
Brief: "incorrect library.properties file name",
80+
Description: "",
81+
MessageTemplate: "Incorrectly spelled library.properties file name found: {{.}}. See: https://arduino.github.io/arduino-cli/latest/library-specification/#library-metadata",
82+
DisableModes: nil,
83+
EnableModes: []checkmode.Type{checkmode.All},
84+
InfoModes: nil,
85+
WarningModes: []checkmode.Type{checkmode.Permissive},
86+
ErrorModes: []checkmode.Type{checkmode.Default},
87+
CheckFunction: checkfunctions.MisspelledLibraryPropertiesFileName,
88+
},
7489
{
7590
ProjectType: projecttype.Library,
7691
Category: "library.properties",

Diff for: check/checkfunctions/library.go

+16
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ func LibraryPropertiesFormat() (result checkresult.Type, output string) {
4343
return checkresult.Pass, ""
4444
}
4545

46+
// MisspelledLibraryPropertiesFileName checks for incorrectly spelled library.properties file name.
47+
func MisspelledLibraryPropertiesFileName() (result checkresult.Type, output string) {
48+
directoryListing, err := checkdata.ProjectPath().ReadDir()
49+
if err != nil {
50+
panic(err)
51+
}
52+
directoryListing.FilterOutDirs()
53+
54+
path, found := containsMisspelledPathBaseName(directoryListing, "library.properties", "(?i)^librar(y)|(ie)s?[.-_]?propert(y)|(ie)s?$")
55+
if found {
56+
return checkresult.Fail, path.String()
57+
}
58+
59+
return checkresult.Pass, ""
60+
}
61+
4662
// LibraryPropertiesNameFieldMissing checks for missing library.properties "name" field.
4763
func LibraryPropertiesNameFieldMissing() (result checkresult.Type, output string) {
4864
if checkdata.LibraryPropertiesLoadError() != nil {

Diff for: check/checkfunctions/library_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ func checkLibraryCheckFunction(checkFunction Type, testTables []libraryCheckFunc
6464
}
6565
}
6666

67+
func TestMisspelledLibraryPropertiesFileName(t *testing.T) {
68+
testTables := []libraryCheckFunctionTestTable{
69+
{"Incorrect", "MisspelledLibraryProperties", checkresult.Fail, ""},
70+
{"Correct", "Recursive", checkresult.Pass, ""},
71+
}
72+
73+
checkLibraryCheckFunction(MisspelledLibraryPropertiesFileName, testTables, t)
74+
}
75+
6776
func TestLibraryPropertiesNameFieldMissingOfficialPrefix(t *testing.T) {
6877
testTables := []libraryCheckFunctionTestTable{
6978
{"Unable to load", "InvalidLibraryProperties", checkresult.NotRun, ""},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=MisspelledLibraryProperties
2+
version=1.0.0
3+
author=Cristian Maglie <[email protected]>, Pippo Pluto <[email protected]>
4+
maintainer=Cristian Maglie <[email protected]>
5+
sentence=A library that makes coding a web server a breeze.
6+
paragraph=Supports HTTP1.1 and you can do GET and POST.
7+
category=Communication
8+
url=http://example.com/
9+
architectures=avr

Diff for: check/checkfunctions/testdata/libraries/MisspelledLibraryProperties/src/MisspelledLibraryProperties.h

Whitespace-only changes.

Diff for: etc/codespell-ignore-words-list.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
ot
2+
propert

0 commit comments

Comments
 (0)