Add rules to check loading of URLs in package index · arduino/arduino-lint@6b82e86 (original) (raw)

`@@ -16,6 +16,8 @@

`

16

16

`package rulefunction

`

17

17

``

18

18

`import (

`

``

19

`+

"strings"

`

``

20

+

19

21

`"github.com/arduino/arduino-lint/internal/project/packageindex"

`

20

22

`"github.com/arduino/arduino-lint/internal/project/projectdata"

`

21

23

`"github.com/arduino/arduino-lint/internal/rule/ruleresult"

`

`@@ -83,3 +85,168 @@ func PackageIndexFormat() (result ruleresult.Type, output string) {

`

83

85

``

84

86

`return ruleresult.Pass, ""

`

85

87

`}

`

``

88

+

``

89

`+

// PackageIndexPackagesWebsiteURLDeadLink checks for dead links in packages[].websiteURL.

`

``

90

`+

func PackageIndexPackagesWebsiteURLDeadLink() (result ruleresult.Type, output string) {

`

``

91

`+

if projectdata.PackageIndexLoadError() != nil {

`

``

92

`+

return ruleresult.NotRun, "Error loading package index"

`

``

93

`+

}

`

``

94

+

``

95

`+

nonCompliantIDs := []string{}

`

``

96

`+

for _, data := range projectdata.PackageIndexPackages() {

`

``

97

`+

url, ok := data.Object["websiteURL"].(string)

`

``

98

`+

if !ok {

`

``

99

`+

continue

`

``

100

`+

}

`

``

101

+

``

102

`+

if url == "" {

`

``

103

`+

continue

`

``

104

`+

}

`

``

105

+

``

106

`+

if checkURL(url) == nil {

`

``

107

`+

continue

`

``

108

`+

}

`

``

109

+

``

110

`+

nonCompliantIDs = append(nonCompliantIDs, data.ID)

`

``

111

`+

}

`

``

112

+

``

113

`+

if len(nonCompliantIDs) > 0 {

`

``

114

`+

return ruleresult.Fail, strings.Join(nonCompliantIDs, ", ")

`

``

115

`+

}

`

``

116

+

``

117

`+

return ruleresult.Pass, ""

`

``

118

`+

}

`

``

119

+

``

120

`+

// PackageIndexPackagesHelpOnlineDeadLink checks for dead links in packages[].help.online.

`

``

121

`+

func PackageIndexPackagesHelpOnlineDeadLink() (result ruleresult.Type, output string) {

`

``

122

`+

if projectdata.PackageIndexLoadError() != nil {

`

``

123

`+

return ruleresult.NotRun, "Error loading package index"

`

``

124

`+

}

`

``

125

+

``

126

`+

nonCompliantIDs := []string{}

`

``

127

`+

for _, data := range projectdata.PackageIndexPackages() {

`

``

128

`+

help, ok := data.Object["help"].(map[string]interface{})

`

``

129

`+

if !ok {

`

``

130

`+

continue

`

``

131

`+

}

`

``

132

+

``

133

`+

url, ok := help["online"].(string)

`

``

134

`+

if !ok {

`

``

135

`+

continue

`

``

136

`+

}

`

``

137

+

``

138

`+

if url == "" {

`

``

139

`+

continue

`

``

140

`+

}

`

``

141

+

``

142

`+

if checkURL(url) == nil {

`

``

143

`+

continue

`

``

144

`+

}

`

``

145

+

``

146

`+

nonCompliantIDs = append(nonCompliantIDs, data.ID)

`

``

147

`+

}

`

``

148

+

``

149

`+

if len(nonCompliantIDs) > 0 {

`

``

150

`+

return ruleresult.Fail, strings.Join(nonCompliantIDs, ", ")

`

``

151

`+

}

`

``

152

+

``

153

`+

return ruleresult.Pass, ""

`

``

154

`+

}

`

``

155

+

``

156

`+

// PackageIndexPackagesPlatformsHelpOnlineDeadLink checks for dead links in packages[].platforms[].help.online.

`

``

157

`+

func PackageIndexPackagesPlatformsHelpOnlineDeadLink() (result ruleresult.Type, output string) {

`

``

158

`+

if projectdata.PackageIndexLoadError() != nil {

`

``

159

