Skip to main content

litscan 1.4.0

A small CLI tool that scans a codebase for string and numeric literals, helping you quickly spot hard-coded values in source files.

Prerequisites

  • Python 3.14+

Installation

pip install litscan

Usage

After installation, litscan is available as a console script:

litscan <path> [options]

What is detected

The scanner recognises the following literal types in any source file:

Type Examples
Triple-quoted strings (multiline) """hello""", '''world'''
Double-quoted strings "hello"
Single-quoted strings 'world'
Decimal numbers 3.14, 0.5
Integer numbers 42, 0

Results are grouped by unique literal value and sorted by occurrence count (highest first).

Arguments

Argument Description
path Target directory or file to scan. Multiple paths can be specified, separated by a semicolon (e.g. src;lib;tests).

Options

Option Default Description
--ext <exts> (all files) Comma-separated extensions to include (e.g. py,js,ts)
--output <name> litscan-output Base name (without extension) for output file(s)
--output-dir <dir> reports Directory where output file(s) will be written
--format <fmt> json Output format: json, html, or all
--workers <n> min(32, cpu_count + 4) Number of parallel worker threads used during scanning
--db <path> <system-temp>/litscan.db Path to the SQLite scratch database that stores occurrences during a scan run. Session records are removed after the report is written.
--functions-only (off) Scan only literals that appear inside function or method implementations. Supported for Python and brace-style languages (Java, JS, JSX, TS, TSX, C/C++, C#, Go, Rust, Kotlin, Swift, Scala, Groovy, GS, GSX).
--version Print the version and exit.

Examples

Scan all files in the current directory and produce a JSON report:

litscan .

Scan only Python and JavaScript files in src/:

litscan src --ext py,js

Generate both JSON and HTML reports in a custom directory:

litscan . --format all --output-dir my-reports

Scan a Java source tree with a custom output name:

litscan src/main/java --ext java --format all --output-dir reports

Scan only literals inside functions and methods:

litscan src --functions-only

Configuration

Environment variable Description
LITSCAN_CONFIG_DIR Directory where logging.ini, lit_ignore, lit_brace_ext, and lit_control_kw are seeded on first run and read from. When unset, the bundled copies inside the package are used directly.

Ignore patterns

The lit_ignore file (seeded into LITSCAN_CONFIG_DIR on first run) contains one regex pattern per line. Any literal whose value matches a pattern is excluded from scan results. Edit the file to suppress noise such as common stop-words or numeric constants you do not care about.

Brace-style language extensions

The lit_brace_ext file (seeded into LITSCAN_CONFIG_DIR on first run) extends the built-in set of brace-style language extensions used by --functions-only. One extension per line (e.g. .dart). The built-in defaults (.java, .js, .ts, .jsx, .tsx, .c, .cpp, .h, .hpp, .cs, .go, .rs, .kt, .swift, .scala, .groovy, .gs, .gsx) are always active; entries in this file are added on top.

Control-flow keywords

The lit_control_kw file (seeded into LITSCAN_CONFIG_DIR on first run) extends the built-in set of control-flow keywords excluded from function detection in --functions-only mode. One keyword per line (e.g. using). The built-in defaults (if, else, for, while, do, switch, try, catch, finally, with, synchronized) are always active; entries in this file are added on top.

Development

Prerequisites

  • Poetry 2.2+

Installation

poetry install

Architecture

flowchart TD
    CLI["cli.py\n(entry point)"] --> logenrich["setup_logger()\nlogenrich"]
    CLI --> discover["discover_files()"]
    discover --> concurrent["ThreadPoolExecutor\n(parallel scan)"]
    concurrent --> scan["scan_file()\nscanner.py"]
    scan --> litignore["lit_ignore\n(exclude patterns)"]
    scan --> litbraceext["lit_brace_ext\n(extra brace-style extensions)"]
    scan --> litcontrolkw["lit_control_kw\n(extra control-flow keywords)"]
    scan --> store["SessionStore\nstore.py (SQLite)"]
    store --> report["write_outputs()\nreporter.py"]
    report --> JSON["JSON report"]
    report --> HTML["HTML report"]
Module Responsibility
cli.py Argument parsing, file discovery, orchestration
scanner.py Regex-based literal extraction; LiteralOccurrence / LiteralGroup types
store.py SessionStore — thread-safe SQLite scratch store; one UUID per scan run
reporter.py write_outputs() — renders JSON and/or HTML reports
logenrich External library that provides setup_logger() — logging config seeded from logging.ini

Test with coverage

poetry run pytest --cov=litscan tests --cov-report html

Format and lint

poetry run black litscan; poetry run pylint litscan

Quality gates

  • Coverage ≥ 90%
  • Pylint score 10/10

Example

Scan the test fixtures and produce both JSON and HTML reports:

poetry run litscan tests\fixtures --format all

Publishing to PyPI

Prerequisites

  • A PyPI account with an API token.

Configure the token

poetry config pypi-token.pypi <your-token>

Build and publish

poetry publish --build

This builds the source distribution and wheel, then uploads them to PyPI in one step.

Note: PyPI releases are immutable. Once a version is published, it cannot be overwritten.
To fix a mistake, yank the release via the PyPI web UI and publish a new version.

Changelog

License

MIT

Author

Ron Webb <ron@ronella.xyz>

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

litscan-1.4.0.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

litscan-1.4.0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file litscan-1.4.0.tar.gz.

File metadata

  • Download URL: litscan-1.4.0.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.0 CPython/3.14.6 Linux/6.17.0-1018-azure

File hashes

Hashes for litscan-1.4.0.tar.gz
Algorithm Hash digest
SHA256 8a45cfaf0d0450953f4cf64387de5d6e1c83d7bb23d415de8bd44c5164bd1fb2
MD5 2abacda1dec75d8958b1a482e8c29309
BLAKE2b-256 a460e2aaf739d7e1c615de2cbbf91735a312e1184c1bcbed1fce8bd354d21e80

See more details on using hashes here.

File details

Details for the file litscan-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: litscan-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.0 CPython/3.14.6 Linux/6.17.0-1018-azure

File hashes

Hashes for litscan-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cb3a53a5de894ea5955c7484d7934d5556f176a3774b41ef6467e828d3752a1f
MD5 96dacd6c5d3df399ce494b808685ff0d
BLAKE2b-256 107c50db7ea5c1d842f5552b7186ae973afa5225511fcb11fd772593a8db2bc1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page