Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 155272a

Browse files
docs: rule suppressions (#443)
1 parent ffeb33f commit 155272a

File tree

2 files changed

+107
-12
lines changed

2 files changed

+107
-12
lines changed

‎docs/rule_suppressions.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Rule Suppressions
2+
3+
You can suppress specific diagnostics or rules in your code using suppression comments. This is useful when you want to ignore a particular rule for an entire file, a line or a block of code.
4+
5+
## How to Suppress a Rule
6+
7+
To suppress a rule, add a comment above the line causing the diagnostic with the following format:
8+
9+
```sql
10+
-- pgt-ignore lint/safety/banDropTable
11+
drop table users;
12+
```
13+
14+
You can suppress single rules, groups of rules, or entire categories. The format of the rule to suppress is:
15+
16+
`category(/group(/specific-rule))`
17+
18+
Where group and specific rule are optional.
19+
20+
So, to suppress the `lint/safety/banDropTable` diagnostic, all of these would work:
21+
22+
```sql
23+
-- pgt-ignore lint
24+
-- pgt-ignore lint/safety
25+
-- pgt-ignore lint/safety/banDropTable
26+
```
27+
28+
You can also add an explanation to the suppression by adding a `:` and the explanation text:
29+
30+
```sql
31+
-- pgt-ignore lint/safety/banDropTable: My startup never had any users.
32+
drop table users;
33+
```
34+
35+
### Suppressing Rules for Block of Code
36+
37+
You can suppress rules for blocks of code.
38+
39+
```sql
40+
create table users (
41+
-- ...
42+
);
43+
44+
-- pgt-ignore-start typecheck: The `users` table will be created with this migration.
45+
alter table users drop constraint users_pkey;
46+
47+
alter table users add primary key (user_id);
48+
-- pgt-ignore-end typecheck
49+
```
50+
51+
Every `pgt-ignore-start` needs a `pgt-ignore-end` suppression comment, and the suppressed rules must match exactly.
52+
53+
This _won't_ work, because the start tag suppresses a different diagnostic:
54+
55+
```sql
56+
-- pgt-ignore-start lint/safety/banDropColumn
57+
-- pgt-ignore-end lint/safety
58+
```
59+
60+
Nesting is allowed, so this works fine:
61+
62+
```sql
63+
-- pgt-ignore-start typecheck: outer
64+
-- pgt-ignore-start lint/safety: inner
65+
-- pgt-ignore-end lint/safety: inner
66+
-- pgt-ignore-end typecheck: outer
67+
```
68+
69+
### Suppressing Rules for Entire Files
70+
71+
Instead of repeating the same suppression on multiple lines, you can suppress for an entire file.
72+
73+
```sql
74+
-- pgt-ignore-all lint/safety/banDropTable
75+
76+
drop table tasks;
77+
drop table projects;
78+
drop table users;
79+
```
80+
81+
## Suppressing Multiple Rules
82+
83+
You can suppress multiple rules by adding multiple suppression comments above a statement:
84+
85+
```sql
86+
-- pgt-ignore lint/safety/banDropColumn
87+
-- pgt-ignore typecheck
88+
alter table tasks drop column created_at;
89+
```
90+
91+
## Notes
92+
93+
- Trying to suppress diagnostics that have already been disabled in your [configuration file](/#configuration) will show a warning.
94+
- Trying to suppress diagnostics that don't haven't been raised will also show a warning.

‎mkdocs.yml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@ repo_name: supabase-community/postgres-language-server
66
repo_url: https://github.com/supabase-community/postgres-language-server
77

88
theme:
9-
name: 'readthedocs'
10-
features:
11-
- navigation.expand
12-
palette:
13-
primary: grey
14-
accent: red
9+
name: "readthedocs"
10+
features:
11+
- navigation.expand
12+
palette:
13+
primary: grey
14+
accent: red
1515
nav:
1616
- Introduction: index.md
1717
- Guides:
18-
- Linting Migrations: checking_migrations.md
19-
- Troubleshooting: troubleshooting.md
18+
- Linting Migrations: checking_migrations.md
19+
- Troubleshooting: troubleshooting.md
2020
- Reference:
21-
- Rules: rules.md
22-
- Rule Sources: rule_sources.md
23-
- CLI: cli_reference.md
24-
- Environment Variables: env_variables.md
21+
- Rules: rules.md
22+
- Rule Sources: rule_sources.md
23+
- Rule Suppressions: rule_suppressions.md
24+
- CLI: cli_reference.md
25+
- Environment Variables: env_variables.md
2526

2627
plugins:
2728
- gh-admonitions

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /