Add jetc --lint-sql to find <sql> that pastes values (phase 2)
Implements phase 2 of docs/design-sql-bound-parameters.md. jetc --lint-sql [--strict] <file|dir>... lists each <sql> whose statement contains a $[...] or #[...] reference instead of a <bind>, with file:line and where each value comes from. Row values ($[.col], $[session.col], $[?N], $[#]) are only reported with --strict. References in <bind>, <if>, <set> and the other attribute-only tags, <comment> and |> <| are skipped. A custom tag defined as <sql><container></sql> (barant.com's <showtable>) is checked at each use. Exit status is 0 for none found, 1 for findings, 2 for an unreadable path. - jetc/JetLint.*: the scanner; jetc.cpp: the option - build scripts and runbindtests.sh: link JetLint.cpp - tests/runlinttests.sh and tests/lintsql/: fixtures and expected output - docs: worklist for the local copies of both sites, design doc status, manual note on the lint Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fd81bb877f
commit
2847ce5fa7
22 files changed
+667
-10
No files matched your search
@@ -0,0 +1,57 @@
|
||||
#ifndef __JetLint_h__
|
||||
#define __JetLint_h__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <ostream>
|
||||
|
||||
// jetc --lint-sql: phase 2 of docs/design-sql-bound-parameters.md.
|
||||
//
|
||||
// Lists every <sql> whose body pastes a variable into the statement text
|
||||
// ($[...] or #[...]) instead of passing it with <bind>. These are the
|
||||
// queries to migrate. A value from a row of an earlier query
|
||||
// ($[.column], $[session.column], $[?N], $[#]) is not reported, as the
|
||||
// design doc specifies, unless strict is set.
|
||||
|
||||
namespace jetc {
|
||||
|
||||
struct LintRef {
|
||||
std::string text; // the reference as written, e.g. "$[:email]"
|
||||
std::string kind; // cgi, global, local, session, env, keyword, row, ...
|
||||
};
|
||||
|
||||
struct LintFinding {
|
||||
std::string file;
|
||||
int line; // line of the <sql tag
|
||||
std::string tag; // "sql", or a custom tag that wraps <sql><container></sql>
|
||||
std::vector<LintRef> refs;
|
||||
};
|
||||
|
||||
struct LintStats {
|
||||
int files = 0; // files that contain at least one <sql>
|
||||
int sqlBlocks = 0;
|
||||
int flaggedBlocks = 0;
|
||||
};
|
||||
|
||||
// Scans one file's text. Appends to findings and stats.
|
||||
// wrappers: custom tag names whose uses count as <sql> (see
|
||||
// findSqlWrappers).
|
||||
void lintSqlText(const std::string &file, const std::string &text, bool strict,
|
||||
const std::vector<std::string> &wrappers,
|
||||
std::vector<LintFinding> &findings, LintStats &stats);
|
||||
|
||||
// Adds to wrappers each custom tag defined in text (<tag name="X">)
|
||||
// whose definition runs the caller's content as its statement:
|
||||
// <sql ...><container></sql>.
|
||||
void findSqlWrappers(const std::string &text, std::vector<std::string> &wrappers);
|
||||
|
||||
// Scans files and directories (recursively; every regular file,
|
||||
// whatever its extension). Tag definitions are collected from all of
|
||||
// them first, so a wrapper defined in one file is found in all.
|
||||
// Prints one line per finding and a summary. Returns 0 when nothing is found, 1 when something is,
|
||||
// 2 on an error (unreadable path).
|
||||
int lintSql(const std::vector<std::string> &paths, bool strict, std::ostream &out, std::ostream &err);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user