-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPostgresSqlRulesDefinition.java
More file actions
247 lines (210 loc) · 13.8 KB
/
PostgresSqlRulesDefinition.java
File metadata and controls
247 lines (210 loc) · 13.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
package com.premiumminds.sonar.postgres;
import java.util.Arrays;
import java.util.List;
import com.premiumminds.sonar.postgres.visitors.AddFieldWithDefaultVisitorCheck;
import com.premiumminds.sonar.postgres.visitors.AddForeignKeyVisitorCheck;
import com.premiumminds.sonar.postgres.visitors.AddingSerialPrimaryKeyfieldvisitorCheck;
import com.premiumminds.sonar.postgres.visitors.BanAlterDomainWithConstraintCheck;
import com.premiumminds.sonar.postgres.visitors.BanCharFieldVisitorCheck;
import com.premiumminds.sonar.postgres.visitors.BanCreateDomainWithConstraintCheck;
import com.premiumminds.sonar.postgres.visitors.BanDropDatabaseVisitorCheck;
import com.premiumminds.sonar.postgres.visitors.BanTruncateCascade;
import com.premiumminds.sonar.postgres.visitors.ChangingColumnTypeVisitorCheck;
import com.premiumminds.sonar.postgres.visitors.ClusterVisitorCheck;
import com.premiumminds.sonar.postgres.visitors.ConcurrentVisitorCheck;
import com.premiumminds.sonar.postgres.visitors.ConstraintMissingNotValidVisitorCheck;
import com.premiumminds.sonar.postgres.visitors.DisallowedDoVisitorCheck;
import com.premiumminds.sonar.postgres.visitors.DisallowedUniqueConstraintVisitorCheck;
import com.premiumminds.sonar.postgres.visitors.DropConstraintDropsIndexVisitorCheck;
import com.premiumminds.sonar.postgres.visitors.OneMigrationPerFileVisitorCheck;
import com.premiumminds.sonar.postgres.visitors.OnlySchemaMigrationsVisitorCheck;
import com.premiumminds.sonar.postgres.visitors.PreferIdentityVisitorCheck;
import com.premiumminds.sonar.postgres.visitors.PreferTextFieldVisitorCheck;
import com.premiumminds.sonar.postgres.visitors.RenameColumnVisitorCheck;
import com.premiumminds.sonar.postgres.visitors.RenameTableVisitorCheck;
import com.premiumminds.sonar.postgres.visitors.RequireEnumValueOrderingCheck;
import com.premiumminds.sonar.postgres.visitors.RobustStatementsVisitorCheck;
import com.premiumminds.sonar.postgres.visitors.SettingNotNullVisitorCheck;
import com.premiumminds.sonar.postgres.visitors.VacuumFullVisitorCheck;
import com.premiumminds.sonar.postgres.visitors.VisitorCheck;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.Severity;
import org.sonar.api.rules.RuleType;
import org.sonar.api.server.rule.RulesDefinition;
public class PostgresSqlRulesDefinition implements RulesDefinition {
public static final String REPOSITORY = "postgres-repository";
public static final RuleKey RULE_PARSE_ERROR = RuleKey.of(REPOSITORY, "parse-error");
public static final RuleKey RULE_PREFER_ROBUST_STMTS = RuleKey.of(REPOSITORY, "prefer-robust-stmts");
public static final RuleKey RULE_CONCURRENTLY = RuleKey.of(REPOSITORY, "concurrently");
public static final RuleKey RULE_ADD_FIELD_WITH_DEFAULT = RuleKey.of(REPOSITORY, "adding-field-with-default");
public static final RuleKey RULE_ADD_FOREIGN_KEY = RuleKey.of(REPOSITORY, "adding-foreign-key-constraint");
public static final RuleKey RULE_SETTING_NOT_NULLABLE_FIELD = RuleKey.of(REPOSITORY, "setting-not-nullable-field");
public static final RuleKey RULE_ADDING_SERIAL_PRIMARY_KEY_FIELD = RuleKey.of(REPOSITORY, "adding-serial-primary-key-field");
public static final RuleKey RULE_BAN_CHAR_FIELD = RuleKey.of(REPOSITORY, "ban-char-field");
public static final RuleKey RULE_BAN_CREATE_DOMAIN_WITH_CONSTRAINT = RuleKey.of(REPOSITORY, "ban-create-domain-with-constraint");
public static final RuleKey RULE_BAN_ALTER_DOMAIN_WITH_CONSTRAINT = RuleKey.of(REPOSITORY, "ban-alter-domain-with-add-constraint");
public static final RuleKey RULE_BAN_TRUNCATE_CASCADE = RuleKey.of(REPOSITORY, "ban-truncate-cascade");
public static final RuleKey RULE_BAN_DROP_DATABASE = RuleKey.of(REPOSITORY, "ban-drop-database");
public static final RuleKey RULE_CHANGING_COLUMN_TYPE = RuleKey.of(REPOSITORY, "changing-column-type");
public static final RuleKey RULE_CONSTRAINT_MISSING_NOT_VALID = RuleKey.of(REPOSITORY, "constraint-missing-not-valid");
public static final RuleKey RULE_DISALLOWED_UNIQUE_CONSTRAINT = RuleKey.of(REPOSITORY, "disallowed-unique-constraint");
public static final RuleKey RULE_PREFER_TEXT_FIELD = RuleKey.of(REPOSITORY, "prefer-text-field");
public static final RuleKey RULE_RENAMING_COLUMN = RuleKey.of(REPOSITORY, "renaming-column");
public static final RuleKey RULE_RENAMING_TABLE = RuleKey.of(REPOSITORY, "renaming-table");
public static final RuleKey RULE_IDENTIFIER_MAX_LENGTH = RuleKey.of(REPOSITORY, "identifier-max-length");
public static final RuleKey RULE_DROP_CONSTRAINT_DROPS_INDEX = RuleKey.of(REPOSITORY, "drop-constraint-drops-index");
public static final RuleKey RULE_VACUUM_FULL = RuleKey.of(REPOSITORY, "vacuum-full");
public static final RuleKey RULE_CLUSTER = RuleKey.of(REPOSITORY, "cluster");
public static final RuleKey RULE_PREFER_IDENTITY_FIELD = RuleKey.of(REPOSITORY, "prefer-identity-field");
public static final RuleKey RULE_ONE_MIGRATION_PER_FILE = RuleKey.of(REPOSITORY, "one-migration-per-file");
public static final RuleKey RULE_DISALLOWED_DO = RuleKey.of(REPOSITORY, "disallowed-do");
public static final RuleKey RULE_ONLY_SCHEMA_MIGRATIONS = RuleKey.of(REPOSITORY, "only-schema-migrations");
public static final RuleKey RULE_ONLY_LOWER_CASE_NAMES = RuleKey.of(REPOSITORY, "only-lower-case-names");
public static final RuleKey RULE_REQUIRE_ENUM_VALUE_ORDERING = RuleKey.of(REPOSITORY, "require-enum-value-ordering");
@Override
public void define(Context context) {
NewRepository repository = context.createRepository(REPOSITORY, PostgresSqlLanguage.KEY);
repository.createRule(RULE_PARSE_ERROR.rule())
.setName("parse error rule")
.setType(RuleType.BUG)
.setSeverity(Severity.BLOCKER)
.setMarkdownDescription(getClass().getResource("parse-error.md"));
repository.createRule(RULE_PREFER_ROBUST_STMTS.rule())
.setName("prefer-robust-stmts rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("prefer-robust-stmts.md"));
repository.createRule(RULE_CONCURRENTLY.rule())
.setName("concurrently rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("concurrently.md"));
repository.createRule(RULE_ADD_FIELD_WITH_DEFAULT.rule())
.setName("adding-field-with-default rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("adding-field-with-default.md"));
repository.createRule(RULE_ADD_FOREIGN_KEY.rule())
.setName("adding-foreign-key-constraint rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("adding-foreign-key-constraint.md"));
repository.createRule(RULE_SETTING_NOT_NULLABLE_FIELD.rule())
.setName("setting-not-nullable-field rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("setting-not-nullable-field.md"));
repository.createRule(RULE_ADDING_SERIAL_PRIMARY_KEY_FIELD.rule())
.setName("adding-serial-primary-key-field rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("adding-serial-primary-key-field.md"));
repository.createRule(RULE_BAN_CHAR_FIELD.rule())
.setName("ban-char-field rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("ban-char-field.md"));
repository.createRule(RULE_BAN_CREATE_DOMAIN_WITH_CONSTRAINT.rule())
.setName("ban-create-domain-with-constraint")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("ban-create-domain-with-constraint.md"));
repository.createRule(RULE_BAN_ALTER_DOMAIN_WITH_CONSTRAINT.rule())
.setName("ban-alter-domain-with-add-constraint")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("ban-alter-domain-with-add-constraint.md"));
repository.createRule(RULE_BAN_TRUNCATE_CASCADE.rule())
.setName("ban-truncate-cascade")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("ban-truncate-cascade.md"));
repository.createRule(RULE_BAN_DROP_DATABASE.rule())
.setName("ban-drop-database rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("ban-drop-database.md"));
repository.createRule(RULE_CHANGING_COLUMN_TYPE.rule())
.setName("changing-column-type rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("changing-column-type.md"));
repository.createRule(RULE_CONSTRAINT_MISSING_NOT_VALID.rule())
.setName("constraint-missing-not-valid rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("constraint-missing-not-valid.md"));
repository.createRule(RULE_DISALLOWED_UNIQUE_CONSTRAINT.rule())
.setName("disallowed-unique-constraint rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("disallowed-unique-constraint.md"));
repository.createRule(RULE_PREFER_TEXT_FIELD.rule())
.setName("prefer-text-field rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("prefer-text-field.md"));
repository.createRule(RULE_RENAMING_COLUMN.rule())
.setName("renaming-column rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("renaming-column.md"));
repository.createRule(RULE_RENAMING_TABLE.rule())
.setName("renaming-table rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("renaming-table.md"));
repository.createRule(RULE_IDENTIFIER_MAX_LENGTH.rule())
.setName("identifier-max-length rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("identifier-max-length.md"));
repository.createRule(RULE_DROP_CONSTRAINT_DROPS_INDEX.rule())
.setName("drop-constraint-drops-index rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("drop-constraint-drops-index.md"));
repository.createRule(RULE_VACUUM_FULL.rule())
.setName("vacuum-full rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("vacuum-full.md"));
repository.createRule(RULE_CLUSTER.rule())
.setName("cluster rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("cluster.md"));
repository.createRule(RULE_PREFER_IDENTITY_FIELD.rule())
.setName("prefer-identity-field rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("prefer-identity-field.md"));
repository.createRule(RULE_ONE_MIGRATION_PER_FILE.rule())
.setName("one-migration-per-file rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("one-migration-per-file.md"));
repository.createRule(RULE_DISALLOWED_DO.rule())
.setName("disallowed-do rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("disallowed-do.md"));
repository.createRule(RULE_ONLY_SCHEMA_MIGRATIONS.rule())
.setName("only-schema-migrations rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("only-schema-migrations.md"));
repository.createRule(RULE_ONLY_LOWER_CASE_NAMES.rule())
.setName("only-lower-case-names rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("only-lower-case-names.md"));
repository.createRule(RULE_REQUIRE_ENUM_VALUE_ORDERING.rule())
.setName("require-enum-value-ordering rule")
.setType(RuleType.BUG)
.setMarkdownDescription(getClass().getResource("require-enum-value-ordering.md"));
repository.done();
}
public static List<VisitorCheck> allChecks(){
return Arrays.asList(
new BanDropDatabaseVisitorCheck(),
new ConcurrentVisitorCheck(),
new RenameColumnVisitorCheck(),
new RenameTableVisitorCheck(),
new RobustStatementsVisitorCheck(),
new SettingNotNullVisitorCheck(),
new DropConstraintDropsIndexVisitorCheck(),
new ChangingColumnTypeVisitorCheck(),
new DisallowedUniqueConstraintVisitorCheck(),
new AddingSerialPrimaryKeyfieldvisitorCheck(),
new ConstraintMissingNotValidVisitorCheck(),
new AddForeignKeyVisitorCheck(),
new AddFieldWithDefaultVisitorCheck(),
new BanCharFieldVisitorCheck(),
new BanCreateDomainWithConstraintCheck(),
new BanAlterDomainWithConstraintCheck(),
new BanTruncateCascade(),
new PreferTextFieldVisitorCheck(),
new VacuumFullVisitorCheck(),
new ClusterVisitorCheck(),
new PreferIdentityVisitorCheck(),
new DisallowedDoVisitorCheck(),
new OneMigrationPerFileVisitorCheck(),
new OnlySchemaMigrationsVisitorCheck(),
new RequireEnumValueOrderingCheck());
}
}