
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
eslint-plugin-sqlite
Advanced tools
ESLint plugin that can validate SQLite queries and automatically generate types for query parameters and results
An ESLint plugin that can validate SQLite queries and automatically
generate types for query parameters and results when using the
better-sqlite3
library.
Note that the following examples exclude the setup of TypeScript linting.
// eslint.config.js
import { createSqlitePlugin } from "eslint-plugin-sqlite";
const sqlitePlugin = createSqlitePlugin({
getDatabase() {
return new URL("./database.db", import.meta.url);
},
});
export default [sqlitePlugin.configs.recommended];
If you have multiple databases you can return a different URL based on the name of the database and/or name of the file that is being linted.
// eslint.config.js
import { createSqlitePlugin } from "eslint-plugin-sqlite";
const sqlitePlugin = createSqlitePlugin({
getDatabase({ name, filename }) {
if (filename.includes("authentication") && name === "users") {
return new URL("./users_database.db", import.meta.url);
} else {
return new URL("./database.db", import.meta.url);
}
},
});
export default [sqlitePlugin.configs.recommended];
If you require additional setup for the database you can return a Database instance instead of a URL.
// eslint.config.js
import { createSqlitePlugin } from "eslint-plugin-sqlite";
import Database from "better-sqlite3";
const sqlitePlugin = createSqlitePlugin({
getDatabase() {
const db = new Database("my_database.db");
db.loadExtension("mod_spatialite");
return db;
},
});
export default [sqlitePlugin.configs.recommended];
By default the ESLint extension for VSCode uses the Node.js version included with VSCode, if that version isn't the same major version as the one used by your project then you need to configure the extension to use the version of Node.js that your project uses.
You can do that by adding the following to your .vscode/settings.json
file:
{
"eslint.runtime": "node"
}
The recommended config enables the valid-query
, typed-input
, and typed-result
rules.
Validates that the query can be prepared by SQLite.
// Bad - Error: in prepare, no such table: user (1)
const users = db.prepare("SELECT * FROM user").all();
// Good
const users = db.prepare("SELECT * FROM users").all();
Generates types for the input parameters of a query.
The type of an input parameter is set to unknown
and for named
parameters you can replace that unknown
with a more specific type.
// Bad
const user = db.prepare("SELECT * FROM users WHERE id = :id").get({ id: 1 });
// Good
const user = db
.prepare<{ id: unknown }>("SELECT * FROM users WHERE id = :id")
.get({ id: 1 });
Generates types for the result of a query.
If the type of a result column can't be determined then it will be typed
as unknown
which you can replace with a more specific type.
// Bad
const user = db.prepare("SELECT * FROM users").all();
// Good
const user = db
.prepare<[], { id: number; name: string }>("SELECT * FROM users")
.all();
Enforce that all queries use the same prefix for named parameters.
Can be configured to one of :
(default), @
, or $
.
// Bad
/* eslint "sqlite/parameter-prefix": ["error", ":"] */
db.prepare("SELECT * FROM users WHERE id = @id");
// Good
/* eslint "sqlite/parameter-prefix": ["error", ":"] */
db.prepare("SELECT * FROM users WHERE id = :id");
eslint-plugin-sqlite is licensed under the MIT License and uses various Rust crates compiled to WebAssembly and bundled with the plugin, their licenses can be found in Third Party Licenses.
FAQs
ESLint plugin that can validate SQLite queries and automatically generate types for query parameters and results
The npm package eslint-plugin-sqlite receives a total of 23 weekly downloads. As such, eslint-plugin-sqlite popularity was classified as not popular.
We found that eslint-plugin-sqlite demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.