Skip to content

Commit b24f9e2

Browse files
committed
Add rules for checking package index filename
The package index filename must follow a specific format. Package indexes which are not compliant are ignored by the Arduino development software. Only the official package index may be named package_index.json.
1 parent 53c1162 commit b24f9e2

File tree

6 files changed

+234
-0
lines changed

6 files changed

+234
-0
lines changed

internal/rule/ruleconfiguration/ruleconfiguration.go

+32
Original file line numberDiff line numberDiff line change
@@ -2857,6 +2857,38 @@ var configurations = []Type{
28572857
ErrorModes: []rulemode.Type{rulemode.Default},
28582858
RuleFunction: rulefunction.PackageIndexMissing,
28592859
},
2860+
{
2861+
ProjectType: projecttype.PackageIndex,
2862+
SuperprojectType: projecttype.All,
2863+
Category: "data",
2864+
Subcategory: "general",
2865+
ID: "IS002",
2866+
Brief: "invalid filename",
2867+
Description: "",
2868+
MessageTemplate: "Invalid package index filename {{.}}. See: https://arduino.github.io/arduino-cli/latest/package_index_json-specification/",
2869+
DisableModes: []rulemode.Type{rulemode.Official},
2870+
EnableModes: []rulemode.Type{rulemode.Default},
2871+
InfoModes: nil,
2872+
WarningModes: nil,
2873+
ErrorModes: []rulemode.Type{rulemode.Default},
2874+
RuleFunction: rulefunction.PackageIndexFilenameInvalid,
2875+
},
2876+
{
2877+
ProjectType: projecttype.PackageIndex,
2878+
SuperprojectType: projecttype.All,
2879+
Category: "data",
2880+
Subcategory: "general",
2881+
ID: "IS003",
2882+
Brief: "invalid official filename",
2883+
Description: "",
2884+
MessageTemplate: "Invalid official package index filename {{.}}. See: https://arduino.github.io/arduino-cli/latest/package_index_json-specification/",
2885+
DisableModes: []rulemode.Type{rulemode.Default},
2886+
EnableModes: []rulemode.Type{rulemode.Official},
2887+
InfoModes: nil,
2888+
WarningModes: nil,
2889+
ErrorModes: []rulemode.Type{rulemode.Default},
2890+
RuleFunction: rulefunction.PackageIndexOfficialFilenameInvalid,
2891+
},
28602892
{
28612893
ProjectType: projecttype.PackageIndex,
28622894
SuperprojectType: projecttype.All,

internal/rule/rulefunction/packageindex.go

+27
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package rulefunction
1717

1818
import (
19+
"github.com/arduino/arduino-lint/internal/project/packageindex"
1920
"github.com/arduino/arduino-lint/internal/project/projectdata"
2021
"github.com/arduino/arduino-lint/internal/rule/ruleresult"
2122
)
@@ -31,6 +32,32 @@ func PackageIndexMissing() (result ruleresult.Type, output string) {
3132
return ruleresult.Pass, ""
3233
}
3334

35+
// PackageIndexFilenameInvalid checks whether the package index's filename is valid for 3rd party projects.
36+
func PackageIndexFilenameInvalid() (result ruleresult.Type, output string) {
37+
if projectdata.ProjectPath() == nil {
38+
return ruleresult.NotRun, "Package index not found"
39+
}
40+
41+
if packageindex.HasValidFilename(projectdata.ProjectPath(), false) {
42+
return ruleresult.Pass, ""
43+
}
44+
45+
return ruleresult.Fail, projectdata.ProjectPath().Base()
46+
}
47+
48+
// PackageIndexOfficialFilenameInvalid checks whether the package index's filename is valid for official projects.
49+
func PackageIndexOfficialFilenameInvalid() (result ruleresult.Type, output string) {
50+
if projectdata.ProjectPath() == nil {
51+
return ruleresult.NotRun, "Package index not found"
52+
}
53+
54+
if packageindex.HasValidFilename(projectdata.ProjectPath(), true) {
55+
return ruleresult.Pass, ""
56+
}
57+
58+
return ruleresult.Fail, projectdata.ProjectPath().Base()
59+
}
60+
3461
// PackageIndexJSONFormat checks whether the package index file is a valid JSON document.
3562
func PackageIndexJSONFormat() (result ruleresult.Type, output string) {
3663
if projectdata.ProjectPath() == nil {

internal/rule/rulefunction/packageindex_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,28 @@ func TestPackageIndexMissing(t *testing.T) {
6969
checkPackageIndexRuleFunction(PackageIndexMissing, testTables, t)
7070
}
7171

72+
func TestPackageIndexFilenameInvalid(t *testing.T) {
73+
testTables := []packageIndexRuleFunctionTestTable{
74+
{"Missing", "missing", ruleresult.NotRun, ""},
75+
{"Valid 3rd party", "3rd-party-filename", ruleresult.Pass, ""},
76+
{"Valid official", "official-filename", ruleresult.Fail, "^package_index.json$"},
77+
{"Invalid", "invalid-filename", ruleresult.Fail, "^invalid-filename.json$"},
78+
}
79+
80+
checkPackageIndexRuleFunction(PackageIndexFilenameInvalid, testTables, t)
81+
}
82+
83+
func TestPackageIndexOfficialFilenameInvalid(t *testing.T) {
84+
testTables := []packageIndexRuleFunctionTestTable{
85+
{"Missing", "missing", ruleresult.NotRun, ""},
86+
{"Valid 3rd party", "3rd-party-filename", ruleresult.Pass, ""},
87+
{"Valid official", "official-filename", ruleresult.Pass, ""},
88+
{"Invalid", "invalid-filename", ruleresult.Fail, "^invalid-filename.json$"},
89+
}
90+
91+
checkPackageIndexRuleFunction(PackageIndexOfficialFilenameInvalid, testTables, t)
92+
}
93+
7294
func TestPackageIndexJSONFormat(t *testing.T) {
7395
testTables := []packageIndexRuleFunctionTestTable{
7496
{"Invalid JSON", "invalid-JSON", ruleresult.Fail, ""},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"packages": [
3+
{
4+
"name": "notarduino",
5+
"maintainer": "NotArduino",
6+
"websiteURL": "http://www.arduino.cc/",
7+
"email": "packages@arduino.cc",
8+
"help": {
9+
"online": "http://www.arduino.cc/en/Reference/HomePage"
10+
},
11+
"platforms": [
12+
{
13+
"name": "Arduino AVR Boards",
14+
"architecture": "avr",
15+
"version": "1.8.3",
16+
"category": "Contributed",
17+
"help": {
18+
"online": "http://www.arduino.cc/en/Reference/HomePage"
19+
},
20+
"url": "http://downloads.arduino.cc/cores/avr-1.8.3.tar.bz2",
21+
"archiveFileName": "avr-1.8.3.tar.bz2",
22+
"checksum": "SHA-256:de8a9b982477762d3d3e52fc2b682cdd8ff194dc3f1d46f4debdea6a01b33c14",
23+
"size": "4941548",
24+
"boards": [{ "name": "Arduino Uno" }],
25+
"toolsDependencies": [
26+
{
27+
"packager": "arduino",
28+
"name": "avr-gcc",
29+
"version": "7.3.0-atmel3.6.1-arduino7"
30+
}
31+
]
32+
}
33+
],
34+
"tools": [
35+
{
36+
"name": "avr-gcc",
37+
"version": "7.3.0-atmel3.6.1-arduino7",
38+
"systems": [
39+
{
40+
"size": "34683056",
41+
"checksum": "SHA-256:3903553d035da59e33cff9941b857c3cb379cb0638105dfdf69c97f0acc8e7b5",
42+
"host": "arm-linux-gnueabihf",
43+
"archiveFileName": "avr-gcc-7.3.0-atmel3.6.1-arduino7-arm-linux-gnueabihf.tar.bz2",
44+
"url": "http://downloads.arduino.cc/tools/avr-gcc-7.3.0-atmel3.6.1-arduino7-arm-linux-gnueabihf.tar.bz2"
45+
}
46+
]
47+
}
48+
]
49+
}
50+
]
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"packages": [
3+
{
4+
"name": "notarduino",
5+
"maintainer": "NotArduino",
6+
"websiteURL": "http://www.arduino.cc/",
7+
"email": "packages@arduino.cc",
8+
"help": {
9+
"online": "http://www.arduino.cc/en/Reference/HomePage"
10+
},
11+
"platforms": [
12+
{
13+
"name": "Arduino AVR Boards",
14+
"architecture": "avr",
15+
"version": "1.8.3",
16+
"category": "Contributed",
17+
"help": {
18+
"online": "http://www.arduino.cc/en/Reference/HomePage"
19+
},
20+
"url": "http://downloads.arduino.cc/cores/avr-1.8.3.tar.bz2",
21+
"archiveFileName": "avr-1.8.3.tar.bz2",
22+
"checksum": "SHA-256:de8a9b982477762d3d3e52fc2b682cdd8ff194dc3f1d46f4debdea6a01b33c14",
23+
"size": "4941548",
24+
"boards": [{ "name": "Arduino Uno" }],
25+
"toolsDependencies": [
26+
{
27+
"packager": "arduino",
28+
"name": "avr-gcc",
29+
"version": "7.3.0-atmel3.6.1-arduino7"
30+
}
31+
]
32+
}
33+
],
34+
"tools": [
35+
{
36+
"name": "avr-gcc",
37+
"version": "7.3.0-atmel3.6.1-arduino7",
38+
"systems": [
39+
{
40+
"size": "34683056",
41+
"checksum": "SHA-256:3903553d035da59e33cff9941b857c3cb379cb0638105dfdf69c97f0acc8e7b5",
42+
"host": "arm-linux-gnueabihf",
43+
"archiveFileName": "avr-gcc-7.3.0-atmel3.6.1-arduino7-arm-linux-gnueabihf.tar.bz2",
44+
"url": "http://downloads.arduino.cc/tools/avr-gcc-7.3.0-atmel3.6.1-arduino7-arm-linux-gnueabihf.tar.bz2"
45+
}
46+
]
47+
}
48+
]
49+
}
50+
]
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"packages": [
3+
{
4+
"name": "arduino",
5+
"maintainer": "Arduino",
6+
"websiteURL": "http://www.arduino.cc/",
7+
"email": "packages@arduino.cc",
8+
"help": {
9+
"online": "http://www.arduino.cc/en/Reference/HomePage"
10+
},
11+
"platforms": [
12+
{
13+
"name": "Arduino AVR Boards",
14+
"architecture": "avr",
15+
"version": "1.8.3",
16+
"category": "Arduino",
17+
"help": {
18+
"online": "http://www.arduino.cc/en/Reference/HomePage"
19+
},
20+
"url": "http://downloads.arduino.cc/cores/avr-1.8.3.tar.bz2",
21+
"archiveFileName": "avr-1.8.3.tar.bz2",
22+
"checksum": "SHA-256:de8a9b982477762d3d3e52fc2b682cdd8ff194dc3f1d46f4debdea6a01b33c14",
23+
"size": "4941548",
24+
"boards": [{ "name": "Arduino Uno" }],
25+
"toolsDependencies": [
26+
{
27+
"packager": "arduino",
28+
"name": "avr-gcc",
29+
"version": "7.3.0-atmel3.6.1-arduino7"
30+
}
31+
]
32+
}
33+
],
34+
"tools": [
35+
{
36+
"name": "avr-gcc",
37+
"version": "7.3.0-atmel3.6.1-arduino7",
38+
"systems": [
39+
{
40+
"size": "34683056",
41+
"checksum": "SHA-256:3903553d035da59e33cff9941b857c3cb379cb0638105dfdf69c97f0acc8e7b5",
42+
"host": "arm-linux-gnueabihf",
43+
"archiveFileName": "avr-gcc-7.3.0-atmel3.6.1-arduino7-arm-linux-gnueabihf.tar.bz2",
44+
"url": "http://downloads.arduino.cc/tools/avr-gcc-7.3.0-atmel3.6.1-arduino7-arm-linux-gnueabihf.tar.bz2"
45+
}
46+
]
47+
}
48+
]
49+
}
50+
]
51+
}

0 commit comments

Comments
 (0)