safety

package
v1.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package safety provides linter rules for detecting dangerous SQL operations that can cause irreversible data loss or security vulnerabilities.

Rules:

  • L011: DELETE without WHERE clause
  • L012: UPDATE without WHERE clause
  • L013: DROP without IF EXISTS
  • L014: TRUNCATE TABLE warning
  • L015: SELECT INTO OUTFILE/DUMPFILE

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeleteWithoutWhereRule

type DeleteWithoutWhereRule struct{ linter.BaseRule }

DeleteWithoutWhereRule (L011) flags DELETE statements that have no WHERE clause. Unfiltered DELETEs remove all rows from a table and are almost always a mistake.

func NewDeleteWithoutWhereRule

func NewDeleteWithoutWhereRule() *DeleteWithoutWhereRule

NewDeleteWithoutWhereRule creates a new L011 rule instance.

func (*DeleteWithoutWhereRule) Check

Check walks the AST for DELETE statements without a WHERE clause. Fires at any nesting level — a DELETE in a CTE body (data-modifying CTE) without a WHERE clause is just as dangerous as a top-level DELETE.

func (*DeleteWithoutWhereRule) Fix

func (r *DeleteWithoutWhereRule) Fix(content string, violations []linter.Violation) (string, error)

Fix is a no-op: it is unsafe to auto-fix a missing WHERE clause.

type DropWithoutConditionRule

type DropWithoutConditionRule struct{ linter.BaseRule }

DropWithoutConditionRule (L013) flags DROP TABLE/VIEW/INDEX without IF EXISTS. Without IF EXISTS, a DROP on a non-existent object raises a fatal error in most databases.

func NewDropWithoutConditionRule

func NewDropWithoutConditionRule() *DropWithoutConditionRule

NewDropWithoutConditionRule creates a new L013 rule instance.

func (*DropWithoutConditionRule) Check

Check walks the AST for DROP statements without IF EXISTS at any nesting level. DROP rarely appears nested, but walking makes the rule consistent and catches edge cases like nested script blocks.

func (*DropWithoutConditionRule) Fix

func (r *DropWithoutConditionRule) Fix(content string, violations []linter.Violation) (string, error)

Fix is a no-op: adding IF EXISTS requires careful SQL manipulation.

type SelectIntoOutfileRule

type SelectIntoOutfileRule struct{ linter.BaseRule }

SelectIntoOutfileRule (L015) flags SELECT ... INTO OUTFILE / INTO DUMPFILE patterns. These operations write data to the server filesystem — a significant security risk. This rule works at the text level since SELECT INTO OUTFILE is a MySQL extension that may not always produce a full AST node.

func NewSelectIntoOutfileRule

func NewSelectIntoOutfileRule() *SelectIntoOutfileRule

NewSelectIntoOutfileRule creates a new L015 rule instance.

func (*SelectIntoOutfileRule) Check

Check scans the SQL text for SELECT ... INTO OUTFILE or INTO DUMPFILE patterns.

func (*SelectIntoOutfileRule) Fix

func (r *SelectIntoOutfileRule) Fix(content string, violations []linter.Violation) (string, error)

Fix is a no-op: removing OUTFILE requires understanding export intent.

type TruncateTableRule

type TruncateTableRule struct{ linter.BaseRule }

TruncateTableRule (L014) warns when TRUNCATE TABLE is used. TRUNCATE is irreversible and bypasses row-level triggers — dangerous in application code.

func NewTruncateTableRule

func NewTruncateTableRule() *TruncateTableRule

NewTruncateTableRule creates a new L014 rule instance.

func (*TruncateTableRule) Check

func (r *TruncateTableRule) Check(ctx *linter.Context) ([]linter.Violation, error)

Check walks the AST for TRUNCATE TABLE statements at any nesting level. TRUNCATE almost never appears nested, but walking makes the rule consistent.

func (*TruncateTableRule) Fix

func (r *TruncateTableRule) Fix(content string, violations []linter.Violation) (string, error)

Fix is a no-op: converting TRUNCATE to DELETE requires human intent.

type UpdateWithoutWhereRule

type UpdateWithoutWhereRule struct{ linter.BaseRule }

UpdateWithoutWhereRule (L012) flags UPDATE statements that have no WHERE clause. Unfiltered UPDATEs modify all rows in a table and are almost always a mistake.

func NewUpdateWithoutWhereRule

func NewUpdateWithoutWhereRule() *UpdateWithoutWhereRule

NewUpdateWithoutWhereRule creates a new L012 rule instance.

func (*UpdateWithoutWhereRule) Check

Check walks the AST for UPDATE statements without a WHERE clause. Fires at any nesting level — an UPDATE in a CTE body (data-modifying CTE) without a WHERE clause is just as dangerous as a top-level UPDATE.

func (*UpdateWithoutWhereRule) Fix

func (r *UpdateWithoutWhereRule) Fix(content string, violations []linter.Violation) (string, error)

Fix is a no-op: it is unsafe to auto-fix a missing WHERE clause.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL