]> gitweb.factorcode.org Git - factor.git/blob - basis/help/lint/lint.factor
help.lint: remove check-nulls
[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 classes combinators command-line continuations
4 help help.lint.checks help.topics io kernel listener namespaces
5 parser sequences source-files.errors system tools.errors vocabs
6 vocabs.hierarchy vocabs.hierarchy.private vocabs.loader words ;
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.png" }
22    { quot [ lint-failures get values ] }
23    { forget-quot [ lint-failures get delete-at ] }
24 } define-error-type
25 M: help-lint-error error-type drop +help-lint-failure+ ;
26
27 <PRIVATE
28
29 : <help-lint-error> ( error topic -- help-lint-error )
30     help-lint-error new-source-file-error ;
31
32 PRIVATE>
33
34 : notify-help-lint-error ( error topic -- )
35     lint-failures get pick
36     [ [ [ <help-lint-error> ] keep ] dip set-at ] [ delete-at drop ] if
37     notify-error-observers ;
38
39 <PRIVATE
40
41 :: check-something ( topic quot -- )
42     [ quot call( -- ) f ] [ ] recover
43     topic notify-help-lint-error ; inline
44
45 : check-word ( word -- )
46     [ with-file-vocabs ] vocabs-quot set
47     dup "help" word-prop [
48         [ >link ] keep '[
49             _ dup "help" word-prop {
50                 [ check-values ]
51                 [ check-value-effects ]
52                 [ check-class-description ]
53                 [ nip check-see-also ]
54                 [ nip check-markup ]
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 : help-lint-vocab ( vocab -- )
72     "Checking " write dup vocab-name write "..." print flush
73     [ check-about ]
74     [ vocab-words [ check-word ] each ]
75     [ vocab-articles get at [ check-article ] each ]
76     tri ;
77
78 : help-lint-vocabs ( vocabs -- )
79     [
80         auto-use? off
81         group-articles vocab-articles set
82         [ help-lint-vocab ] each
83     ] with-scope ;
84
85 PRIVATE>
86
87 : help-lint ( prefix -- )
88     loaded-child-vocab-names help-lint-vocabs ;
89
90 : help-lint-all ( -- ) "" help-lint ;
91
92 : :lint-failures ( -- ) lint-failures get values errors. ;
93
94 : unlinked-words ( vocab -- seq )
95     vocab-words all-word-help [ article-parent ] reject ;
96
97 : linked-undocumented-words ( -- seq )
98     all-words
99     [ word-help ] reject
100     [ article-parent ] filter
101     [ predicate? ] reject ;
102
103 : test-lint-main ( -- )
104     command-line get [
105         dup vocab-roots get member? [
106             "" vocabs-to-load [ require-all ] keep
107         ] [
108             [ load ] [ loaded-child-vocab-names ] bi
109         ] if help-lint-vocabs
110     ] each
111     lint-failures get assoc-empty?
112     [ [ "==== FAILING LINT" print :lint-failures flush ] unless ]
113     [ 0 1 ? exit ] bi ;
114
115 MAIN: test-lint-main