class

Analyzer::Dart::DartFrog

Inherits Analyzer < FileHelper < Reference < Object

Dart Frog is a filesystem-routed framework. Routes live under routes/ and the URL is derived from the directory layout:

routes/index.dart → / routes/about.dart → /about routes/users/index.dart → /users routes/users/[id].dart → /users/{id} routes/users/[id]/posts.dart → /users/{id}/posts

Each route file exports an onRequest(RequestContext, ...) handler. Method dispatch happens inside that handler — typically a switch on context.request.method against HttpMethod.<verb> constants. We surface the verbs we can see referenced in the file and fall back to the standard set when the file looks like a catch-all (no explicit HttpMethod.* references).

_middleware.dart and other underscore-prefixed Dart files are framework plumbing — not user-facing routes — and skipped.

Constants

CASE_METHOD_REGEX = /\bcase\s+HttpMethod\.([a-z]+)\s*:/

Matches case HttpMethod.<verb>: clauses inside a method switch.

CLAUSE_BOUNDARY_REGEX = /\}|\bcase\b|\bdefault\b/

The handler body for a case clause runs until the next clause or the closing brace of the switch — whichever comes first. We bound at the earliest of a }, a case, or a default keyword so the last enumerated method-case can't sweep in a trailing default: arm (whose 405/methodNotAllowed would wrongly tar the case).

FALLBACK_METHODS = ["GET", "POST", "PUT", "DELETE", "PATCH"]
HTTP_METHOD_MAP = {"get" => "GET", "post" => "POST", "put" => "PUT", "delete" => "DELETE", "patch" => "PATCH", "head" => "HEAD", "options" => "OPTIONS"}
HTTP_METHOD_PATTERNS = HTTP_METHOD_MAP.map do |dart_name, verb| {verb, /HttpMethod\.#{dart_name}\b/} end

Crystal recompiles an interpolated regex literal on every evaluation (a full PCRE2 JIT compile) — precompile the fixed verb probes once at load time instead of per handler file.

METHOD_NOT_ALLOWED_REGEX = /methodNotAllowed|MethodNotAllowed|statusCode\s*:\s*405|\(\s*405\b/

A clause body that rejects the verb: methodNotAllowed, MethodNotAllowedResponse(), or a literal 405 status code passed positionally (Response(405)) or by name (statusCode: 405). We deliberately avoid a bare 405 so an unrelated {'code': 405} in a real handler body can't be mistaken for a rejection.

ON_REQUEST_HANDLER_REGEX = /\bonRequest\s*[(=]/

Every Dart Frog route file exports an onRequest handler — either a function (Response onRequest(...), Future<Response> onRequest(...)) or the assignment form (Handler onRequest = ...). A .dart file under a routes/ directory that lacks it is not a server route. This matters for full-stack monorepos, where a Flutter client commonly keeps its UI navigation under lib/.../routes/ — those widget files must not be reported as HTTP endpoints.

Class methods

tech_name
Source

Instance methods

analyze
Source
tech

Instance-side view of the same declaration. The per-file rescues live on this base class, which has no way to name the analyzer that is running inside them, so a skipped file could not be attributed to a tech. Deriving it from analyzer_for keeps the name written exactly once.

Source