Registry / testing / ut-tsql-lexer

ut-tsql-lexer

JSON →
library1.5.4jsnpmunverified

Transact SQL lexer and linter that parses T-SQL source code into tokens and provides linting rules for code style and correctness. Version 1.5.4 is stable with moderate release cadence. It returns parsed tokens per line with types (whitespace, keyword, operator, etc.) and a lint array with rule violations. Key differentiators: built-in lint rules for uppercase keywords, indentation, whitespace, and quoting; detailed error messages with location.

npm install ut-tsql-lexer
INSTALL
IMPORT
SIG · UT-TSQL-LEXER
U
ut-tsql-lexer
testingjavascriptv1.5.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
✓ import { parse } from 'ut-tsql-lexer'
✗ const parse = require('ut-tsql-lexer')
The package only exports a named function 'parse', not a default export.
parse
✓ const { parse } = require('ut-tsql-lexer')
✗ const pars = require('ut-tsql-lexer').pars
CommonJS require destructuring is correct; do not misspell function name.
parse result
✓ const result = parse(sql); const { lint, tokens } = result;
✗ const parsed = parse(sql); parsed.lint.forEach(...)
parse() returns an object with lint array and tokens array; tokens is an array of arrays (lines of tokens).

Demonstrates parsing T-SQL source code, accessing lint warnings, and iterating tokens per line with error handling.

const { parse } = require('ut-tsql-lexer'); const sql = 'SELECT * FROM someTable'; try { const result = parse(sql); // Lint warnings result.lint.forEach(w => console.log(w.message)); // Tokens per line result.tokens.forEach(line => { line.forEach(t => console.log(t.type, t.text)); }); } catch (err) { console.error(err.message, err.location); }
Debug
Known issues
gotchaparse() returns {lint, tokens} where tokens is an array of arrays (each inner array represents a line of tokens).
fix
Always iterate tokens as result.tokens.forEach(line => ...) and assume line is an array.
affects: <2.0.0
gotchaThe parse function throws on syntax errors; catch the exception to get detailed location info.
fix
Wrap parse() in try-catch block.
affects: >=1.0.0
deprecatedLint rules like 'upppercase-keywords' have typo in rule name (upppercase vs uppercase).
fix
Use the exact string 'upppercase-keywords' in configurations; future versions may fix the typo.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: parse is not a function
Using default import (import parse from 'ut-tsql-lexer') instead of named import.
fix
Use named import: import { parse } from 'ut-tsql-lexer'
Cannot read property 'lint' of undefined
Not catching parse exception when SQL syntax is invalid.
fix
Wrap parse() in try-catch: try { const r = parse(sql); r.lint... } catch (e) { ... }
tokens.forEach is not a function
Assuming tokens is a flat array, but it's an array of arrays (lines).
fix
Iterate as result.tokens.forEach(line => line.forEach(token => ...))
Upgrade
Version history
1.5.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Amazon
1
Resources
ut-tsql-lexer — npm install ut-tsql-lexer · libregistry