1 ! Copyright (C) 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors arrays assocs classes classes.struct
4 classes.tuple combinators combinators.short-circuit debugger
5 definitions effects eval formatting grouping help help.markup
6 help.topics io io.streams.string kernel macros math
7 math.statistics namespaces prettyprint sequences sequences.deep
8 sets splitting strings summary tools.destructors unicode vocabs
9 vocabs.loader words words.constant words.symbol ;
12 ERROR: simple-lint-error message ;
14 M: simple-lint-error summary message>> ;
16 M: simple-lint-error error. summary print ;
19 SYMBOL: vocab-articles
21 : no-ui-disposables ( seq -- seq' )
24 "single-texture" "multi-texture" ! opengl.textures
26 "layout" ! ui.text.pango
27 "script-string" ! windows.uniscribe
28 "linux-monitor" ! github issue #2014, race condition in disposing of child monitors
38 : check-example ( element -- )
43 (eval-with-stack>string)
47 ] vocabs-quot get call( quot -- )
48 ] leaks members no-ui-disposables
50 dup [ class-of ] histogram-by
51 [ "Leaked resources: " write ... ] with-string-writer simple-lint-error
56 : check-examples ( element -- )
57 \ $example swap elements [ check-example ] each ;
59 : extract-values ( element -- seq )
60 \ $values swap elements
61 [ f ] [ first rest keys ] if-empty ;
63 : extract-value-effects ( element -- seq )
64 \ $values swap elements [ f ] [
66 \ $quotation swap elements [ f ] [
67 first second dup effect? [ effect>string ] when
72 : effect-values ( word -- seq )
74 [ in>> ] [ out>> ] bi append
75 [ dup pair? [ first ] when effect>string ] map members ;
77 : effect-effects ( word -- seq )
80 [ second dup effect? [ effect>string ] [ drop f ] if ]
84 : contains-funky-elements? ( element -- ? )
92 } swap '[ _ elements empty? not ] any? ;
94 : don't-check-word? ( word -- ? )
99 [ "declared-effect" word-prop not ]
101 [ "help" word-prop not ]
104 : skip-check-values? ( word element -- ? )
105 [ don't-check-word? ] [ contains-funky-elements? ] bi* or ;
107 : check-values ( word element -- )
108 2dup skip-check-values? [ 2drop ] [
109 [ effect-values ] [ extract-values ] bi* 2dup
110 sequence= [ 2drop ] [
111 "$values don't match stack effect; expected %u, got %u" sprintf
116 : check-value-effects ( word element -- )
117 [ effect-effects ] [ extract-value-effects ] bi*
118 [ 2dup and [ = ] [ 2drop t ] if ] 2all? [
119 "$quotation stack effects in $values don't match"
123 : check-nulls ( element -- )
124 \ $values swap elements
125 null swap deep-member?
126 [ "$values should not contain null" simple-lint-error ] when ;
128 : check-see-also ( element -- )
129 \ $see-also swap elements [ rest all-unique? ] all?
130 [ "$see-also are not unique" simple-lint-error ] unless ;
132 : check-modules ( element -- )
133 \ $vocab-link swap elements [
136 "$vocab-link to non-existent vocabulary"
141 : check-slots-tables ( element -- )
142 \ $slots swap elements [ rest [ length 2 = ] all? ] all?
143 [ "$slots have too many values in at least one row" simple-lint-error ] unless ;
145 : check-rendering ( element -- )
146 [ print-content ] with-string-writer drop ;
148 : check-strings ( str -- )
151 "Paragraph text should not contain \\n or \\t"
156 "Paragraph text should not contain double spaces"
161 : check-whitespace ( str1 str2 -- )
162 [ " " tail? ] [ " " head? ] bi* or
163 [ "Missing whitespace between strings" simple-lint-error ] unless ;
165 : check-bogus-nl ( element -- )
166 { { $nl } { { $nl } } } [ head? ] with any? [
167 "Simple element should not begin with a paragraph break"
171 : extract-slots ( elements -- seq )
172 [ dup pair? [ first \ $slot = ] [ drop f ] if ] deep-filter
175 : check-class-description ( word element -- )
176 \ $class-description swap elements over class? [
178 dup struct-class? [ struct-slots ] [ all-slots ] if
180 ] [ extract-slots ] bi*
181 [ swap member? ] with reject [
182 ", " join "Described $slot does not exist: " prepend
187 "A word that is not a class has a $class-description"
192 : check-article-title ( article -- )
193 article-title first LETTER?
194 [ "Article title must begin with a capital letter" simple-lint-error ] unless ;
196 : check-elements ( element -- )
199 [ [ string? ] filter [ check-strings ] each ]
200 [ [ simple-element? ] filter [ check-elements ] each ]
201 [ 2 <clumps> [ [ string? ] all? ] filter [ first2 check-whitespace ] each ]
204 : check-descriptions ( element -- )
205 { $description $class-description $var-description }
208 rest { { } { "" } } member?
209 [ "Empty $description" simple-lint-error ] when
213 : check-markup ( element -- )
219 [ check-descriptions ]
220 [ check-slots-tables ]
223 : files>vocabs ( -- assoc )
225 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
226 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
229 : group-articles ( -- assoc )
235 [ first _ at _ push-at ] [ 2drop ] if
239 : all-word-help ( words -- seq )
240 [ word-help ] filter ;