`+

return ruleresult.NotRun, "Error loading package index"

`

``

160

`+

}

`

``

161

+

``

162

`+

nonCompliantIDs := []string{}

`

``

163

`+

for _, data := range projectdata.PackageIndexPlatforms() {

`

``

164

`+

help, ok := data.Object["help"].(map[string]interface{})

`

``

165

`+

if !ok {

`

``

166

`+

continue

`

``

167

`+

}

`

``

168

+

``

169

`+

url, ok := help["online"].(string)

`

``

170

`+

if !ok {

`

``

171

`+

continue

`

``

172

`+

}

`

``

173

+

``

174

`+

if url == "" {

`

``

175

`+

continue

`

``

176

`+

}

`

``

177

+

``

178

`+

if checkURL(url) == nil {

`

``

179

`+

continue

`

``

180

`+

}

`

``

181

+

``

182

`+

nonCompliantIDs = append(nonCompliantIDs, data.ID)

`

``

183

`+

}

`

``

184

+

``

185

`+

if len(nonCompliantIDs) > 0 {

`

``

186

`+

return ruleresult.Fail, strings.Join(nonCompliantIDs, ", ")

`

``

187

`+

}

`

``

188

+

``

189

`+

return ruleresult.Pass, ""

`

``

190

`+

}

`

``

191

+

``

192

`+

// PackageIndexPackagesPlatformsURLDeadLink checks for dead links in packages[].platforms[].url.

`

``

193

`+

func PackageIndexPackagesPlatformsURLDeadLink() (result ruleresult.Type, output string) {

`

``

194

`+

if projectdata.PackageIndexLoadError() != nil {

`

``

195

`+

return ruleresult.NotRun, "Error loading package index"

`

``

196

`+

}

`

``

197

+

``

198

`+

nonCompliantIDs := []string{}

`

``

199

`+

for _, data := range projectdata.PackageIndexPlatforms() {

`

``

200

`+

url, ok := data.Object["url"].(string)

`

``

201

`+

if !ok {

`

``

202

`+

continue

`

``

203

`+

}

`

``

204

+

``

205

`+

if url == "" {

`

``

206

`+

continue

`

``

207

`+

}

`

``

208

+

``

209

`+

if checkURL(url) == nil {

`

``

210

`+

continue

`

``

211

`+

}

`

``

212

+

``

213

`+

nonCompliantIDs = append(nonCompliantIDs, data.ID)

`

``

214

`+

}

`

``

215

+

``

216

`+

if len(nonCompliantIDs) > 0 {

`

``

217

`+

return ruleresult.Fail, strings.Join(nonCompliantIDs, ", ")

`

``

218

`+

}

`

``

219

+

``

220

`+

return ruleresult.Pass, ""

`

``

221

`+

}

`

``

222

+

``

223

`+

// PackageIndexPackagesToolsSystemsURLDeadLink checks for dead links in packages[].tools[].systems[].url.

`

``

224

`+

func PackageIndexPackagesToolsSystemsURLDeadLink() (result ruleresult.Type, output string) {

`

``

225

`+

if projectdata.PackageIndexLoadError() != nil {

`

``

226

`+

return ruleresult.NotRun, "Error loading package index"

`

``

227

`+

}

`

``

228

+

``

229

`+

nonCompliantIDs := []string{}

`

``

230

`+

for _, data := range projectdata.PackageIndexSystems() {

`

``

231

`+

url, ok := data.Object["url"].(string)

`

``

232

`+

if !ok {

`

``

233

`+

continue

`

``

234

`+

}

`

``

235

+

``

236

`+

if url == "" {

`

``

237

`+

continue

`

``

238

`+

}

`

``

239

+

``

240

`+

if checkURL(url) == nil {

`

``

241

`+

continue

`

``

242

`+

}

`

``

243

+

``

244

`+

nonCompliantIDs = append(nonCompliantIDs, data.ID)

`

``

245

`+

}

`

``

246

+

``

247

`+

if len(nonCompliantIDs) > 0 {

`

``

248

`+

return ruleresult.Fail, strings.Join(nonCompliantIDs, ", ")

`

``

249

`+

}

`

``

250

+

``

251

`+

return ruleresult.Pass, ""

`

``

252

`+

}

`