Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/codegen/src/rules_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fn write_how_to_configure(
"#
);

writeln!(content, "```toml title=\"pglt.toml\"")?;
writeln!(content, "```toml")?;
writeln!(content, "{}", toml)?;
writeln!(content, "```")?;

Expand Down
5 changes: 3 additions & 2 deletions docs/codegen/src/rules_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fn generate_group(
writeln!(content)?;
write_markup_to_string(content, description)?;
writeln!(content)?;
writeln!(content)?;
writeln!(content, "| Rule name | Description | Properties |")?;
writeln!(content, "| --- | --- | --- |")?;

Expand All @@ -61,14 +62,14 @@ fn generate_group(

let mut properties = String::new();
if is_recommended {
properties.push_str("<span class='inline-icon' title=\"This rule is recommended\" ><Icon name=\"approve-check-circle\" size=\"1.2rem\" label=\"This rule is recommended\" /></span>");
properties.push('✅');
}

let summary = generate_rule_summary(rule_metadata.docs)?;

write!(
content,
"| [{rule_name}](./rules/{dashed_rule}) | {summary} | {properties} |"
"| [{rule_name}](/rules/{dashed_rule}) | {summary} | {properties} |"
)?;

writeln!(content)?;
Expand Down
29 changes: 29 additions & 0 deletions docs/linting_migrations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Linting Migrations

Postgres Language Tools comes with a `check` command that can be integrated into your development workflow to catch problematic schema changes and encourage best practices.

To run it, simply point at your migrations directory.

```sh
pglt check supabase/migrations
```

When you are setting it up in an existing project, you might want to ignore all migrations that are already applied. To do so, add `migrations_dir` and `after` to your `pglt.toml` file


```toml
[migrations]
migrations_dir = "supabase/migrations"
after = 1740868021
```

Alternatively, pass them directly.

```
pglt check supabase/migrations --migrations-dir="supabase/migrations" --after=1740868021
```

This will only check migrations after the specified timestamp.

For pre-commit hooks and when working locally, use `--staged` to only lint files that have been staged. In CI environments, you most likely want to use `--changed` to only lint files that have been changed compared to your `defaultBranch` configuration. If `defaultBranch` is not set in your `pglt.toml`, use `--since=REF` to specify the base branch to compare against.

11 changes: 6 additions & 5 deletions docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

Below the list of rules supported by Postgres Language Tools, divided by group. Here's a legend of the emojis:

- The icon <span class='inline-icon' title="This rule is recommended"><Icon name="approve-check-circle"x label="This rule is recommended" /></span> indicates that the rule is part of the recommended rules.
- The icon indicates that the rule is part of the recommended rules.

[//]: # (BEGIN RULES_INDEX)

## Safety

Rules that detect potential safety issues in your code.

| Rule name | Description | Properties |
| --- | --- | --- |
| [addingRequiredField](./rules/adding-required-field) | Adding a new column that is NOT NULL and has no default value to an existing table effectively makes it required. | |
| [banDropColumn](./rules/ban-drop-column) | Dropping a column may break existing clients. | <span class='inline-icon' title="This rule is recommended" ><Icon name="approve-check-circle" size="1.2rem" label="This rule is recommended" /></span> |
| [banDropNotNull](./rules/ban-drop-not-null) | Dropping a NOT NULL constraint may break existing clients. | <span class='inline-icon' title="This rule is recommended" ><Icon name="approve-check-circle" size="1.2rem" label="This rule is recommended" /></span> |
| [banDropTable](./rules/ban-drop-table) | Dropping a table may break existing clients. | <span class='inline-icon' title="This rule is recommended" ><Icon name="approve-check-circle" size="1.2rem" label="This rule is recommended" /></span> |
| [addingRequiredField](/rules/adding-required-field) | Adding a new column that is NOT NULL and has no default value to an existing table effectively makes it required. | |
| [banDropColumn](/rules/ban-drop-column) | Dropping a column may break existing clients. | |
| [banDropNotNull](/rules/ban-drop-not-null) | Dropping a NOT NULL constraint may break existing clients. | |
| [banDropTable](/rules/ban-drop-table) | Dropping a table may break existing clients. | |

[//]: # (END RULES_INDEX)

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/adding-required-field.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ alter table test add column count int not null;
alter table test add column count int not null default 0;

## How to configure
```toml title="pglt.toml"
```toml
[linter.rules.safety]
addingRequiredField = "error"

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/ban-drop-column.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ code-block.sql lint/safety/banDropColumn ━━━━━━━━━━━━━
```

## How to configure
```toml title="pglt.toml"
```toml
[linter.rules.safety]
banDropColumn = "error"

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/ban-drop-not-null.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ code-block.sql lint/safety/banDropNotNull ━━━━━━━━━━━━
```

## How to configure
```toml title="pglt.toml"
```toml
[linter.rules.safety]
banDropNotNull = "error"

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/ban-drop-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ code-block.sql lint/safety/banDropTable ━━━━━━━━━━━━━
```

## How to configure
```toml title="pglt.toml"
```toml
[linter.rules.safety]
banDropTable = "error"

Expand Down
39 changes: 39 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
site_name: Postgres Language Tools
site_url: https://pglt.github.io
site_description: A collection of language tools and a Language Server Protocol (LSP) implementation for Postgres, focusing on developer experience and reliable SQL tooling.

repo_name: supabase-community/postgres_lsp
repo_url: https://github.com/supabase-community/postgres_lsp

theme:
name: 'readthedocs'
features:
- navigation.expand
palette:
primary: grey
accent: red
nav:
- Introduction: index.md
- Guides:
- Linting Migrations: linting_migrations.md
- Troubleshooting: troubleshooting.md
- Reference:
- Rules: rules.md
- Rule Sources: rule_sources.md
- CLI: cli_reference.md
- Environment Variables: env_variables.md

plugins:
- gh-admonitions

markdown_extensions:
- admonition
# - pymdownx.highlight:
# anchor_linenums: true
# line_spans: __span
# pygments_lang_class: true
# - pymdownx.inlinehilite
# - pymdownx.snippets
# - pymdownx.superfences
# - pymdownx.tabbed:
# alternate_style: true
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[project]
name = "pglt"
version = "0.1.0"
description = "A collection of language tools and a Language Server Protocol (LSP) implementation for Postgres, focusing on developer experience and reliable SQL tooling."
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
"mkdocs>=1.6.1",
"mkdocs-github-admonitions-plugin>=0.0.3",
]
Loading