• This repository has been archived on 30/Aug/2024
  • Stars
    star
    133
  • Rank 272,600 (Top 6 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PL/SQL & SQL formatter settings based on the Trivadis PL/SQL & SQL Coding Guidelines

PL/SQL & SQL Formatter Settings

Introduction

This repository provides formatter settings for the coding style rules of the Trivadis PL/SQL & SQL Coding Guidelines.

Settings are primarily provided for

These settings have been defined and tested with the product versions mentioned above. They might not work in other versions.

JDK 11 is required for SQLDev and SQLcl. The standalone tvdformat.jar works with JDK 11 or newer.

See releases for settings supporting older versions.

Deviating Settings

Please note that these settings do not comply with rule 5. Line breaks are placed after a comma and not before. All other rules are followed. However, you can easily change this in the preferences.

Change Line Breaks On Comma

Installation

Common

Clone this repository or download the ZIP file and extract it.

SQLcl

See sqlcl/README.md.

Standalone Formatter

See standalone/README.md

SQL Developer

  1. Start SQL Developer
  2. Open Preferences
  3. Select Code Editor -> Format -> Advanced Format
  4. Press Import... Advanced Format
  5. Select trivadis_advanced_format.xml
  6. Press Open
  7. Select Code Editor -> Format -> Advanced Format -> Custom Format
  8. Press Import... Custom Format
  9. Select trivadis_custom_format.arbori
  10. Press Open
  11. Press OK to save the settings

Git pre-commit Hook

See hook/README.md.

Nice to Know

Lightweight Formatter

The Arbori program implements a lightweight formatter which accepts different coding styles. The primary scope of the formatter is the following SQL statements:

  • create function
  • create package
  • create package body
  • create procedure
  • create trigger
  • create type
  • create type body
  • create view (including the subquery part of create materialized view)
  • delete
  • insert
  • merge
  • select
  • update

Other statements like create table or create tablespace are basically left as is. There are some exceptions like adding line breaks after reaching the maximum line length and changing the case of keywords and identifiers. But that's it.

If you need a heavyweight formatter to enforce the conformity of your code, you will need to use the default Arbori program provided by the SQL Developer team.

In any case, you can use our SQLcl JavaScript format.js, the standalone formatter or the Git pre-commit hook to format your code.

Disable Formatter

The formatter is enabled by default. You can disable the formatter with a single-line or multi-line comment containing @formatter:off. From that point on, whitespace are kept as is. To re-enable the formatter use @formatter:on.

Supported Marker Comment Action Origin
@formatter:off Disables formatter Eclipse IDE
@formatter:on Enables formatter Eclipse IDE
noformat start Disables formatter PL/SQL Developer
noformat end Enables formatter PL/SQL Developer

The marker comments are case sensitive.

Here's an example showing the code after calling the formatter:

-- @formatter:off
select decode(dummy, 'X', 1 
                   , 'Y', 2
                   , 'Z', 3
                        , 0) /* @formatter:on */
  from dual;

Arbori

SQL Developer uses its own parse tree query language called Arbori for its advanced formatter configuration. Here is some additional information that might be useful if you plan to tweak the behavior of the formatter yourself.

Links

Thank you, Vadim Tropashko for providing this valuable information.

JavaScript Global Variables

To get the most out of the dynamic JavaScript actions from an Arbori program, you should know the following global variables and their corresponding Java class.

Variable Type JAR File
struct oracle.dbtools.app.Format dbtools-common.jar
target oracle.dbtools.parser.Parsed dbtools-common.jar
tuple HashMap<String, oracle.dbtools.parser.ParseNode> dbtools-common.jar
logger oracle.dbtools.util.Logger dbtools-common.jar

Settings for other Products

Formatter settings are also provided for the following products:

Product Version File
Allround Automations PL/SQL Developer 14.0.6 trivadis_beautifier.br
JetBrains DataGrip 2021.1 trivadis.xml
Quest Toad for Oracle 14.1 trivadis_fmtplus.opt

Please refer to the vendor's documentation for instructions on how to import these settings.

License

The Trivadis PL/SQL & SQL Formatter Settings are licensed under the Apache License, Version 2.0. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

More Repositories

1

plsql-and-sql-coding-guidelines

Trivadis PL/SQL & SQL Coding Guidelines
Shell
179
star
2

plsql-unwrapper-sqldev

PL/SQL Unwrapper for SQL Developer
62
star
3

plsql-cop-sqldev

db* CODECOP for SQL Developer
30
star
4

plsql-cop-cli

db* CODECOP Command Line
25
star
5

sqldev-jdbc-proxy

JDBC driver for SQL Developer that can delegate MySQL requests to Snowflake, PostgreSQL, SQLite, H2 and MySQL.
Java
16
star
6

plsql-cop-sonar

db* CODECOP for SonarQube
13
star
7

pgbasenv

pgBasEnv - PostgreSQL Base Environment Tool
Shell
9
star
8

plsql-cop-validators

db* CODECOP Validators
Java
9
star
9

plsql-syntax-colors

PL/SQL Syntax Colors for SQL Developer
9
star
10

pgoperate

pgOperate - PostgreSQL Operation Tool
Shell
9
star
11

AdvancedAngular

Übungen für den Advanced Angular Kurs
TypeScript
8
star
12

TypeScriptAndAngularTraining

Contains projects for the TypeScript Angular startup training
TypeScript
7
star
13

plsql-analyzer

PL/SQL Analyzer is a command line utility to store the PL/SQL parse-trees in relational tables for further analysis
6
star
14

tvd-pgenv

pgBasEnv - PostgreSQL Base Environment Tool
Shell
5
star
15

Angular-Playground

TypeScript
3
star
16

terraform-oci-tvdlab-bastion

A reusable and extensible Terraform module that provisions a Trivadis LAB Bastion Host on Oracle Cloud Infrastructure
HCL
2
star
17

Grueezi.AI

Grüezi.AI
C#
2
star
18

WebWinFormsInteraction

Demos from Article in Windows Developer
C#
2
star
19

vscode-ngtvd-extensions

2
star
20

terraform-examples

Trivadis Terraform examples and code snippets
HCL
2
star
21

AngularCrashCourse

TypeScript
2
star
22

terraform-oci-tvdlab-host

A reusable and extensible Terraform module that provisions a Trivadis LAB host on Oracle Cloud Infrastructure
HCL
1
star
23

good-practice-template

A template for Trivadis Good Practice Guides on various technologies
1
star
24

AngularExpert

TypeScript
1
star
25

LocalizationWithNgxTranslate

How to localize an Angular App with NgxTranslate
TypeScript
1
star
26

terraform-oci-tvdlab-vcn

A reusable and extensible Terraform module that provisions a Trivadis LAB VCN on Oracle Cloud Infrastructure
HCL
1
star
27

terraform-oci-tvdlab-base

A reusable and extensible Terraform module that provisions a Trivadis LAB on Oracle Cloud Infrastructure
HCL
1
star
28

AzureDeveloperBootcamp

Azure Bootcamp for Developers
CSS
1
star