Why this matters
`TRUNCATE ... CASCADE` transitively empties every table whose foreign keys reference the target. That is essentially never the right tool for the intended operation.
Examples
Incorrect
TRUNCATE users CASCADE;Correct
TRUNCATE users;TRUNCATE users RESTRICT;Configure it
// eslint.config.js
import postgresql from "eslint-plugin-postgresql";
export default [
{
files: ["**/*.sql"],
languageOptions: {
parser: postgresql.configs.recommended.languageOptions.parser,
},
plugins: { postgresql },
rules: {
"postgresql/no-truncate-cascade": "warn",
},
},
]; Options
Edit the SQL — only no-truncate-cascade is enabled.
Pre-filled with the first incorrect example. Toggle off in the rule shelf to see how the diagnostic disappears.
Diagnostics
No issues found.
2 rules enabled.
Rule under test
no-truncate-cascade — plus no-syntax-error as a safety net.