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