Skip to content

Add standalone Dream Maker structural linter - #335

Open
scroogemcduck1068 wants to merge 1 commit into
Iamgoofball:masterfrom
scroogemcduck1068:bounty-279-dmlint
Open

Add standalone Dream Maker structural linter#335
scroogemcduck1068 wants to merge 1 commit into
Iamgoofball:masterfrom
scroogemcduck1068:bounty-279-dmlint

Conversation

@scroogemcduck1068

Copy link
Copy Markdown

About The Pull Request

Closes #279.

Adds a dependency-free Python linter that recursively discovers every code/**/*.dm file without invoking DreamMaker. It emits stable path:line:column diagnostics or structured JSON and returns nonzero for validation errors.

Implementation walkthrough

  • Diagnostic and Token are immutable dataclasses so rules exchange stable, sortable values.
  • tokenize performs one linear source pass, retaining exact positions while recognizing comments, resource strings, interpolated strings, custom-delimited regex strings, block strings, and multiline preprocessor macros.
  • delimiter_diagnostics uses a stack to detect unexpected, crossed, and unclosed parentheses, brackets, and braces, including opener locations.
  • directive_diagnostics independently tracks conditional directives, validates #else/#elif placement, and checks required #define and #include arguments.
  • line_diagnostics implements a source-line rule for trailing whitespace, demonstrating how non-token rules can be added.
  • discover recursively and deterministically indexes only .dm files below code/.
  • lint_files isolates UTF-8/read failures per file so one bad input does not crash a repository scan.
  • main owns CLI parsing, text/JSON rendering, summary counts, and the documented 0/1/2 exit contract.
  • Tests cover lexer edge cases, nested interpolation, immediate comments, raw/block strings, macros, structural and preprocessor failures, recursive discovery, JSON, and exit codes.
  • The workflow runs unit tests and a repository-wide scan within a five-minute bound.

This intentionally does not claim compiler equivalence. Rules are conservative and modular: unsupported context-sensitive DM semantics remain DreamMaker's responsibility instead of generating speculative diagnostics.

Verification

  • python3 -m unittest discover -s tools/dmlint -v: 16 tests pass.
  • python3 tools/dmlint/dmlint.py: scans 7,414 current DM files, reports 0 errors and 27 pre-existing trailing-whitespace warnings, exits 0.
  • python3 -m py_compile tools/dmlint/dmlint.py tools/dmlint/test_dmlint.py: passes.
  • git diff --check: passes.

Why It's Good For The Game

DM contributors currently need compiler-oriented feedback even for simple structural mistakes. A fast standalone check catches malformed strings/comments, delimiters, and preprocessor structure with actionable locations before a full build. That shortens feedback loops locally and in CI while the conservative scope avoids pretending to replace DreamMaker. The implementation is documented and easy to extend as the project identifies additional low-false-positive rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BOUNTY] [200$] [URGENT] Write a Python/Javascript based linter for DM [CRITICAL] [P0] [HELP WANTED] [EASY] [OPIRE] [OPPORTUNITY]

1 participant