lint.scm 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014 Cyril Roelandt <tipecaml@gmail.com>
  3. ;;; Copyright © 2014, 2015 Eric Bavier <bavier@member.fsf.org>
  4. ;;; Copyright © 2013-2023 Ludovic Courtès <ludo@gnu.org>
  5. ;;; Copyright © 2015, 2016 Mathieu Lirzin <mthl@gnu.org>
  6. ;;; Copyright © 2016 Danny Milosavljevic <dannym+a@scratchpost.org>
  7. ;;; Copyright © 2016 Hartmut Goebel <h.goebel@crazy-compilers.com>
  8. ;;; Copyright © 2017 Alex Kost <alezost@gmail.com>
  9. ;;; Copyright © 2017, 2021 Tobias Geerinckx-Rice <me@tobias.gr>
  10. ;;; Copyright © 2017, 2018, 2020 Efraim Flashner <efraim@flashner.co.il>
  11. ;;; Copyright © 2018, 2019 Arun Isaac <arunisaac@systemreboot.net>
  12. ;;; Copyright © 2020 Chris Marusich <cmmarusich@gmail.com>
  13. ;;; Copyright © 2020 Timothy Sample <samplet@ngyro.com>
  14. ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
  15. ;;; Copyright © 2021, 2022 Maxime Devos <maximedevos@telenet.be>
  16. ;;; Copyright © 2021 Brice Waegeneire <brice@waegenei.re>
  17. ;;;
  18. ;;; This file is part of GNU Guix.
  19. ;;;
  20. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  21. ;;; under the terms of the GNU General Public License as published by
  22. ;;; the Free Software Foundation; either version 3 of the License, or (at
  23. ;;; your option) any later version.
  24. ;;;
  25. ;;; GNU Guix is distributed in the hope that it will be useful, but
  26. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  27. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. ;;; GNU General Public License for more details.
  29. ;;;
  30. ;;; You should have received a copy of the GNU General Public License
  31. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  32. (define-module (guix lint)
  33. #:use-module (guix store)
  34. #:autoload (guix base16) (bytevector->base16-string)
  35. #:autoload (guix base64) (base64-encode)
  36. #:use-module (guix build-system)
  37. #:use-module (guix diagnostics)
  38. #:use-module (guix download)
  39. #:use-module (guix ftp-client)
  40. #:use-module (guix http-client)
  41. #:use-module (guix packages)
  42. #:use-module (guix i18n)
  43. #:use-module ((guix gexp)
  44. #:select (gexp? local-file? local-file-absolute-file-name
  45. gexp->approximate-sexp))
  46. #:use-module (guix licenses)
  47. #:use-module (guix records)
  48. #:use-module (guix upstream)
  49. #:use-module (guix utils)
  50. #:use-module (guix memoization)
  51. #:use-module (guix profiles)
  52. #:use-module (guix monads)
  53. #:use-module (guix scripts)
  54. #:use-module ((guix ui) #:select (texi->plain-text fill-paragraph))
  55. #:use-module (guix gnu-maintenance)
  56. #:use-module (guix cve)
  57. #:use-module ((guix swh) #:hide (origin?))
  58. #:autoload (guix git-download) (git-reference?
  59. git-reference-url git-reference-commit)
  60. #:autoload (guix svn-download) (svn-reference?
  61. svn-reference-url
  62. svn-reference-user-name
  63. svn-reference-password
  64. svn-multi-reference?
  65. svn-multi-reference-url
  66. svn-multi-reference-user-name
  67. svn-multi-reference-password)
  68. #:use-module (guix import stackage)
  69. #:use-module (ice-9 match)
  70. #:use-module (ice-9 regex)
  71. #:use-module (ice-9 format)
  72. #:autoload (rnrs bytevectors) (string->utf8)
  73. #:use-module (web client)
  74. #:use-module (web uri)
  75. #:use-module ((guix build download)
  76. #:select (maybe-expand-mirrors
  77. (open-connection-for-uri
  78. . guix:open-connection-for-uri)))
  79. #:use-module (web request)
  80. #:use-module (web response)
  81. #:autoload (gnutls) (error->string)
  82. #:use-module (srfi srfi-1)
  83. #:use-module (srfi srfi-6) ;Unicode string ports
  84. #:use-module (srfi srfi-9)
  85. #:use-module (srfi srfi-11)
  86. #:use-module (srfi srfi-26)
  87. #:use-module (srfi srfi-34)
  88. #:use-module (srfi srfi-35)
  89. #:use-module (ice-9 rdelim)
  90. #:export (check-description-style
  91. check-inputs-should-be-native
  92. check-inputs-should-not-be-an-input-at-all
  93. check-input-labels
  94. check-wrapper-inputs
  95. check-patch-file-names
  96. check-patch-headers
  97. check-synopsis-style
  98. check-derivation
  99. check-home-page
  100. check-name
  101. check-source
  102. check-source-file-name
  103. check-source-unstable-tarball
  104. check-optional-tests
  105. check-mirror-url
  106. check-github-url
  107. check-license
  108. check-vulnerabilities
  109. check-for-updates
  110. check-formatting
  111. check-archival
  112. check-profile-collisions
  113. check-haskell-stackage
  114. check-tests-true
  115. lint-warning
  116. lint-warning?
  117. lint-warning-package
  118. lint-warning-message
  119. lint-warning-message-text
  120. lint-warning-message-data
  121. lint-warning-location
  122. %local-checkers
  123. %network-dependent-checkers
  124. %all-checkers
  125. lint-checker
  126. lint-checker?
  127. lint-checker-name
  128. lint-checker-description
  129. lint-checker-check
  130. lint-checker-requires-store?))
  131. ;;;
  132. ;;; Warnings
  133. ;;;
  134. (define-record-type* <lint-warning>
  135. lint-warning make-lint-warning
  136. lint-warning?
  137. (package lint-warning-package)
  138. (message-text lint-warning-message-text)
  139. (message-data lint-warning-message-data
  140. (default '()))
  141. (location lint-warning-location
  142. (default #f)))
  143. (define (lint-warning-message warning)
  144. (apply format #f
  145. (G_ (lint-warning-message-text warning))
  146. (lint-warning-message-data warning)))
  147. (define (package-file package)
  148. (location-file
  149. (package-location package)))
  150. (define* (%make-warning package message-text
  151. #:optional (message-data '())
  152. #:key field location)
  153. (make-lint-warning
  154. package
  155. message-text
  156. message-data
  157. (or location
  158. (and field (package-field-location package field))
  159. (package-location package))))
  160. (define-syntax make-warning
  161. (syntax-rules (G_)
  162. ((_ package (G_ message) rest ...)
  163. (%make-warning package message rest ...))))
  164. ;;;
  165. ;;; Procedures for analysing Scheme code in package definitions
  166. ;;;
  167. (define* (find-procedure-body expression found
  168. #:key (not-found (const '())))
  169. "Try to find the body of the procedure defined inline by EXPRESSION.
  170. If it was found, call FOUND with its body. If it wasn't, call
  171. the thunk NOT-FOUND."
  172. (match expression
  173. (`(,(or 'let 'let*) . ,_)
  174. (find-procedure-body (car (last-pair expression)) found
  175. #:not-found not-found))
  176. (`(,(or 'lambda 'lambda*) ,_ . ,code)
  177. (found code))
  178. (_ (not-found))))
  179. (define* (report-bogus-phase-deltas package bogus-deltas)
  180. "Report a bogus invocation of ‘modify-phases’."
  181. (list (make-warning package
  182. ;; TRANSLATORS: 'modify-phases' is a Scheme syntax
  183. ;; and should not be translated.
  184. (G_ "incorrect call to ‘modify-phases’")
  185. #:field 'arguments)))
  186. (define* (find-phase-deltas package found
  187. #:key (not-found (const '()))
  188. (bogus
  189. (cut report-bogus-phase-deltas package <>)))
  190. "Try to find the clauses of the ‘modify-phases’ form in the phases
  191. specification of PACKAGE. If they were found, all FOUND with a list
  192. of the clauses. If they weren't (e.g. because ‘modify-phases’ wasn't
  193. used at all), call the thunk NOT-FOUND instead. If ‘modify-phases’
  194. was used, but the clauses don't form a list, call BOGUS with the
  195. not-a-list."
  196. (apply (lambda* (#:key phases #:allow-other-keys)
  197. (define phases/sexp
  198. (if (gexp? phases)
  199. (gexp->approximate-sexp phases)
  200. phases))
  201. (match phases/sexp
  202. (`(modify-phases ,_ . ,changes)
  203. ((if (list? changes) found bogus) changes))
  204. (_ (not-found))))
  205. (package-arguments package)))
  206. (define (report-bogus-phase-procedure package)
  207. "Report a syntactically-invalid phase clause."
  208. (list (make-warning package
  209. ;; TRANSLATORS: See ‘modify-phases’ in the manual.
  210. (G_ "invalid phase clause")
  211. #:field 'arguments)))
  212. (define* (find-phase-procedure package expression found
  213. #:key (not-found (const '()))
  214. (bogus (cut report-bogus-phase-procedure
  215. package)))
  216. "Try to find the procedure in the phase clause EXPRESSION. If it was
  217. found, call FOUND with the procedure expression. If EXPRESSION isn't
  218. actually a phase clause, call the thunk BOGUS. If the phase form doesn't
  219. have a procedure, call the thunk NOT-FOUND."
  220. (match expression
  221. (('add-after before after proc-expr)
  222. (found proc-expr))
  223. (('add-before after before proc-expr)
  224. (found proc-expr))
  225. (('replace _ proc-expr)
  226. (found proc-expr))
  227. (('delete _) (not-found))
  228. (_ (bogus))))
  229. ;;;
  230. ;;; Checkers
  231. ;;;
  232. (define-record-type* <lint-checker>
  233. lint-checker make-lint-checker
  234. lint-checker?
  235. ;; TODO: add a 'certainty' field that shows how confident we are in the
  236. ;; checker. Then allow users to only run checkers that have a certain
  237. ;; 'certainty' level.
  238. (name lint-checker-name)
  239. (description lint-checker-description)
  240. (check lint-checker-check)
  241. (requires-store? lint-checker-requires-store?
  242. (default #f)))
  243. (define (check-name package)
  244. "Check whether PACKAGE's name matches our guidelines."
  245. (let ((name (package-name package)))
  246. (cond
  247. ;; Currently checks only whether the name is too short.
  248. ((and (<= (string-length name) 1)
  249. (not (string=? name "r"))) ; common-sense exception
  250. (list
  251. (make-warning package
  252. (G_ "name should be longer than a single character")
  253. #:field 'name)))
  254. ((string-index name #\_)
  255. (list
  256. (make-warning package
  257. (G_ "name should use hyphens instead of underscores")
  258. #:field 'name)))
  259. (else '()))))
  260. (define (check-tests-true package)
  261. "Check whether PACKAGE explicitly requests to run tests, which is
  262. superfluous when building natively and incorrect when cross-compiling."
  263. (define (tests-explicitly-enabled?)
  264. (apply (lambda* (#:key tests? #:allow-other-keys)
  265. (eq? tests? #t))
  266. (package-arguments package)))
  267. (if (and (tests-explicitly-enabled?)
  268. ;; emacs-build-system sets #:tests? #f by default, therefore
  269. ;; writing #:tests? #t in package definitions using
  270. ;; emacs-build-system is reasonable. Likewise for
  271. ;; texlive-build-system.
  272. ;;
  273. ;; Compare the name of the build system instead of the build system
  274. ;; itself to avoid loading unnecessary modules when only a few
  275. ;; modules are linted.
  276. (not (memq (build-system-name (package-build-system package))
  277. '(emacs texlive)))
  278. ;; Some packages, e.g. gnutls, set #:tests?
  279. ;; differently depending on whether it is being
  280. ;; cross-compiled.
  281. (parameterize ((%current-target-system "aarch64-linux-gnu"))
  282. (tests-explicitly-enabled?)))
  283. (list (make-warning package
  284. ;; TRANSLATORS: #:tests? and #t are Scheme constants
  285. ;; and must not be translated.
  286. (G_ "#:tests? must not be explicitly set to #t")
  287. #:field 'arguments))
  288. '()))
  289. (define (properly-starts-sentence? s)
  290. (string-match "^[(\"'`[:upper:][:digit:]]" s))
  291. (define (starts-with-abbreviation? s)
  292. "Return #t if S starts with what looks like an abbreviation or acronym."
  293. (string-match "^[A-Z][A-Z0-9]+\\>" s))
  294. (define %quoted-identifier-rx
  295. ;; A quoted identifier, like 'this'.
  296. (make-regexp "['`][[:graph:]]+'"))
  297. (define (check-description-style package)
  298. ;; Emit a warning if stylistic issues are found in the description of PACKAGE.
  299. (define (check-not-empty description)
  300. (if (string-null? description)
  301. (list
  302. (make-warning package
  303. (G_ "description should not be empty")
  304. #:field 'description))
  305. '()))
  306. (define (check-texinfo-markup description)
  307. "Check that DESCRIPTION can be parsed as a Texinfo fragment. If the
  308. markup is valid return a plain-text version of DESCRIPTION, otherwise #f."
  309. (catch #t
  310. (lambda () (texi->plain-text description))
  311. (lambda (keys . args)
  312. (make-warning package
  313. (G_ "Texinfo markup in description is invalid")
  314. #:field 'description))))
  315. (define (check-description-typo description typo-corrections)
  316. "Check that DESCRIPTION does not contain typo, with optional correction"
  317. (append-map
  318. (match-lambda
  319. ((typo . correction)
  320. (if (string-contains description typo)
  321. (list
  322. (make-warning package
  323. (G_
  324. (format #false
  325. "description contains typo '~a'~@[, should be '~a'~]"
  326. typo correction))))
  327. '())))
  328. typo-corrections))
  329. (define (check-trademarks description)
  330. "Check that DESCRIPTION does not contain '™' or '®' characters. See
  331. http://www.gnu.org/prep/standards/html_node/Trademarks.html."
  332. (match (string-index description (char-set #\™ #\®))
  333. ((and (? number?) index)
  334. (list
  335. (make-warning package
  336. (G_ "description should not contain ~
  337. trademark sign '~a' at ~d")
  338. (list (string-ref description index) index)
  339. #:field 'description)))
  340. (else '())))
  341. (define (check-quotes description)
  342. "Check whether DESCRIPTION contains single quotes and suggest @code."
  343. (if (regexp-exec %quoted-identifier-rx description)
  344. (list
  345. (make-warning package
  346. ;; TRANSLATORS: '@code' is Texinfo markup and must be kept
  347. ;; as is.
  348. (G_ "use @code or similar ornament instead of quotes")
  349. #:field 'description))
  350. '()))
  351. (define (check-proper-start description)
  352. (if (or (string-null? description)
  353. (properly-starts-sentence? description)
  354. (string-prefix-ci? (package-name package) description))
  355. '()
  356. (list
  357. (make-warning
  358. package
  359. (G_ "description should start with an upper-case letter or digit")
  360. #:field 'description))))
  361. (define (check-end-of-sentence-space description)
  362. "Check that an end-of-sentence period is followed by two spaces."
  363. (let ((infractions
  364. (reverse (fold-matches
  365. "\\. [A-Z]" description '()
  366. (lambda (m r)
  367. ;; Filter out matches of common abbreviations.
  368. (if (find (lambda (s)
  369. (string-suffix-ci? s (match:prefix m)))
  370. '("i.e" "e.g" "a.k.a" "resp"))
  371. r (cons (match:start m) r)))))))
  372. (if (null? infractions)
  373. '()
  374. (list
  375. (make-warning package
  376. (G_ "sentences in description should be followed ~
  377. by two spaces; possible infraction~p at ~{~a~^, ~}")
  378. (list (length infractions)
  379. infractions)
  380. #:field 'description)))))
  381. (define (check-no-leading-whitespace description)
  382. "Check that DESCRIPTION doesn't have trailing whitespace."
  383. (if (string-prefix? " " description)
  384. (list
  385. (make-warning package
  386. (G_ "description contains leading whitespace")
  387. #:field 'description))
  388. '()))
  389. (define (check-no-trailing-whitespace description)
  390. "Check that DESCRIPTION doesn't have trailing whitespace."
  391. (if (string-suffix? " " description)
  392. (list
  393. (make-warning package
  394. (G_ "description contains trailing whitespace")
  395. #:field 'description))
  396. '()))
  397. (let ((description (package-description package)))
  398. (if (string? description)
  399. (append
  400. (check-not-empty description)
  401. (check-quotes description)
  402. (check-trademarks description)
  403. (check-description-typo description '(("This packages" . "This package")
  404. ("This modules" . "This module")
  405. ("allows to" . #f)
  406. ("permits to" . #f)))
  407. ;; Use raw description for this because Texinfo rendering
  408. ;; automatically fixes end of sentence space.
  409. (check-end-of-sentence-space description)
  410. (check-no-leading-whitespace description)
  411. (check-no-trailing-whitespace description)
  412. (match (check-texinfo-markup description)
  413. ((and warning (? lint-warning?)) (list warning))
  414. (plain-description
  415. (check-proper-start plain-description))))
  416. (list
  417. (make-warning package
  418. (G_ "invalid description: ~s")
  419. (list description)
  420. #:field 'description)))))
  421. (define (package-input-intersection inputs-to-check input-names)
  422. "Return the intersection between INPUTS-TO-CHECK, the list of input tuples
  423. of a package, and INPUT-NAMES, a list of package specifications such as
  424. \"glib:bin\"."
  425. (match inputs-to-check
  426. (((labels packages . outputs) ...)
  427. (filter-map (lambda (package output)
  428. (and (package? package)
  429. (let ((input (string-append
  430. (package-name package)
  431. (if (> (length output) 0)
  432. (string-append ":" (car output))
  433. ""))))
  434. (and (member input input-names)
  435. input))))
  436. packages outputs))))
  437. (define (check-inputs-should-be-native package)
  438. ;; Emit a warning if some inputs of PACKAGE are likely to belong to its
  439. ;; native inputs.
  440. (let ((inputs (append (package-inputs package)
  441. (package-propagated-inputs package)))
  442. (input-names
  443. '("pkg-config"
  444. "autoconf"
  445. "automake"
  446. "bison"
  447. "cmake"
  448. "dejagnu"
  449. "desktop-file-utils"
  450. "doxygen"
  451. "extra-cmake-modules"
  452. "flex"
  453. "gettext"
  454. "glib:bin"
  455. "gobject-introspection"
  456. "googletest-source"
  457. "groff"
  458. "gtk-doc"
  459. "help2man"
  460. "intltool"
  461. "itstool"
  462. "kdoctools"
  463. "libtool"
  464. "m4"
  465. "qttools-5"
  466. "yasm" "nasm" "fasm"
  467. "python-coverage"
  468. "python-cython"
  469. "python-docutils"
  470. "python-mock"
  471. "python-nose"
  472. "python-pbr"
  473. "python-pytest"
  474. "python-pytest-cov"
  475. "python-setuptools-scm"
  476. "python-sphinx"
  477. "scdoc"
  478. "swig"
  479. "qmake"
  480. "qttools-5"
  481. "texinfo"
  482. "xorg-server-for-tests"
  483. "yelp-tools")))
  484. (map (lambda (input)
  485. (make-warning
  486. package
  487. (G_ "'~a' should probably be a native input")
  488. (list input)
  489. #:field 'inputs))
  490. (package-input-intersection inputs input-names))))
  491. (define (check-inputs-should-not-be-an-input-at-all package)
  492. ;; Emit a warning if some inputs of PACKAGE are likely to should not be
  493. ;; an input at all.
  494. (let ((input-names '("python-setuptools"
  495. "python-pip"
  496. "python-pre-commit")))
  497. (map (lambda (input)
  498. (make-warning
  499. package
  500. (G_ "'~a' should probably not be an input at all")
  501. (list input)
  502. #:field 'inputs))
  503. (package-input-intersection (package-direct-inputs package)
  504. input-names))))
  505. (define (check-input-labels package)
  506. "Emit a warning for labels that differ from the corresponding package name."
  507. (define (check input-kind package-inputs)
  508. (define (warning label name)
  509. (make-warning package
  510. (G_ "label '~a' does not match package name '~a'")
  511. (list label name)
  512. #:field input-kind))
  513. (append-map (match-lambda
  514. (((? string? label) (? package? dependency))
  515. (if (string=? label (package-name dependency))
  516. '()
  517. (list (warning label (package-name dependency)))))
  518. (((? string? label) (? package? dependency) output)
  519. (let ((expected (string-append (package-name dependency)
  520. ":" output)))
  521. (if (string=? label expected)
  522. '()
  523. (list (warning label expected)))))
  524. (_
  525. '()))
  526. (package-inputs package)))
  527. (append-map (match-lambda
  528. ((kind proc)
  529. (check kind proc)))
  530. `((native-inputs ,package-native-inputs)
  531. (inputs ,package-inputs)
  532. (propagated-inputs ,package-propagated-inputs))))
  533. (define (report-wrap-program-error package wrapper-name)
  534. "Warn that \"bash-minimal\" is missing from 'inputs', while WRAPPER-NAME
  535. requires it."
  536. (make-warning package
  537. (G_ "\"bash-minimal\" should be in 'inputs' when '~a' is used")
  538. (list wrapper-name)))
  539. (define (check-wrapper-inputs package)
  540. "Emit a warning if PACKAGE uses 'wrap-program' or similar, but \"bash\"
  541. or \"bash-minimal\" is not in its inputs. 'wrap-script' is not supported."
  542. (define input-names '("bash" "bash-minimal"))
  543. (define has-bash-input?
  544. (pair? (package-input-intersection (package-inputs package)
  545. input-names)))
  546. (define (check-procedure-body body)
  547. (match body
  548. ;; Explicitely setting an interpreter is acceptable.
  549. (('wrap-program _ '#:sh . _) '())
  550. (('wrap-program _ . _)
  551. (list (report-wrap-program-error package 'wrap-program)))
  552. ;; Wrapper of 'wrap-program' for Qt programs.
  553. (('wrap-qt-program _ '#:sh . _) '())
  554. (('wrap-qt-program _ . _)
  555. (list (report-wrap-program-error package 'wrap-qt-program)))
  556. ((x . y)
  557. (append (check-procedure-body x) (check-procedure-body y)))
  558. (_ '())))
  559. (define (check-phase-procedure expression)
  560. (find-procedure-body expression check-procedure-body))
  561. (define (check-delta expression)
  562. (find-phase-procedure package expression check-phase-procedure))
  563. (define (check-deltas deltas)
  564. (append-map check-delta deltas))
  565. (if has-bash-input?
  566. ;; "bash" (or "bash-minimal") is in 'inputs', so everything seems ok.
  567. '()
  568. ;; "bash" is not in 'inputs'. Verify 'wrap-program' and friends
  569. ;; are unused
  570. (find-phase-deltas package check-deltas)))
  571. (define (package-name-regexp package)
  572. "Return a regexp that matches PACKAGE's name as a word at the beginning of a
  573. line."
  574. (make-regexp (string-append "^" (regexp-quote (package-name package))
  575. "\\>")
  576. regexp/icase))
  577. (define (check-synopsis-style package)
  578. ;; Emit a warning if stylistic issues are found in the synopsis of PACKAGE.
  579. (define (check-final-period synopsis)
  580. ;; Synopsis should not end with a period, except for some special cases.
  581. (if (and (string-suffix? "." synopsis)
  582. (not (string-suffix? "etc." synopsis)))
  583. (list
  584. (make-warning package
  585. (G_ "no period allowed at the end of the synopsis")
  586. #:field 'synopsis))
  587. '()))
  588. (define check-start-article
  589. ;; Skip this check for GNU packages, as suggested by Karl Berry's reply to
  590. ;; <http://lists.gnu.org/archive/html/bug-womb/2014-11/msg00000.html>.
  591. (if (false-if-exception (gnu-package? package))
  592. (const '())
  593. (lambda (synopsis)
  594. (if (or (string-prefix-ci? "A " synopsis)
  595. (string-prefix-ci? "An " synopsis))
  596. (list
  597. (make-warning package
  598. (G_ "no article allowed at the beginning of \
  599. the synopsis")
  600. #:field 'synopsis))
  601. '()))))
  602. (define (check-synopsis-length synopsis)
  603. (if (>= (string-length synopsis) 80)
  604. (list
  605. (make-warning package
  606. (G_ "synopsis should be less than 80 characters long")
  607. #:field 'synopsis))
  608. '()))
  609. (define (check-proper-start synopsis)
  610. (if (properly-starts-sentence? synopsis)
  611. '()
  612. (list
  613. (make-warning package
  614. (G_ "synopsis should start with an upper-case letter or digit")
  615. #:field 'synopsis))))
  616. (define (check-start-with-package-name synopsis)
  617. (if (and (regexp-exec (package-name-regexp package) synopsis)
  618. (not (starts-with-abbreviation? synopsis)))
  619. (list
  620. (make-warning package
  621. (G_ "synopsis should not start with the package name")
  622. #:field 'synopsis))
  623. '()))
  624. (define (check-texinfo-markup synopsis)
  625. "Check that SYNOPSIS can be parsed as a Texinfo fragment. If the
  626. markup is valid return a plain-text version of SYNOPSIS, otherwise #f."
  627. (catch #t
  628. (lambda ()
  629. (texi->plain-text synopsis)
  630. '())
  631. (lambda (keys . args)
  632. (list
  633. (make-warning package
  634. (G_ "Texinfo markup in synopsis is invalid")
  635. #:field 'synopsis)))))
  636. (define (check-no-trailing-whitespace synopsis)
  637. "Check that SYNOPSIS doesn't have trailing whitespace."
  638. (if (string-suffix? " " synopsis)
  639. (list
  640. (make-warning package
  641. (G_ "synopsis contains trailing whitespace")
  642. #:field 'synopsis))
  643. '()))
  644. (define checks
  645. (list check-proper-start
  646. check-final-period
  647. check-start-article
  648. check-start-with-package-name
  649. check-synopsis-length
  650. check-texinfo-markup
  651. check-no-trailing-whitespace))
  652. (match (package-synopsis package)
  653. (""
  654. (list
  655. (make-warning package
  656. (G_ "synopsis should not be empty")
  657. #:field 'synopsis)))
  658. ((? string? synopsis)
  659. (append-map
  660. (lambda (proc)
  661. (proc synopsis))
  662. checks))
  663. (invalid
  664. (list
  665. (make-warning package
  666. (G_ "invalid synopsis: ~s")
  667. (list invalid)
  668. #:field 'synopsis)))))
  669. (define* (probe-uri uri #:key timeout)
  670. "Probe URI, a URI object, and return two values: a symbol denoting the
  671. probing status, such as 'http-response' when we managed to get an HTTP
  672. response from URI, and additional details, such as the actual HTTP response.
  673. TIMEOUT is the maximum number of seconds (possibly an inexact number) to wait
  674. for connections to complete; when TIMEOUT is #f, wait as long as needed."
  675. (define headers
  676. `((User-Agent . "GNU Guile")
  677. (Accept . "*/*")
  678. ,@(match (uri-userinfo uri)
  679. ((? string? str) ;"basic authentication"
  680. `((Authorization . ,(string-append "Basic "
  681. (base64-encode
  682. (string->utf8 str))))))
  683. (_ '()))))
  684. (let loop ((uri uri)
  685. (visited '()))
  686. (match (uri-scheme uri)
  687. ((or 'http 'https)
  688. (catch #t
  689. (lambda ()
  690. (let ((port (guix:open-connection-for-uri
  691. uri #:timeout timeout))
  692. (request (build-request uri #:headers headers)))
  693. (define response
  694. (dynamic-wind
  695. (const #f)
  696. (lambda ()
  697. (write-request request port)
  698. (force-output port)
  699. (read-response port))
  700. (lambda ()
  701. (close-port port))))
  702. (case (response-code response)
  703. ((302 ; found (redirection)
  704. 303 ; see other
  705. 307 ; temporary redirection
  706. 308) ; permanent redirection
  707. (let ((location (response-location response)))
  708. (if (or (not location) (member location visited))
  709. (values 'http-response response)
  710. (loop location (cons location visited))))) ;follow the redirect
  711. ((301) ; moved permanently
  712. (let ((location (response-location response)))
  713. ;; Return RESPONSE, unless the final response as we follow
  714. ;; redirects is not 200.
  715. (if location
  716. (let-values (((status response2)
  717. (loop location (cons location visited))))
  718. (case status
  719. ((http-response)
  720. (values 'http-response
  721. (if (= 200 (response-code response2))
  722. response
  723. response2)))
  724. (else
  725. (values status response2))))
  726. (values 'http-response response)))) ;invalid redirect
  727. (else
  728. (values 'http-response response)))))
  729. (lambda (key . args)
  730. (case key
  731. ((bad-header bad-header-component)
  732. ;; This can happen if the server returns an invalid HTTP header,
  733. ;; as is the case with the 'Date' header at sqlite.org.
  734. (values 'invalid-http-response #f))
  735. ((getaddrinfo-error system-error
  736. gnutls-error tls-certificate-error)
  737. (values key args))
  738. (else
  739. (apply throw key args))))))
  740. ('ftp
  741. (catch #t
  742. (lambda ()
  743. (let ((conn (ftp-open (uri-host uri) #:timeout timeout)))
  744. (define response
  745. (dynamic-wind
  746. (const #f)
  747. (lambda ()
  748. (ftp-chdir conn (dirname (uri-path uri)))
  749. (ftp-size conn (basename (uri-path uri))))
  750. (lambda ()
  751. (ftp-close conn))))
  752. (values 'ftp-response '(ok))))
  753. (lambda (key . args)
  754. (case key
  755. ((ftp-error)
  756. (values 'ftp-response `(error ,@args)))
  757. ((getaddrinfo-error system-error gnutls-error)
  758. (values key args))
  759. (else
  760. (apply throw key args))))))
  761. (_
  762. (values 'unknown-protocol #f)))))
  763. (define (call-with-networking-fail-safe message error-value proc)
  764. "Call PROC catching any network-related errors. Upon a networking error,
  765. display a message including MESSAGE and return ERROR-VALUE."
  766. (guard (c ((http-get-error? c)
  767. (warning (G_ "~a: HTTP GET error for ~a: ~a (~s)~%")
  768. message
  769. (uri->string (http-get-error-uri c))
  770. (http-get-error-code c)
  771. (http-get-error-reason c))
  772. error-value))
  773. (catch #t
  774. proc
  775. (match-lambda*
  776. (('getaddrinfo-error errcode)
  777. (warning (G_ "~a: host lookup failure: ~a~%")
  778. message
  779. (gai-strerror errcode))
  780. error-value)
  781. (('tls-certificate-error args ...)
  782. (warning (G_ "~a: TLS certificate error: ~a")
  783. message
  784. (tls-certificate-error-string args))
  785. error-value)
  786. (('gnutls-error error function _ ...)
  787. (warning (G_ "~a: TLS error in '~a': ~a~%")
  788. message
  789. function (error->string error))
  790. error-value)
  791. ((and ('system-error _ ...) args)
  792. (let ((errno (system-error-errno args)))
  793. (if (member errno (list ECONNRESET ECONNABORTED ECONNREFUSED))
  794. (let ((details (call-with-output-string
  795. (lambda (port)
  796. (print-exception port #f (car args)
  797. (cdr args))))))
  798. (warning (G_ "~a: ~a~%") message details)
  799. error-value)
  800. (apply throw args))))
  801. (args
  802. (apply throw args))))))
  803. (define-syntax-rule (with-networking-fail-safe message error-value exp ...)
  804. (call-with-networking-fail-safe message error-value
  805. (lambda () exp ...)))
  806. (define (tls-certificate-error-string args)
  807. "Return a string explaining the 'tls-certificate-error' arguments ARGS."
  808. (call-with-output-string
  809. (lambda (port)
  810. (print-exception port #f
  811. 'tls-certificate-error args))))
  812. (define (validate-uri uri package field)
  813. "Return #t if the given URI can be reached, otherwise return a warning for
  814. PACKAGE mentioning the FIELD."
  815. (let-values (((status argument)
  816. (probe-uri uri #:timeout 3))) ;wait at most 3 seconds
  817. (case status
  818. ((http-response)
  819. (cond ((= 200 (response-code argument))
  820. (match (response-content-length argument)
  821. ((? number? length)
  822. ;; As of July 2016, SourceForge returns 200 (instead of 404)
  823. ;; with a small HTML page upon failure. Attempt to detect
  824. ;; such malicious behavior.
  825. (or (> length 1000)
  826. (make-warning package
  827. (G_ "URI ~a returned \
  828. suspiciously small file (~a bytes)")
  829. (list (uri->string uri)
  830. length)
  831. #:field field)))
  832. (_ #t)))
  833. ((= 301 (response-code argument))
  834. (if (response-location argument)
  835. (make-warning package
  836. (G_ "permanent redirect from ~a to ~a")
  837. (list (uri->string uri)
  838. (uri->string
  839. (response-location argument)))
  840. #:field field)
  841. (make-warning package
  842. (G_ "invalid permanent redirect \
  843. from ~a")
  844. (list (uri->string uri))
  845. #:field field)))
  846. (else
  847. (make-warning package
  848. (G_ "URI ~a not reachable: ~a (~s)")
  849. (list (uri->string uri)
  850. (response-code argument)
  851. (response-reason-phrase argument))
  852. #:field field))))
  853. ((ftp-response)
  854. (match argument
  855. (('ok) #t)
  856. (('error port command code message)
  857. (make-warning package
  858. (G_ "URI ~a not reachable: ~a (~s)")
  859. (list (uri->string uri)
  860. code (string-trim-both message))
  861. #:field field))))
  862. ((getaddrinfo-error)
  863. (make-warning package
  864. (G_ "URI ~a domain not found: ~a")
  865. (list (uri->string uri)
  866. (gai-strerror (car argument)))
  867. #:field field))
  868. ((system-error)
  869. (make-warning package
  870. (G_ "URI ~a unreachable: ~a")
  871. (list (uri->string uri)
  872. (strerror
  873. (system-error-errno
  874. (cons status argument))))
  875. #:field field))
  876. ((tls-certificate-error)
  877. (make-warning package
  878. (G_ "TLS certificate error: ~a")
  879. (list (tls-certificate-error-string argument))
  880. #:field field))
  881. ((invalid-http-response gnutls-error)
  882. ;; Probably a misbehaving server; ignore.
  883. #f)
  884. ((unknown-protocol) ;nothing we can do
  885. #f)
  886. (else
  887. (error "internal linter error" status)))))
  888. (define (check-home-page package)
  889. "Emit a warning if PACKAGE has an invalid 'home-page' field, or if that
  890. 'home-page' is not reachable."
  891. (let ((uri (and=> (package-home-page package) string->uri)))
  892. (cond
  893. ((uri? uri)
  894. (match (validate-uri uri package 'home-page)
  895. ((and (? lint-warning? warning) warning)
  896. (list warning))
  897. (_ '())))
  898. ((not (package-home-page package))
  899. (if (or (string-contains (package-name package) "bootstrap")
  900. (string=? (package-name package) "ld-wrapper"))
  901. '()
  902. (list
  903. (make-warning package
  904. (G_ "invalid value for home page")
  905. #:field 'home-page))))
  906. (else
  907. (list
  908. (make-warning package
  909. (G_ "invalid home page URL: ~s")
  910. (list (package-home-page package))
  911. #:field 'home-page))))))
  912. (define %distro-directory
  913. (mlambda ()
  914. (dirname (search-path %load-path "gnu.scm"))))
  915. (define (check-patch-file-names package)
  916. "Emit a warning if the patches requires by PACKAGE are badly named or if the
  917. patch could not be found."
  918. (guard (c ((formatted-message? c) ;raised by 'search-patch'
  919. (list (%make-warning package
  920. (formatted-message-string c)
  921. (formatted-message-arguments c)
  922. #:field 'source))))
  923. (define patches
  924. (match (package-source package)
  925. ((? origin? origin) (origin-patches origin))
  926. (_ '())))
  927. (define (starts-with-package-name? file-name)
  928. (and=> (string-contains file-name (package-name package))
  929. zero?))
  930. (append
  931. (if (every (match-lambda ;patch starts with package name?
  932. ((? string? patch)
  933. (starts-with-package-name? (basename patch)))
  934. ((? origin? patch)
  935. (starts-with-package-name? (origin-actual-file-name patch)))
  936. (_ #f)) ;must be some other file-like object
  937. patches)
  938. '()
  939. (list
  940. (make-warning
  941. package
  942. (G_ "file names of patches should start with the package name")
  943. #:field 'patch-file-names)))
  944. ;; Check whether we're reaching tar's maximum file name length.
  945. (let ((prefix (string-length (%distro-directory)))
  946. ;; Margin approximating the largest path that "make dist" might
  947. ;; create, with a release candidate version, 123456 commits, and
  948. ;; git commit hash abcde0.
  949. (margin (string-length "guix-92.0.0rc3-123456-abcde0/"))
  950. ;; Tested maximum patch file length for ustar format.
  951. (max 151))
  952. (filter-map (match-lambda
  953. ((? string? patch)
  954. (if (> (+ margin (if (string-prefix? (%distro-directory)
  955. patch)
  956. (- (string-length patch) prefix)
  957. (string-length patch)))
  958. max)
  959. (make-warning
  960. package
  961. (G_ "~a: file name is too long, which may break 'make dist'")
  962. (list (basename patch))
  963. #:field 'patch-file-names)
  964. #f))
  965. (_ #f))
  966. patches)))))
  967. (define (check-patch-headers package)
  968. "Check that PACKAGE's patches start with a comment. Return a list of
  969. warnings."
  970. (define (blank? str)
  971. (string-every char-set:blank str))
  972. (define (patch-header-warnings patch)
  973. (call-with-input-file patch
  974. (lambda (port)
  975. ;; Read from PORT until a non-blank line is found or EOF is reached.
  976. (let loop ()
  977. (let ((line (read-line port)))
  978. (cond ((eof-object? line)
  979. (list (make-warning package
  980. (G_ "~a: empty patch")
  981. (list (basename patch))
  982. #:field 'source)))
  983. ((blank? line)
  984. (loop))
  985. ((or (string-prefix? "--- " line)
  986. (string-prefix? "+++ " line)
  987. (string-prefix? "diff --git " line))
  988. (list (make-warning package
  989. (G_ "~a: patch lacks comment and \
  990. upstream status")
  991. (list (basename patch))
  992. #:field 'source)))
  993. (else
  994. '())))))))
  995. (guard (c ((formatted-message? c) ;raised by 'search-patch'
  996. (list (%make-warning package
  997. (formatted-message-string c)
  998. (formatted-message-arguments c)
  999. #:field 'source))))
  1000. (let ((patches (if (origin? (package-source package))
  1001. (origin-patches (package-source package))
  1002. '())))
  1003. (append-map (lambda (patch)
  1004. ;; Dismiss PATCH if it's an origin or similar.
  1005. (cond ((string? patch)
  1006. (patch-header-warnings patch))
  1007. ((local-file? patch)
  1008. (patch-header-warnings
  1009. (local-file-absolute-file-name patch)))
  1010. (else
  1011. '())))
  1012. patches))))
  1013. (define (escape-quotes str)
  1014. "Replace any quote character in STR by an escaped quote character."
  1015. (list->string
  1016. (string-fold-right (lambda (chr result)
  1017. (match chr
  1018. (#\" (cons* #\\ #\"result))
  1019. (_ (cons chr result))))
  1020. '()
  1021. str)))
  1022. (define official-gnu-packages*
  1023. (mlambda ()
  1024. "A memoizing version of 'official-gnu-packages' that returns the empty
  1025. list when something goes wrong, such as a networking issue."
  1026. (let ((gnus (false-if-exception (official-gnu-packages))))
  1027. (or gnus '()))))
  1028. (define (check-gnu-synopsis+description package)
  1029. "Make sure that, if PACKAGE is a GNU package, it uses the synopsis and
  1030. descriptions maintained upstream."
  1031. (match (find (lambda (descriptor)
  1032. (string=? (gnu-package-name descriptor)
  1033. (package-name package)))
  1034. (official-gnu-packages*))
  1035. (#f ;not a GNU package, so nothing to do
  1036. '())
  1037. (descriptor ;a genuine GNU package
  1038. (append
  1039. (let ((upstream (gnu-package-doc-summary descriptor))
  1040. (downstream (package-synopsis package)))
  1041. (if (and upstream
  1042. (or (not (string? downstream))
  1043. (not (string=? upstream downstream))))
  1044. (list
  1045. (make-warning package
  1046. (G_ "proposed synopsis: ~s~%")
  1047. (list upstream)
  1048. #:field 'synopsis))
  1049. '()))
  1050. (let ((upstream (gnu-package-doc-description descriptor))
  1051. (downstream (package-description package)))
  1052. (if (and upstream
  1053. (or (not (string? downstream))
  1054. (not (string=? (fill-paragraph upstream 100)
  1055. (fill-paragraph downstream 100)))))
  1056. (list
  1057. (make-warning
  1058. package
  1059. (G_ "proposed description:~% \"~a\"~%")
  1060. (list (fill-paragraph (escape-quotes upstream) 77 7))
  1061. #:field 'description))
  1062. '()))))))
  1063. (define (origin-uris origin)
  1064. "Return the list of URIs (strings) for ORIGIN."
  1065. (match (origin-uri origin)
  1066. ((? string? uri)
  1067. (list uri))
  1068. ((uris ...)
  1069. uris)))
  1070. (define (svn-reference-uri-with-userinfo ref)
  1071. "Return the URI of REF, an <svn-reference> or <svn-multi-reference> object,
  1072. but with an additional 'userinfo' part corresponding to REF's user name and
  1073. password, provided REF's URI is HTTP or HTTPS."
  1074. ;; XXX: For lack of record type inheritance.
  1075. (define ->url
  1076. (if (svn-reference? ref)
  1077. svn-reference-url
  1078. svn-multi-reference-url))
  1079. (define ->user-name
  1080. (if (svn-reference? ref)
  1081. svn-reference-user-name
  1082. svn-multi-reference-user-name))
  1083. (define ->password
  1084. (if (svn-reference? ref)
  1085. svn-reference-password
  1086. svn-multi-reference-password))
  1087. (let ((uri (string->uri (->url ref))))
  1088. (if (and (->user-name ref)
  1089. (memq (uri-scheme uri) '(http https)))
  1090. (build-uri (uri-scheme uri)
  1091. #:userinfo
  1092. (string-append (->user-name ref)
  1093. (if (->password ref)
  1094. (string-append
  1095. ":" (->password ref))
  1096. ""))
  1097. #:host (uri-host uri)
  1098. #:port (uri-port uri)
  1099. #:query (uri-query uri)
  1100. #:fragment (uri-fragment uri))
  1101. uri)))
  1102. (define (check-source package)
  1103. "Emit a warning if PACKAGE has an invalid 'source' field, or if that
  1104. 'source' is not reachable."
  1105. (define (warnings-for-uris uris)
  1106. (let loop ((uris uris)
  1107. (warnings '()))
  1108. (match uris
  1109. (()
  1110. (reverse warnings))
  1111. ((uri rest ...)
  1112. (match (validate-uri uri package 'source)
  1113. (#t
  1114. ;; We found a working URL, so stop right away.
  1115. '())
  1116. (#f
  1117. ;; Unsupported URL or other error, skip.
  1118. (loop rest warnings))
  1119. ((? lint-warning? warning)
  1120. (loop rest (cons warning warnings))))))))
  1121. (let ((origin (package-source package)))
  1122. (if (origin? origin)
  1123. (cond
  1124. ((eq? (origin-method origin) url-fetch)
  1125. (let* ((uris (append-map (cut maybe-expand-mirrors <> %mirrors)
  1126. (map string->uri (origin-uris origin))))
  1127. (warnings (warnings-for-uris uris)))
  1128. ;; Just make sure that at least one of the URIs is valid.
  1129. (if (= (length uris) (length warnings))
  1130. ;; When everything fails, report all of WARNINGS, otherwise don't
  1131. ;; report anything.
  1132. ;;
  1133. ;; XXX: Ideally we'd still allow warnings to be raised if *some*
  1134. ;; URIs are unreachable, but distinguish that from the error case
  1135. ;; where *all* the URIs are unreachable.
  1136. (cons*
  1137. (make-warning package
  1138. (G_ "all the source URIs are unreachable:")
  1139. #:field 'source)
  1140. warnings)
  1141. '())))
  1142. ((git-reference? (origin-uri origin))
  1143. (warnings-for-uris
  1144. (list (string->uri (git-reference-url (origin-uri origin))))))
  1145. ((or (svn-reference? (origin-uri origin))
  1146. (svn-multi-reference? (origin-uri origin)))
  1147. (let ((uri (svn-reference-uri-with-userinfo (origin-uri origin))))
  1148. (if (memq (uri-scheme uri) '(http https))
  1149. (warnings-for-uris (list uri))
  1150. '()))) ;TODO: handle svn:// URLs
  1151. (else
  1152. '()))
  1153. '())))
  1154. (define (check-source-file-name package)
  1155. "Emit a warning if PACKAGE's origin has no meaningful file name."
  1156. (define (origin-file-name-valid? origin)
  1157. ;; Return #f if the source file name contains only a version or is #f;
  1158. ;; indicates that the origin needs a 'file-name' field.
  1159. (let ((file-name (origin-actual-file-name origin))
  1160. (version (package-version package)))
  1161. (and file-name
  1162. ;; Common in many projects is for the filename to start
  1163. ;; with a "v" followed by the version,
  1164. ;; e.g. "v3.2.0.tar.gz".
  1165. (not (string-match (string-append "^v?" version) file-name)))))
  1166. (let ((origin (package-source package)))
  1167. (if (or (not (origin? origin)) (origin-file-name-valid? origin))
  1168. '()
  1169. (list
  1170. (make-warning package
  1171. (G_ "the source file name should contain the package name")
  1172. #:field 'source)))))
  1173. (define (check-source-unstable-tarball package)
  1174. "Emit a warning if PACKAGE's source is an autogenerated tarball."
  1175. (define (check-source-uri uri)
  1176. (if (and (string=? (uri-host (string->uri uri)) "github.com")
  1177. (match (split-and-decode-uri-path
  1178. (uri-path (string->uri uri)))
  1179. ((_ _ "archive" _ ...) #t)
  1180. (_ #f)))
  1181. (make-warning package
  1182. (G_ "the source URI should not be an autogenerated tarball")
  1183. #:field 'source)
  1184. #f))
  1185. (let ((origin (package-source package)))
  1186. (if (and (origin? origin)
  1187. (eqv? (origin-method origin) url-fetch))
  1188. (filter-map check-source-uri
  1189. (origin-uris origin))
  1190. '())))
  1191. (define (check-mirror-url package)
  1192. "Check whether PACKAGE uses source URLs that should be 'mirror://'."
  1193. (define (check-mirror-uri uri)
  1194. (define rewritten-uri
  1195. (uri-mirror-rewrite uri))
  1196. (and (not (string=? uri rewritten-uri))
  1197. (make-warning package (G_ "URL should be '~a'")
  1198. (list rewritten-uri)
  1199. #:field 'source)))
  1200. (let ((origin (package-source package)))
  1201. (if (and (origin? origin)
  1202. (eqv? (origin-method origin) url-fetch))
  1203. (let ((uris (origin-uris origin)))
  1204. (filter-map check-mirror-uri uris))
  1205. '())))
  1206. (define* (check-github-url package #:key (timeout 3))
  1207. "Check whether PACKAGE uses source URLs that redirect to GitHub."
  1208. (define (follow-redirect url)
  1209. (let* ((uri (string->uri url))
  1210. (port (guix:open-connection-for-uri uri #:timeout timeout))
  1211. (response (http-head uri #:port port)))
  1212. (close-port port)
  1213. (case (response-code response)
  1214. ((301 302)
  1215. (uri->string (assoc-ref (response-headers response) 'location)))
  1216. (else #f))))
  1217. (define (follow-redirects-to-github uri)
  1218. (cond
  1219. ((string-prefix? "https://github.com/" uri) uri)
  1220. ((string-prefix? "http" uri)
  1221. (and=> (follow-redirect uri) follow-redirects-to-github))
  1222. ;; Do not attempt to follow redirects on URIs other than http and https
  1223. ;; (such as mirror, file)
  1224. (else #f)))
  1225. (let ((origin (package-source package)))
  1226. (if (and (origin? origin)
  1227. (eqv? (origin-method origin) url-fetch))
  1228. (filter-map
  1229. (lambda (uri)
  1230. (and=> (with-networking-fail-safe
  1231. (format #f (G_ "while accessing '~a'") uri)
  1232. #f
  1233. (follow-redirects-to-github uri))
  1234. (lambda (github-uri)
  1235. (and (not (string=? github-uri uri))
  1236. (make-warning
  1237. package
  1238. (G_ "URL should be '~a'")
  1239. (list github-uri)
  1240. #:field 'source)))))
  1241. (origin-uris origin))
  1242. '())))
  1243. ;; Guile 3.0.0 does not export this predicate.
  1244. (define exception-with-kind-and-args?
  1245. (exception-predicate &exception-with-kind-and-args))
  1246. (define (check-optional-tests package)
  1247. "Emit a warning if the test suite is run unconditionally."
  1248. (define (sexp-contains-atom? sexp atom)
  1249. "Test if SEXP contains ATOM."
  1250. (if (pair? sexp)
  1251. (or (sexp-contains-atom? (car sexp) atom)
  1252. (sexp-contains-atom? (cdr sexp) atom))
  1253. (eq? sexp atom)))
  1254. (define (sexp-uses-tests?? sexp)
  1255. "Test if SEXP contains the symbol 'tests?'."
  1256. (sexp-contains-atom? sexp 'tests?))
  1257. (define (check-procedure-body code)
  1258. (if (sexp-uses-tests?? code)
  1259. '()
  1260. (list (make-warning package
  1261. ;; TRANSLATORS: check and #:tests? are a
  1262. ;; Scheme symbol and keyword respectively
  1263. ;; and should not be translated.
  1264. (G_ "the 'check' phase should respect #:tests?")
  1265. #:field 'arguments))))
  1266. (define (check-check-procedure expression)
  1267. (find-procedure-body expression check-procedure-body))
  1268. (define (check-phases-delta delta)
  1269. (match delta
  1270. (`(replace 'check ,expression)
  1271. (check-check-procedure expression))
  1272. (_ '())))
  1273. (define (check-phases-deltas deltas)
  1274. (append-map check-phases-delta deltas))
  1275. (find-phase-deltas package check-phases-deltas))
  1276. (define* (check-derivation package #:key store)
  1277. "Emit a warning if we fail to compile PACKAGE to a derivation."
  1278. (define (try store system)
  1279. (guard (c ((store-protocol-error? c)
  1280. (make-warning package
  1281. (G_ "failed to create ~a derivation: ~a")
  1282. (list system
  1283. (store-protocol-error-message c))))
  1284. ((exception-with-kind-and-args? c)
  1285. (make-warning package
  1286. (G_ "failed to create ~a derivation: ~s")
  1287. (list system
  1288. (cons (exception-kind c)
  1289. (exception-args c)))))
  1290. ((message-condition? c)
  1291. (make-warning package
  1292. (G_ "failed to create ~a derivation: ~a")
  1293. (list system
  1294. (condition-message c))))
  1295. ((formatted-message? c)
  1296. (let ((str (apply format #f
  1297. (formatted-message-string c)
  1298. (formatted-message-arguments c))))
  1299. (make-warning package
  1300. (G_ "failed to create ~a derivation: ~a")
  1301. (list system str))))
  1302. (else
  1303. (make-warning package
  1304. (G_ "failed to create ~a derivation: ~a")
  1305. (list system c))))
  1306. (parameterize ((%graft? #f))
  1307. (package-derivation store package system #:graft? #f)
  1308. ;; If there's a replacement, make sure we can compute its
  1309. ;; derivation.
  1310. (match (package-replacement package)
  1311. (#f #t)
  1312. (replacement
  1313. (package-derivation store replacement system
  1314. #:graft? #f))))))
  1315. (define (check-with-store store)
  1316. (filter lint-warning?
  1317. (map (cut try store <>) (package-supported-systems package))))
  1318. ;; For backwards compatability, don't rely on store being set
  1319. (or (and=> store check-with-store)
  1320. (with-store store
  1321. (check-with-store store))))
  1322. (define* (check-profile-collisions package #:key store)
  1323. "Check for collisions that would occur when installing PACKAGE as a result
  1324. of the propagated inputs it pulls in."
  1325. (define (do-check store)
  1326. (guard (c ((profile-collision-error? c)
  1327. (let ((first (profile-collision-error-entry c))
  1328. (second (profile-collision-error-conflict c)))
  1329. (define format
  1330. (if (string=? (manifest-entry-version first)
  1331. (manifest-entry-version second))
  1332. manifest-entry-item
  1333. (lambda (entry)
  1334. (string-append (manifest-entry-name entry) "@"
  1335. (manifest-entry-version entry)))))
  1336. (list (make-warning package
  1337. (G_ "propagated inputs ~a and ~a collide")
  1338. (list (format first)
  1339. (format second)))))))
  1340. ;; Disable grafts to avoid building PACKAGE and its dependencies.
  1341. (parameterize ((%graft? #f))
  1342. (run-with-store store
  1343. (mbegin %store-monad
  1344. (check-for-collisions (packages->manifest (list package))
  1345. (%current-system))
  1346. (return '()))))))
  1347. (if store
  1348. (do-check store)
  1349. (with-store store
  1350. (do-check store))))
  1351. (define (check-license package)
  1352. "Warn about type errors of the 'license' field of PACKAGE."
  1353. (match (package-license package)
  1354. ((or (? license?)
  1355. ((? license?) ...))
  1356. '())
  1357. (x
  1358. (list
  1359. (make-warning package (G_ "invalid license field")
  1360. #:field 'license)))))
  1361. (define (current-vulnerabilities*)
  1362. "Like 'current-vulnerabilities', but return the empty list upon networking
  1363. or HTTP errors. This allows network-less operation and makes problems with
  1364. the NIST server non-fatal."
  1365. (with-networking-fail-safe (G_ "while retrieving CVE vulnerabilities")
  1366. '()
  1367. (current-vulnerabilities #:timeout 4)))
  1368. (define package-vulnerabilities
  1369. (let ((lookup (delay (vulnerabilities->lookup-proc
  1370. (current-vulnerabilities*)))))
  1371. (lambda (package)
  1372. "Return a list of vulnerabilities affecting PACKAGE."
  1373. ;; First we retrieve the Common Platform Enumeration (CPE) name and
  1374. ;; version for PACKAGE, then we can pass them to LOOKUP.
  1375. (let ((name (or (assoc-ref (package-properties package)
  1376. 'cpe-name)
  1377. (package-name package)))
  1378. (version (or (assoc-ref (package-properties package)
  1379. 'cpe-version)
  1380. (package-version package))))
  1381. ((force lookup) name version)))))
  1382. ;; Prevent Guile 3 from inlining this procedure so we can mock it in tests.
  1383. (set! package-vulnerabilities package-vulnerabilities)
  1384. (define* (check-vulnerabilities package
  1385. #:optional (package-vulnerabilities
  1386. package-vulnerabilities))
  1387. "Check for known vulnerabilities for PACKAGE. Obtain the list of
  1388. vulnerability records for PACKAGE by calling PACKAGE-VULNERABILITIES."
  1389. (let ((package (or (package-replacement package) package)))
  1390. (match (package-vulnerabilities package)
  1391. (()
  1392. '())
  1393. ((vulnerabilities ...)
  1394. (let* ((patched (package-patched-vulnerabilities package))
  1395. (known-safe (or (assq-ref (package-properties package)
  1396. 'lint-hidden-cve)
  1397. '()))
  1398. (unpatched (remove (lambda (vuln)
  1399. (let ((id (vulnerability-id vuln)))
  1400. (or (member id patched)
  1401. (member id known-safe))))
  1402. vulnerabilities)))
  1403. (if (null? unpatched)
  1404. '()
  1405. (list
  1406. (make-warning
  1407. package
  1408. (G_ "probably vulnerable to ~a")
  1409. (list (string-join (map vulnerability-id unpatched)
  1410. ", "))))))))))
  1411. (define (check-for-updates package)
  1412. "Check if there is an update available for PACKAGE."
  1413. (match (lookup-updater package)
  1414. (#f
  1415. (list (make-warning package (G_ "no updater for ~a")
  1416. (list (package-name package))
  1417. #:field 'source)))
  1418. ((? upstream-updater? updater)
  1419. (match (with-networking-fail-safe
  1420. (format #f (G_ "while retrieving upstream info for '~a'")
  1421. (package-name package))
  1422. #f
  1423. (package-latest-release package))
  1424. ((? upstream-source? source)
  1425. (if (version>? (upstream-source-version source)
  1426. (package-version package))
  1427. (list
  1428. (make-warning package
  1429. (G_ "can be upgraded to ~a")
  1430. (list (upstream-source-version source))
  1431. #:field 'version))
  1432. '()))
  1433. (#f ;cannot find upstream release
  1434. (list (make-warning package
  1435. (G_ "updater '~a' failed to find \
  1436. upstream releases")
  1437. (list (upstream-updater-name updater))
  1438. #:field 'source)))))))
  1439. (define (lookup-disarchive-spec hash)
  1440. "If Disarchive mirrors have a spec for HASH, return the list of SWH
  1441. directory identifiers the spec refers to. Otherwise return #f."
  1442. (define (extract-swh-id spec)
  1443. ;; Return the list of SWH directory identifiers SPEC refers to, where SPEC
  1444. ;; is a Disarchive sexp. Instead of attempting to parse it, traverse it
  1445. ;; in a pretty unintelligent fashion.
  1446. (let loop ((sexp spec)
  1447. (ids '()))
  1448. (match sexp
  1449. ((? string? str)
  1450. (let ((prefix "swh:1:dir:"))
  1451. (if (string-prefix? prefix str)
  1452. (cons (string-drop str (string-length prefix)) ids)
  1453. ids)))
  1454. ((head tail ...)
  1455. (loop tail (loop head ids)))
  1456. (_ ids))))
  1457. (any (lambda (mirror)
  1458. (with-networking-fail-safe
  1459. (format #f (G_ "failed to access Disarchive database at ~a")
  1460. mirror)
  1461. #f
  1462. (guard (c ((http-get-error? c) #f))
  1463. (let* ((url (string-append mirror
  1464. (symbol->string
  1465. (content-hash-algorithm hash))
  1466. "/"
  1467. (bytevector->base16-string
  1468. (content-hash-value hash))))
  1469. (port (http-fetch (string->uri url) #:text? #t))
  1470. (spec (read port)))
  1471. (close-port port)
  1472. (extract-swh-id spec)))))
  1473. %disarchive-mirrors))
  1474. (define (check-archival package)
  1475. "Check whether PACKAGE's source code is archived on Software Heritage. If
  1476. it's not, and if its source code is a VCS snapshot, then send a \"save\"
  1477. request to Software Heritage.
  1478. Software Heritage imposes limits on the request rate per client IP address.
  1479. This checker prints a notice and stops doing anything once that limit has been
  1480. reached."
  1481. (define (response->warning url method response)
  1482. (if (request-rate-limit-reached? url method)
  1483. (list (make-warning package
  1484. (G_ "Software Heritage rate limit reached; \
  1485. try again later")
  1486. #:field 'source))
  1487. (list (make-warning package
  1488. (G_ "'~a' returned ~a")
  1489. (list url (response-code response))
  1490. #:field 'source))))
  1491. (define skip-key (gensym "skip-archival-check"))
  1492. (define (skip-when-limit-reached url method)
  1493. (or (not (request-rate-limit-reached? url method))
  1494. (throw skip-key #t)))
  1495. (parameterize ((%allow-request? skip-when-limit-reached))
  1496. (catch #t
  1497. (lambda ()
  1498. (match (package-source package)
  1499. (#f ;no source
  1500. '())
  1501. ((and (? origin?)
  1502. (= origin-uri (? git-reference? reference)))
  1503. (define url
  1504. (git-reference-url reference))
  1505. (define commit
  1506. (git-reference-commit reference))
  1507. (match (if (commit-id? commit)
  1508. (or (lookup-revision commit)
  1509. (lookup-origin-revision url commit))
  1510. (lookup-origin-revision url commit))
  1511. ((? revision? revision)
  1512. '())
  1513. (#f
  1514. ;; Revision is missing from the archive, attempt to save it.
  1515. (catch 'swh-error
  1516. (lambda ()
  1517. (save-origin (git-reference-url reference) "git")
  1518. (list (make-warning
  1519. package
  1520. ;; TRANSLATORS: "Software Heritage" is a proper noun
  1521. ;; that must remain untranslated. See
  1522. ;; <https://www.softwareheritage.org>.
  1523. (G_ "scheduled Software Heritage archival")
  1524. #:field 'source)))
  1525. (lambda (key url method response . _)
  1526. (cond ((= 429 (response-code response))
  1527. (list (make-warning
  1528. package
  1529. (G_ "archival rate limit exceeded; \
  1530. try again later")
  1531. #:field 'source)))
  1532. (else
  1533. (response->warning url method response))))))))
  1534. ((? origin? origin)
  1535. ;; Since "save" origins are not supported for non-VCS source, all
  1536. ;; we can do is tell whether a given tarball is available or not.
  1537. (if (and=> (origin-hash origin) ;XXX: for ungoogled-chromium
  1538. content-hash-value) ;& icecat
  1539. (let ((hash (origin-hash origin)))
  1540. (match (lookup-content (content-hash-value hash)
  1541. (symbol->string
  1542. (content-hash-algorithm hash)))
  1543. (#f
  1544. ;; If SWH doesn't have HASH as is, it may be because it's
  1545. ;; a hand-crafted tarball. In that case, check whether
  1546. ;; the Disarchive database has an entry for that tarball.
  1547. (match (lookup-disarchive-spec hash)
  1548. (#f
  1549. (list (make-warning package
  1550. (G_ "source not archived on Software \
  1551. Heritage and missing from the Disarchive database")
  1552. #:field 'source)))
  1553. (directory-ids
  1554. (match (find (lambda (id)
  1555. (not (lookup-directory id)))
  1556. directory-ids)
  1557. (#f '())
  1558. (id
  1559. (list (make-warning package
  1560. (G_ "\
  1561. Disarchive entry refers to non-existent SWH directory '~a'")
  1562. (list id)
  1563. #:field 'source)))))))
  1564. ((? content?)
  1565. '())))
  1566. '()))
  1567. ((? local-file?)
  1568. '())
  1569. (_
  1570. (list (make-warning package
  1571. (G_ "\
  1572. source is not an origin, it cannot be archived")
  1573. #:field 'source)))))
  1574. (match-lambda*
  1575. (('swh-error url method response)
  1576. (response->warning url method response))
  1577. ((key . args)
  1578. (if (eq? key skip-key)
  1579. '()
  1580. (with-networking-fail-safe
  1581. (G_ "while connecting to Software Heritage")
  1582. '()
  1583. (apply throw key args))))))))
  1584. (define (check-haskell-stackage package)
  1585. "Check whether PACKAGE is a Haskell package ahead of the current
  1586. Stackage LTS version."
  1587. (match (with-networking-fail-safe
  1588. (format #f (G_ "while retrieving upstream info for '~a'")
  1589. (package-name package))
  1590. #f
  1591. (package-latest-release package (list %stackage-updater)))
  1592. ((? upstream-source? source)
  1593. (if (version>? (package-version package)
  1594. (upstream-source-version source))
  1595. (list
  1596. (make-warning package
  1597. (G_ "ahead of Stackage LTS version ~a")
  1598. (list (upstream-source-version source))
  1599. #:field 'version))
  1600. '()))
  1601. (#f '())))
  1602. ;;;
  1603. ;;; Source code formatting.
  1604. ;;;
  1605. (define (report-tabulations package line line-number)
  1606. "Warn about tabulations found in LINE."
  1607. (match (string-index line #\tab)
  1608. (#f #f)
  1609. (index
  1610. (make-warning package
  1611. (G_ "tabulation on line ~a, column ~a")
  1612. (list line-number index)
  1613. #:location
  1614. (location (package-file package)
  1615. line-number
  1616. index)))))
  1617. (define (report-trailing-white-space package line line-number)
  1618. "Warn about trailing white space in LINE."
  1619. (and (not (or (string=? line (string-trim-right line))
  1620. (string=? line (string #\page))))
  1621. (make-warning package
  1622. (G_ "trailing white space on line ~a")
  1623. (list line-number)
  1624. #:location
  1625. (location (package-file package)
  1626. line-number
  1627. 0))))
  1628. (define (report-long-line package line line-number)
  1629. "Emit a warning if LINE is too long."
  1630. ;; Note: We don't warn at 80 characters because sometimes hashes and URLs
  1631. ;; make it hard to fit within that limit and we want to avoid making too
  1632. ;; much noise.
  1633. (and (> (string-length line) 90)
  1634. (make-warning package
  1635. (G_ "line ~a is way too long (~a characters)")
  1636. (list line-number (string-length line))
  1637. #:location
  1638. (location (package-file package)
  1639. line-number
  1640. 0))))
  1641. (define %hanging-paren-rx
  1642. (make-regexp "^[[:blank:]]*[()]+[[:blank:]]*$"))
  1643. (define (report-lone-parentheses package line line-number)
  1644. "Emit a warning if LINE contains hanging parentheses."
  1645. (and (regexp-exec %hanging-paren-rx line)
  1646. (make-warning package
  1647. (G_ "parentheses feel lonely, \
  1648. move to the previous or next line")
  1649. (list line-number)
  1650. #:location
  1651. (location (package-file package)
  1652. line-number
  1653. 0))))
  1654. (define %formatting-reporters
  1655. ;; List of procedures that report formatting issues. These are not separate
  1656. ;; checkers because they would need to re-read the file.
  1657. (list report-tabulations
  1658. report-trailing-white-space
  1659. report-long-line
  1660. report-lone-parentheses))
  1661. (define* (report-formatting-issues package file starting-line
  1662. #:key (reporters %formatting-reporters))
  1663. "Report white-space issues in FILE starting from STARTING-LINE, and report
  1664. them for PACKAGE."
  1665. (define (sexp-last-line port)
  1666. ;; Return the last line of the sexp read from PORT or an estimate thereof.
  1667. (define &failure (list 'failure))
  1668. (let ((start (ftell port))
  1669. (start-line (port-line port))
  1670. (sexp (catch 'read-error
  1671. (lambda () (read port))
  1672. (const &failure))))
  1673. (let ((line (port-line port)))
  1674. (seek port start SEEK_SET)
  1675. (set-port-line! port start-line)
  1676. (if (eq? sexp &failure)
  1677. (+ start-line 60) ;conservative estimate
  1678. line))))
  1679. (call-with-input-file file
  1680. (lambda (port)
  1681. (let loop ((line-number 1)
  1682. (last-line #f)
  1683. (warnings '()))
  1684. (let ((line (read-line port)))
  1685. (if (or (eof-object? line)
  1686. (and last-line (> line-number last-line)))
  1687. warnings
  1688. (if (and (= line-number starting-line)
  1689. (not last-line))
  1690. (loop (+ 1 line-number)
  1691. (+ 1 (sexp-last-line port))
  1692. warnings)
  1693. (loop (+ 1 line-number)
  1694. last-line
  1695. (append
  1696. warnings
  1697. (if (< line-number starting-line)
  1698. '()
  1699. (filter-map (lambda (report)
  1700. (report package line line-number))
  1701. reporters)))))))))))
  1702. (define (check-formatting package)
  1703. "Check the formatting of the source code of PACKAGE."
  1704. (let ((location (package-location package)))
  1705. (if location
  1706. ;; Report issues starting from the line before the 'package'
  1707. ;; form, which usually contains the 'define' form.
  1708. (let ((line (- (location-line location) 1)))
  1709. (match (search-path %load-path (location-file location))
  1710. ((? string? file)
  1711. (report-formatting-issues package file line))
  1712. (#f
  1713. ;; It could be that LOCATION lists a "true" relative file
  1714. ;; name--i.e., not relative to an element of %LOAD-PATH.
  1715. (let ((file (location-file location)))
  1716. (if (file-exists? file)
  1717. (report-formatting-issues package file line)
  1718. (list (make-warning package
  1719. (G_ "source file not found"))))))))
  1720. '())))
  1721. ;;;
  1722. ;;; List of checkers.
  1723. ;;;
  1724. (define %local-checkers
  1725. (list
  1726. (lint-checker
  1727. (name 'name)
  1728. (description "Validate package names")
  1729. (check check-name))
  1730. (lint-checker
  1731. (name 'tests-true)
  1732. (description "Check if tests are explicitly enabled")
  1733. (check check-tests-true))
  1734. (lint-checker
  1735. (name 'description)
  1736. (description "Validate package descriptions")
  1737. (check check-description-style))
  1738. (lint-checker
  1739. (name 'synopsis)
  1740. (description "Validate package synopses")
  1741. (check check-synopsis-style))
  1742. (lint-checker
  1743. (name 'inputs-should-be-native)
  1744. (description "Identify inputs that should be native inputs")
  1745. (check check-inputs-should-be-native))
  1746. (lint-checker
  1747. (name 'inputs-should-not-be-input)
  1748. (description "Identify inputs that shouldn't be inputs at all")
  1749. (check check-inputs-should-not-be-an-input-at-all))
  1750. (lint-checker
  1751. (name 'input-labels)
  1752. (description "Identify input labels that do not match package names")
  1753. (check check-input-labels))
  1754. (lint-checker
  1755. (name 'wrapper-inputs)
  1756. (description "Make sure 'wrap-program' can finds its interpreter.")
  1757. (check check-wrapper-inputs))
  1758. (lint-checker
  1759. (name 'license)
  1760. ;; TRANSLATORS: <license> is the name of a data type and must not be
  1761. ;; translated.
  1762. (description "Make sure the 'license' field is a <license> \
  1763. or a list thereof")
  1764. (check check-license))
  1765. (lint-checker
  1766. (name 'optional-tests)
  1767. (description "Make sure tests are only run when requested")
  1768. (check check-optional-tests))
  1769. (lint-checker
  1770. (name 'mirror-url)
  1771. (description "Suggest 'mirror://' URLs")
  1772. (check check-mirror-url))
  1773. (lint-checker
  1774. (name 'source-file-name)
  1775. (description "Validate file names of sources")
  1776. (check check-source-file-name))
  1777. (lint-checker
  1778. (name 'source-unstable-tarball)
  1779. (description "Check for autogenerated tarballs")
  1780. (check check-source-unstable-tarball))
  1781. (lint-checker
  1782. (name 'derivation)
  1783. (description "Report failure to compile a package to a derivation")
  1784. (check check-derivation)
  1785. (requires-store? #t))
  1786. (lint-checker
  1787. (name 'profile-collisions)
  1788. (description "Report collisions that would occur due to propagated inputs")
  1789. (check check-profile-collisions)
  1790. (requires-store? #t))
  1791. (lint-checker
  1792. (name 'patch-file-names)
  1793. (description "Validate file names and availability of patches")
  1794. (check check-patch-file-names))
  1795. (lint-checker
  1796. (name 'patch-headers)
  1797. (description "Validate patch headers")
  1798. (check check-patch-headers))
  1799. (lint-checker
  1800. (name 'formatting)
  1801. (description "Look for formatting issues in the source")
  1802. (check check-formatting))))
  1803. (define %network-dependent-checkers
  1804. (list
  1805. (lint-checker
  1806. (name 'gnu-description)
  1807. (description "Validate synopsis & description of GNU packages")
  1808. (check check-gnu-synopsis+description))
  1809. (lint-checker
  1810. (name 'home-page)
  1811. (description "Validate home-page URLs")
  1812. (check check-home-page))
  1813. (lint-checker
  1814. (name 'source)
  1815. (description "Validate source URLs")
  1816. (check check-source))
  1817. (lint-checker
  1818. (name 'github-url)
  1819. (description "Suggest GitHub URLs")
  1820. (check check-github-url))
  1821. (lint-checker
  1822. (name 'cve)
  1823. (description "Check the Common Vulnerabilities and Exposures\
  1824. (CVE) database")
  1825. (check check-vulnerabilities))
  1826. (lint-checker
  1827. (name 'refresh)
  1828. (description "Check the package for new upstream releases")
  1829. (check check-for-updates))
  1830. (lint-checker
  1831. (name 'archival)
  1832. (description "Ensure source code archival on Software Heritage")
  1833. (check check-archival))
  1834. (lint-checker
  1835. (name 'haskell-stackage)
  1836. (description "Ensure Haskell packages use Stackage LTS versions")
  1837. (check check-haskell-stackage))))
  1838. (define %all-checkers
  1839. (append %local-checkers
  1840. %network-dependent-checkers))