Skip to content

Commit

Permalink
Add extra newline after a comment when it is not in a block or a stat…
Browse files Browse the repository at this point in the history
…ement. Thanks to Aaron Reisman for the report.
  • Loading branch information
darold committed Nov 10, 2018
1 parent 3f151ea commit bdbcefe
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/pgFormatter/Beautify.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,12 @@ sub beautify {
$token =~ s/\s*$//;
$self->_add_token( $token );
$self->_new_line if ($start);
# Add extra newline after the last comment if we are not in a block or a statement
if (defined $self->_next_token and $self->_next_token !~ /^\s*--/) {
$self->{ 'content' } .= "\n" if ($self->{ '_is_in_block' } == -1
and !$self->{ '_is_in_declare' } and !$self->{ '_fct_code_delimiter' }
and !$self->{ '_current_sql_stmt' });
}
next;
}

Expand Down
9 changes: 9 additions & 0 deletions samples/ex18.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,12 @@ GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA foo TO role_bar, ro

SELECT * FROM t WHERE a IS NOT DISTINCT FROM b;

-- Deploy schemas/custom/grants/grant_schema_to_authenticated to pg
-- requires: schemas/custom/schema
BEGIN;

GRANT USAGE ON SCHEMA custom
TO authenticated;
GRANT USAGE ON SCHEMA custom TO authenticated;

COMMIT;
1 change: 1 addition & 0 deletions samples/expected/ex1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
-- Please click the button <Format>
-- or "ctrl+F"
------------------------------------------

SELECT
price.col1 AS col1,
price.col2 AS col2,
Expand Down
50 changes: 50 additions & 0 deletions samples/expected/ex17.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
--
-- Dumped from database version 9.6.2
-- Dumped by pg_dump version 9.6.2

SET statement_timeout = 0;

SET lock_timeout = 0;
Expand All @@ -22,18 +23,21 @@ SET row_security = off;
--
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner:
--

CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;

--
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner:
--

COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';

SET search_path = public, pg_catalog;

--
-- Name: add(integer, integer); Type: FUNCTION; Schema: public; Owner: gilles
--

CREATE FUNCTION ADD (integer, integer)
RETURNS integer
LANGUAGE sql
Expand All @@ -48,6 +52,7 @@ ALTER FUNCTION public.add (integer, integer) OWNER TO gilles;
--
-- Name: check_password(text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text); Type: FUNCTION; Schema: public; Owner: gilles
--

