From 82e1f9d7b8dded2bf05da7eb59ebfb549f595a48 Mon Sep 17 00:00:00 2001 From: Mark Fashing Date: Tue, 28 Jul 2020 14:15:54 -0600 Subject: [PATCH] Support Spanner schema and Skylark files. Adds support for the .sdl file extension which is used for Spanner's Schema Definition Language. It uses -- for comments in the manner of .sql files. Adds support for the .bzl file extension which is used for Bazel's Starlark language. It uses # for comments in the manner of Python. --- main.go | 4 ++-- testdata/expected/file.bzl | 19 +++++++++++++++++++ testdata/expected/file.sdl | 22 ++++++++++++++++++++++ testdata/initial/file.bzl | 5 +++++ testdata/initial/file.sdl | 8 ++++++++ 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 testdata/expected/file.bzl create mode 100644 testdata/expected/file.sdl create mode 100644 testdata/initial/file.bzl create mode 100644 testdata/initial/file.sdl diff --git a/main.go b/main.go index 295aeb1..c449ad2 100644 --- a/main.go +++ b/main.go @@ -211,13 +211,13 @@ func licenseHeader(path string, tmpl *template.Template, data *copyrightData) ([ lic, err = prefix(tmpl, data, "/**", " * ", " */") case ".cc", ".cpp", ".cs", ".go", ".hh", ".hpp", ".java", ".m", ".mm", ".proto", ".rs", ".scala", ".swift", ".dart", ".groovy", ".kt", ".kts": lic, err = prefix(tmpl, data, "", "// ", "") - case ".py", ".sh", ".yaml", ".yml", ".dockerfile", "dockerfile", ".rb", "gemfile": + case ".py", ".sh", ".yaml", ".yml", ".dockerfile", "dockerfile", ".rb", "gemfile", ".bzl": lic, err = prefix(tmpl, data, "", "# ", "") case ".el", ".lisp": lic, err = prefix(tmpl, data, "", ";; ", "") case ".erl": lic, err = prefix(tmpl, data, "", "% ", "") - case ".hs", ".sql": + case ".hs", ".sql", ".sdl": lic, err = prefix(tmpl, data, "", "-- ", "") case ".html", ".xml", ".vue": lic, err = prefix(tmpl, data, "") diff --git a/testdata/expected/file.bzl b/testdata/expected/file.bzl new file mode 100644 index 0000000..0961665 --- /dev/null +++ b/testdata/expected/file.bzl @@ -0,0 +1,19 @@ +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Say hello +def hello(): + print("Hello world!") + +hello() diff --git a/testdata/expected/file.sdl b/testdata/expected/file.sdl new file mode 100644 index 0000000..2d84c9c --- /dev/null +++ b/testdata/expected/file.sdl @@ -0,0 +1,22 @@ +-- Copyright 2018 Google LLC +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. + +-- This is a fake table. +CREATE TABLE Foo ( + -- This is a fake column. + Bar INT64 NOT NULL, + + -- Another fake column. + Baz STRING(MAX) NOT NULL, +) PRIMARY KEY (Bar); diff --git a/testdata/initial/file.bzl b/testdata/initial/file.bzl new file mode 100644 index 0000000..96328ee --- /dev/null +++ b/testdata/initial/file.bzl @@ -0,0 +1,5 @@ +# Say hello +def hello(): + print("Hello world!") + +hello() diff --git a/testdata/initial/file.sdl b/testdata/initial/file.sdl new file mode 100644 index 0000000..639a923 --- /dev/null +++ b/testdata/initial/file.sdl @@ -0,0 +1,8 @@ +-- This is a fake table. +CREATE TABLE Foo ( + -- This is a fake column. + Bar INT64 NOT NULL, + + -- Another fake column. + Baz STRING(MAX) NOT NULL, +) PRIMARY KEY (Bar);