]> gitweb.factorcode.org Git - factor.git/blob - basis/help/lint/lint.factor
core/basis: Rename words dealing with vocabs to loaded-vocabs or disk-vocabs because...
[factor.git] / basis / help / lint / lint.factor
1 ! Copyright (C) 2006, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: assocs combinators continuations fry help
4 help.lint.checks help.topics io kernel namespaces parser
5 sequences source-files.errors vocabs.hierarchy vocabs words
6 classes locals tools.errors listener ;
7 IN: help.lint
8
9 SYMBOL: lint-failures
10
11 lint-failures [ H{ } clone ] initialize
12
13 TUPLE: help-lint-error < source-file-error ;
14
15 SYMBOL: +help-lint-failure+
16
17 T{ error-type-holder
18    { type +help-lint-failure+ }
19    { word ":lint-failures" }
20    { plural "help lint failures" }
21    { icon "vocab:ui/tools/error-list/icons/help-lint-error.tiff" }
22    { quot [ lint-failures get values ] }
23    { forget-quot [ lint-failures get delete-at ] }
24 } define-error-type
25
26 M: help-lint-error error-type drop +help-lint-failure+ ;
27
28 <PRIVATE
29
30 : <help-lint-error> ( error topic -- help-lint-error )
31     \ help-lint-error <definition-error> ;
32
33 PRIVATE>
34
35 : notify-help-lint-error ( error topic -- )
36     lint-failures get pick
37     [ [ [ <help-lint-error> ] keep ] dip set-at ] [ delete-at drop ] if
38     notify-error-observers ;
39
40 <PRIVATE
41
42 :: check-something ( topic quot -- )
43     [ quot call( -- ) f ] [ ] recover
44     topic notify-help-lint-error ; inline
45
46 : check-word ( word -- )
47     [ with-file-vocabs ] vocabs-quot set
48     dup word-help [
49         [ >link ] keep '[
50             _ dup word-help {
51                 [ check-values ]
52                 [ check-value-effects ]
53                 [ check-class-description ]
54                 [ nip [ check-nulls ] [ check-see-also ] [ check-markup ] tri ]
55             } 2cleave
56         ] check-something
57     ] [ drop ] if ;
58
59 : check-article ( article -- )
60     [ with-interactive-vocabs ] vocabs-quot set
61     >link dup '[
62         _
63         [ check-article-title ]
64         [ article-content check-markup ] bi
65     ] check-something ;
66
67 : check-about ( vocab -- )
68     <vocab-link> dup
69     '[ _ vocab-help [ lookup-article drop ] when* ] check-something ;
70
71 : check-vocab ( vocab -- )
72     "Checking " write dup write "..." print flush
73     [ check-about ]
74     [ vocab-words [ check-word ] each ]
75     [ vocab-articles get at [ check-article ] each ]
76     tri ;
77
78 PRIVATE>
79
80 : help-lint ( prefix -- )
81     [
82         auto-use? off
83         all-disk-vocab-names all-vocabs-list set
84         group-articles vocab-articles set
85         loaded-child-vocab-names
86         [ check-vocab ] each
87     ] with-scope ;
88
89 : help-lint-all ( -- ) "" help-lint ;
90
91 : :lint-failures ( -- ) lint-failures get values errors. ;
92
93 : unlinked-words ( vocab -- seq )
94     vocab-words all-word-help [ article-parent ] reject ;
95
96 : linked-undocumented-words ( -- seq )
97     all-words
98     [ word-help ] reject
99     [ article-parent ] filter
100     [ predicate? ] reject ;