lint.scm 75 KB

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