CREATE FUNCTION check_password (uname1 text, pass1 text, uname2 text, pass2 text, uname3 text, pass3 text, uname4 text, pass4 text, uname5 text, pass5 text, uname6 text, pass6 text, uname7 text, pass7 text, uname8 text, pass8 text, uname9 text, pass9 text)
RETURNS boolean
LANGUAGE plpgsql
Expand All @@ -72,6 +77,7 @@ ALTER FUNCTION public.check_password (uname1 text, pass1 text, uname2 text, pass
--
-- Name: dup(integer); Type: FUNCTION; Schema: public; Owner: gilles
--

CREATE FUNCTION dup (integer, OUT f1 integer, OUT f2 text)
RETURNS record
LANGUAGE sql
Expand All @@ -86,6 +92,7 @@ ALTER FUNCTION public.dup (integer, OUT f1 integer, OUT f2 text) OWNER TO gilles
--
-- Name: increment(integer); Type: FUNCTION; Schema: public; Owner: gilles
--

CREATE FUNCTION INCREMENT (i integer)
RETURNS integer
LANGUAGE plpgsql
Expand All @@ -100,6 +107,7 @@ ALTER FUNCTION public.increment (i integer) OWNER TO gilles;
--
-- Name: peuple_stock(integer, integer); Type: FUNCTION; Schema: public; Owner: userdb
--

CREATE FUNCTION peuple_stock (annee_debut integer, annee_fin integer)
RETURNS bigint
LANGUAGE plpgsql
Expand Down Expand Up @@ -165,6 +173,7 @@ ALTER FUNCTION public.peuple_stock (annee_debut integer, annee_fin integer) OWNE
--
-- Name: peuple_vin(); Type: FUNCTION; Schema: public; Owner: userdb
--

CREATE FUNCTION peuple_vin ()
RETURNS bigint
LANGUAGE plpgsql
Expand Down Expand Up @@ -228,6 +237,7 @@ ALTER FUNCTION public.peuple_vin () OWNER TO userdb;
--
-- Name: trous_stock(); Type: FUNCTION; Schema: public; Owner: userdb
--

CREATE FUNCTION trous_stock ()
RETURNS bigint
LANGUAGE plpgsql
Expand Down Expand Up @@ -302,6 +312,7 @@ ALTER FUNCTION public.trous_stock () OWNER TO userdb;
--
-- Name: trous_vin(); Type: FUNCTION; Schema: public; Owner: userdb
--

CREATE FUNCTION trous_vin ()
RETURNS bigint
LANGUAGE plpgsql
Expand Down Expand Up @@ -354,6 +365,7 @@ SET default_with_oids = FALSE;
--
-- Name: appellation; Type: TABLE; Schema: public; Owner: userdb
--

CREATE TABLE appellation (
id integer NOT NULL,
libelle text NOT NULL,
Expand All @@ -368,6 +380,7 @@ ALTER TABLE appellation OWNER TO userdb;
--
-- Name: appellation_id_seq; Type: SEQUENCE; Schema: public; Owner: userdb
--

CREATE SEQUENCE appellation_id_seq
START WITH 1
INCREMENT BY 1
Expand All @@ -380,11 +393,13 @@ ALTER TABLE appellation_id_seq OWNER TO userdb;
--
-- Name: appellation_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: userdb
--

ALTER SEQUENCE appellation_id_seq OWNED BY appellation.id;

--
-- Name: contenant; Type: TABLE; Schema: public; Owner: userdb
--

CREATE TABLE contenant (
id integer NOT NULL,
contenance real NOT NULL,
Expand All @@ -400,6 +415,7 @@ ALTER TABLE contenant OWNER TO userdb;
--
-- Name: contenant_id_seq; Type: SEQUENCE; Schema: public; Owner: userdb
--

CREATE SEQUENCE contenant_id_seq
START WITH 1
INCREMENT BY 1
Expand All @@ -412,11 +428,13 @@ ALTER TABLE contenant_id_seq OWNER TO userdb;
--
-- Name: contenant_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: userdb
--

ALTER SEQUENCE contenant_id_seq OWNED BY contenant.id;

--
-- Name: recoltant; Type: TABLE; Schema: public; Owner: userdb
--

CREATE TABLE recoltant (
id integer NOT NULL,
nom text,
Expand All @@ -431,6 +449,7 @@ ALTER TABLE recoltant OWNER TO userdb;
--
-- Name: recoltant_id_seq; Type: SEQUENCE; Schema: public; Owner: userdb
--

CREATE SEQUENCE recoltant_id_seq
START WITH 1
INCREMENT BY 1
Expand All @@ -443,11 +462,13 @@ ALTER TABLE recoltant_id_seq OWNER TO userdb;
--
-- Name: recoltant_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: userdb
--

ALTER SEQUENCE recoltant_id_seq OWNED BY recoltant.id;

--
-- Name: region; Type: TABLE; Schema: public; Owner: userdb
--

CREATE TABLE region (
id integer NOT NULL,
libelle text NOT NULL
Expand All @@ -461,6 +482,7 @@ ALTER TABLE region OWNER TO userdb;
--
-- Name: region_id_seq; Type: SEQUENCE; Schema: public; Owner: userdb
--

CREATE SEQUENCE region_id_seq
START WITH 1
INCREMENT BY 1
Expand All @@ -473,11 +495,13 @@ ALTER TABLE region_id_seq OWNER TO userdb;
--
-- Name: region_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: userdb
--

ALTER SEQUENCE region_id_seq OWNED BY region.id;

--
-- Name: stock; Type: TABLE; Schema: public; Owner: userdb
--

CREATE TABLE stock (
vin_id integer NOT NULL,
contenant_id integer NOT NULL,
Expand All @@ -493,6 +517,7 @@ ALTER TABLE stock OWNER TO userdb;
--
-- Name: type_vin; Type: TABLE; Schema: public; Owner: userdb
--

CREATE TABLE type_vin (
id integer NOT NULL,
libelle text NOT NULL
Expand All @@ -506,6 +531,7 @@ ALTER TABLE type_vin OWNER TO userdb;
--
-- Name: type_vin_id_seq; Type: SEQUENCE; Schema: public; Owner: userdb
--

CREATE SEQUENCE type_vin_id_seq
START WITH 1
INCREMENT BY 1
Expand All @@ -518,11 +544,13 @@ ALTER TABLE type_vin_id_seq OWNER TO userdb;
--
-- Name: type_vin_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: userdb
--

ALTER SEQUENCE type_vin_id_seq OWNED BY type_vin.id;

--
-- Name: vin; Type: TABLE; Schema: public; Owner: userdb
--

CREATE TABLE vin (
id integer NOT NULL,
recoltant_id integer,
Expand All @@ -538,6 +566,7 @@ ALTER TABLE vin OWNER TO userdb;
--
-- Name: vin_id_seq; Type: SEQUENCE; Schema: public; Owner: userdb
--

CREATE SEQUENCE vin_id_seq
START WITH 1
INCREMENT BY 1
Expand All @@ -550,119 +579,140 @@ ALTER TABLE vin_id_seq OWNER TO userdb;
--
-- Name: vin_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: userdb
--

ALTER SEQUENCE vin_id_seq OWNED BY vin.id;

--
-- Name: appellation id; Type: DEFAULT; Schema: public; Owner: userdb
--

ALTER TABLE ONLY appellation ALTER COLUMN id SET DEFAULT nextval('appellation_id_seq'::regclass);

--
-- Name: contenant id; Type: DEFAULT; Schema: public; Owner: userdb
--

ALTER TABLE ONLY contenant ALTER COLUMN id SET DEFAULT nextval('contenant_id_seq'::regclass);

--
-- Name: recoltant id; Type: DEFAULT; Schema: public; Owner: userdb
--

ALTER TABLE ONLY recoltant ALTER COLUMN id SET DEFAULT nextval('recoltant_id_seq'::regclass);

--
-- Name: region id; Type: DEFAULT; Schema: public; Owner: userdb
--

ALTER TABLE ONLY region ALTER COLUMN id SET DEFAULT nextval('region_id_seq'::regclass);

--
-- Name: type_vin id; Type: DEFAULT; Schema: public; Owner: userdb
--

ALTER TABLE ONLY type_vin ALTER COLUMN id SET DEFAULT nextval('type_vin_id_seq'::regclass);

--
-- Name: vin id; Type: DEFAULT; Schema: public; Owner: userdb
--

ALTER TABLE ONLY vin ALTER COLUMN id SET DEFAULT nextval('vin_id_seq'::regclass);

--
-- Name: appellation appellation_libelle_key; Type: CONSTRAINT; Schema: public; Owner: userdb
--

ALTER TABLE ONLY appellation
ADD CONSTRAINT appellation_libelle_key UNIQUE (libelle);

--
-- Name: appellation appellation_pkey; Type: CONSTRAINT; Schema: public; Owner: userdb
--

ALTER TABLE ONLY appellation
ADD CONSTRAINT appellation_pkey PRIMARY KEY (id);

--
-- Name: contenant contenant_pkey; Type: CONSTRAINT; Schema: public; Owner: userdb
--

ALTER TABLE ONLY contenant
ADD CONSTRAINT contenant_pkey PRIMARY KEY (id);

--
-- Name: recoltant recoltant_pkey; Type: CONSTRAINT; Schema: public; Owner: userdb
--

ALTER TABLE ONLY recoltant
ADD CONSTRAINT recoltant_pkey PRIMARY KEY (id);

--
-- Name: region region_pkey; Type: CONSTRAINT; Schema: public; Owner: userdb
--

ALTER TABLE ONLY region
ADD CONSTRAINT region_pkey PRIMARY KEY (id);

--
-- Name: stock stock_pkey; Type: CONSTRAINT; Schema: public; Owner: userdb
--

ALTER TABLE ONLY stock
ADD CONSTRAINT stock_pkey PRIMARY KEY (vin_id, contenant_id, annee);

--
-- Name: type_vin type_vin_pkey; Type: CONSTRAINT; Schema: public; Owner: userdb
--

ALTER TABLE ONLY type_vin
ADD CONSTRAINT type_vin_pkey PRIMARY KEY (id);

--
-- Name: vin vin_pkey; Type: CONSTRAINT; Schema: public; Owner: userdb
--

ALTER TABLE ONLY vin
ADD CONSTRAINT vin_pkey PRIMARY KEY (id);

--
-- Name: appellation appellation_region_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: userdb
--

ALTER TABLE ONLY appellation
ADD CONSTRAINT appellation_region_id_fkey FOREIGN KEY (region_id) REFERENCES region (id) ON DELETE CASCADE;

--
-- Name: stock stock_contenant_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: userdb
--

ALTER TABLE ONLY stock
ADD CONSTRAINT stock_contenant_id_fkey FOREIGN KEY (contenant_id) REFERENCES contenant (id) ON DELETE CASCADE;

--
-- Name: stock stock_vin_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: userdb
--

ALTER TABLE ONLY stock
ADD CONSTRAINT stock_vin_id_fkey FOREIGN KEY (vin_id) REFERENCES vin (id) ON DELETE CASCADE;

--
-- Name: vin vin_appellation_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: userdb
--

ALTER TABLE ONLY vin
ADD CONSTRAINT vin_appellation_id_fkey FOREIGN KEY (appellation_id) REFERENCES appellation (id) ON DELETE CASCADE;

--
-- Name: vin vin_recoltant_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: userdb
--

ALTER TABLE ONLY vin
ADD CONSTRAINT vin_recoltant_id_fkey FOREIGN KEY (recoltant_id) REFERENCES recoltant (id) ON DELETE CASCADE;

--
-- Name: vin vin_type_vin_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: userdb
--

ALTER TABLE ONLY vin
ADD CONSTRAINT vin_type_vin_id_fkey FOREIGN KEY (type_vin_id) REFERENCES type_vin (id) ON DELETE CASCADE;

Expand Down
Loading

0 comments on commit bdbcefe

Please sign in to comment.