1 ! Copyright (C) 2009 Slava Pestov.
2 ! See https://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 )
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-see-also ( element -- )
124 \ $see-also swap elements [ rest all-unique? ] all?
125 [ "$see-also are not unique" simple-lint-error ] unless ;
127 : check-modules ( element -- )
128 \ $vocab-link swap elements [
130 dup vocab-exists? [ drop ] [
131 "$vocab-link to non-existent vocabulary ``" "''" surround
136 : check-slots-tables ( element -- )
137 \ $slots swap elements [ rest [ length 2 = ] all? ] all?
138 [ "$slots have too many values in at least one row" simple-lint-error ] unless ;
140 : check-rendering ( element -- )
141 [ print-content ] with-string-writer drop ;
143 : check-strings ( str -- )
146 "Paragraph text should not contain \\n or \\t"
151 "Paragraph text should not contain double spaces"
156 : check-whitespace ( str1 str2 -- )
157 [ " " tail? ] [ " " head? ] bi* or
158 [ "Missing whitespace between strings" simple-lint-error ] unless ;
160 : check-bogus-nl ( element -- )
161 { { $nl } { { $nl } } } [ head? ] with any? [
162 "Simple element should not begin with a paragraph break"
166 : extract-slots ( elements -- seq )
167 [ dup pair? [ first \ $slot = ] [ drop f ] if ] deep-filter
170 : check-class-description ( word element -- )
171 \ $class-description swap elements over class? [
173 dup struct-class? [ struct-slots ] [ all-slots ] if
175 ] [ extract-slots ] bi*
176 [ swap member? ] with reject [
177 ", " join "Described $slot does not exist: " prepend
182 "A word that is not a class has a $class-description"
187 : check-article-title ( article -- )
188 article-title first LETTER?
189 [ "Article title must begin with a capital letter" simple-lint-error ] unless ;
191 : check-elements ( element -- )
194 [ [ string? ] filter [ check-strings ] each ]
195 [ [ simple-element? ] filter [ check-elements ] each ]
196 [ 2 <clumps> [ [ string? ] all? ] filter [ first2 check-whitespace ] each ]
199 : check-descriptions ( element -- )
200 { $description $class-description $var-description }
203 rest { { } { "" } } member?
204 [ "Empty $description" simple-lint-error ] when
208 : check-markup ( element -- )
214 [ check-descriptions ]
215 [ check-slots-tables ]
218 : files>vocabs ( -- assoc )
220 [ [ [ vocab-docs-path ] keep ] H{ } map>assoc ]
221 [ [ [ vocab-source-path ] keep ] H{ } map>assoc ]
224 : group-articles ( -- assoc )
230 [ first _ at _ push-at ] [ 2drop ] if
234 : all-word-help ( words -- seq )
235 [ word-help ] filter ;