-
Notifications
You must be signed in to change notification settings - Fork 1
v0.4.0: Type Safety Modes — Two Axes of Type Control (DD-009) #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
dd4122c
feat: type safety modes (DD-009) — two axes of type control
larimonious 0ab1460
fix: address Copilot review, extend type system coverage, fix CI
larimonious 24a1c18
fix: address second round of Copilot review comments
larimonious 0f1d861
polish: type system production readiness (DD-009 Phase 6)
larimonious 22eb976
fix: address third round of Copilot review (10 comments)
larimonious 4e7a092
feat: world-class type system (DD-009 Phase 7.1-7.4)
larimonious cc175ae
fix: address Copilot review round 4 (3 comments)
larimonious e5fe366
fix: accurate line numbers on runtime/type/parser errors
larimonious 3d32eac
fix: unify execution contexts for lib, routes, and middleware (findin…
larimonious 7cbab97
fix: self-review — Located-aware lint + remove dead_code suppression
larimonious 0dc2224
docs: update all guides with v0.4.0 type syntax and features
larimonious File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| //! Configuration for NTNT runtime and lint modes. | ||
| //! | ||
| //! Provides [`TypeMode`] (runtime behavior for type mismatches) and [`LintMode`] | ||
| //! (lint-time behavior for missing annotations), read from environment variables. | ||
| //! Values are cached via `OnceLock` in production builds; re-read on every call | ||
| //! in test builds so that tests can manipulate env vars with isolation. | ||
|
|
||
| /// Runtime type safety mode, controlled by the `NTNT_TYPE_MODE` env var. | ||
| /// | ||
| /// Controls how runtime type mismatches are handled in: | ||
| /// - Index operations (`[]`) on unexpected types | ||
| /// - `for..in` on non-collection values | ||
| /// - Template expression errors | ||
| /// | ||
| /// | Value | Behaviour | | ||
| /// |-------|-----------| | ||
| /// | `strict` | Type mismatches are runtime errors (program halts) | | ||
| /// | `warn` | Type mismatches emit a warning to stderr and continue **(default)** | | ||
| /// | `forgiving` | Type mismatches are silently ignored | | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub enum TypeMode { | ||
| /// Type mismatches are runtime errors — the program halts. | ||
| Strict, | ||
| /// Type mismatches emit `[WARN]` to stderr and continue (default). | ||
| Warn, | ||
| /// Type mismatches are silently ignored (pre-v0.4 behaviour). | ||
| Forgiving, | ||
| } | ||
|
|
||
| /// Lint-time type annotation mode, controlled by `NTNT_LINT_MODE` or CLI flags. | ||
| /// | ||
| /// Controls how the linter treats functions without type annotations. | ||
| /// | ||
| /// | Value | Behaviour | | ||
| /// |-------|-----------| | ||
| /// | `default` | Only report type errors where annotations exist **(default)** | | ||
| /// | `warn` | Also emit warnings for functions missing type annotations | | ||
| /// | `strict` | Missing annotations are lint errors (non-zero exit code) | | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub enum LintMode { | ||
| /// Only report type errors where annotations exist (default behaviour). | ||
| Default, | ||
| /// Also emit warnings for functions missing type annotations. | ||
| Warn, | ||
| /// Missing annotations are lint errors (non-zero exit code). | ||
| Strict, | ||
| } | ||
|
|
||
| fn read_type_mode_from_env() -> TypeMode { | ||
| match std::env::var("NTNT_TYPE_MODE").as_deref().unwrap_or("warn") { | ||
| "strict" => TypeMode::Strict, | ||
| "forgiving" => TypeMode::Forgiving, | ||
| _ => TypeMode::Warn, | ||
| } | ||
| } | ||
|
|
||
| /// Get the current runtime type mode from the `NTNT_TYPE_MODE` env var. | ||
| /// | ||
| /// Default is [`TypeMode::Warn`]. In production builds the result is cached on | ||
| /// first call; in test builds it reads fresh from the environment every call | ||
| /// so tests can manipulate `NTNT_TYPE_MODE` with per-test isolation. | ||
| #[cfg(not(test))] | ||
| pub fn get_type_mode() -> TypeMode { | ||
| use std::sync::OnceLock; | ||
| static TYPE_MODE: OnceLock<TypeMode> = OnceLock::new(); | ||
| *TYPE_MODE.get_or_init(read_type_mode_from_env) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| pub fn get_type_mode() -> TypeMode { | ||
| read_type_mode_from_env() | ||
| } | ||
|
|
||
| fn read_lint_mode_from_env() -> LintMode { | ||
| match std::env::var("NTNT_LINT_MODE") | ||
| .as_deref() | ||
| .unwrap_or("default") | ||
| { | ||
| "warn" => LintMode::Warn, | ||
| "strict" => LintMode::Strict, | ||
| _ => LintMode::Default, | ||
| } | ||
| } | ||
|
|
||
| /// Get the current lint mode from the `NTNT_LINT_MODE` env var. | ||
| /// | ||
| /// Default is [`LintMode::Default`]. CLI flags take precedence over this value | ||
| /// (caller is responsible for applying the override). In production builds the | ||
| /// result is cached; in test builds it reads fresh each call. | ||
| #[cfg(not(test))] | ||
| pub fn get_lint_mode() -> LintMode { | ||
| use std::sync::OnceLock; | ||
| static LINT_MODE: OnceLock<LintMode> = OnceLock::new(); | ||
| *LINT_MODE.get_or_init(read_lint_mode_from_env) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| pub fn get_lint_mode() -> LintMode { | ||
| read_lint_mode_from_env() | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.