MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / scan_file

Function scan_file

scripts/website/find_suspicious_inline_code.py:190–237  ·  view source on GitHub ↗
(path: Path)

Source from the content-addressed store, hash-verified

188
189
190def scan_file(path: Path):
191 text = path.read_text(encoding="utf-8")
192 lines = text.splitlines()
193
194 in_front_matter = False
195 in_fence = False
196
197 for i, line in enumerate(lines, start=1):
198 stripped = line.strip()
199
200 if i == 1 and stripped == "---":
201 in_front_matter = True
202 continue
203 if in_front_matter:
204 if stripped == "---":
205 in_front_matter = False
206 continue
207
208 if stripped.startswith("```"):
209 in_fence = not in_fence
210 continue
211 if in_fence:
212 continue
213 if line.startswith(" ") or line.startswith("\t"):
214 continue
215 if stripped.startswith(">"):
216 continue
217 if "](" in line or line.lstrip().startswith("!["):
218 continue
219
220 spans = code_spans(line)
221 found = []
222 for kind, rx in PATTERNS:
223 for m in rx.finditer(line):
224 token = m.group(0)
225 if in_spans(m.start(), spans):
226 continue
227 # Skip obvious URLs/domains for java_like_ref false positives
228 if kind == "java_like_ref" and token.endswith((".com", ".org", ".net", ".io")):
229 continue
230 found.append((kind, token, m.start(), m.end()))
231
232 if found:
233 yield i, line, found
234
235 # Emit structural findings as pseudo-token rows with line context.
236 for kind, line_no, snippet in structural_findings(lines):
237 yield line_no, snippet, [(kind, snippet, 0, len(snippet))]
238
239
240def main() -> int:

Callers 1

mainFunction · 0.85

Calls 8

code_spansFunction · 0.85
in_spansFunction · 0.85
structural_findingsFunction · 0.85
groupMethod · 0.65
startMethod · 0.65
appendMethod · 0.65
endMethod · 0.65
stripMethod · 0.45

Tested by

no test coverage detected