Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Vim, AWK, Elixir, Julia, and Raku support #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 55 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,62 @@ func licenseHeader(path string, tmpl *template.Template, data licenseData) ([]by
base := strings.ToLower(filepath.Base(path))

switch fileExtension(base) {
case ".c", ".h", ".gv", ".java", ".scala", ".kt", ".kts":
case ".c",
".h",
".gv",
".java",
".scala",
".kt",
".kts":
lic, err = executeTemplate(tmpl, data, "/*", " * ", " */")
case ".js", ".mjs", ".cjs", ".jsx", ".tsx", ".css", ".scss", ".sass", ".ts":
case ".js",
".mjs",
".cjs",
".jsx",
".tsx",
".css",
".scss",
".sass",
".ts":
lic, err = executeTemplate(tmpl, data, "/**", " * ", " */")
case ".cc", ".cpp", ".cs", ".go", ".hcl", ".hh", ".hpp", ".m", ".mm", ".proto", ".rs", ".swift", ".dart", ".groovy", ".v", ".sv":
case ".cc",
".cpp",
".cs",
".go",
".hcl",
".hh",
".hpp",
".m",
".mm",
".proto",
".rs",
".swift",
".dart",
".groovy",
".v",
".sv":
lic, err = executeTemplate(tmpl, data, "", "// ", "")
case ".py", ".sh", ".yaml", ".yml", ".dockerfile", "dockerfile", ".rb", "gemfile", ".tcl", ".tf", ".bzl", ".pl", ".pp", "build", ".build", ".toml":
case ".py",
".sh",
".yaml",
".yml",
".dockerfile",
"dockerfile",
".rb",
"gemfile",
".tcl",
".tf",
".bzl",
".pl",
".pp",
"build",
".build",
".toml",
".awk",
".ex",
".exs",
".jl",
".raku":
lic, err = executeTemplate(tmpl, data, "", "# ", "")
case ".el", ".lisp":
lic, err = executeTemplate(tmpl, data, "", ";; ", "")
Expand All @@ -311,6 +360,8 @@ func licenseHeader(path string, tmpl *template.Template, data licenseData) ([]by
lic, err = executeTemplate(tmpl, data, "{#", "", "#}")
case ".ml", ".mli", ".mll", ".mly":
lic, err = executeTemplate(tmpl, data, "(**", " ", "*)")
case ".vim":
lic, err = executeTemplate(tmpl, data, "", `" `, "")
default:
// handle various cmake files
if base == "cmakelists.txt" || strings.HasSuffix(base, ".cmake.in") || strings.HasSuffix(base, ".cmake") {
Expand Down
66 changes: 61 additions & 5 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,20 +303,72 @@ func TestLicenseHeader(t *testing.T) {
"",
},
{
[]string{"f.c", "f.h", "f.gv", "f.java", "f.scala", "f.kt", "f.kts"},
[]string{"f.c",
"f.h",
"f.gv",
"f.java",
"f.scala",
"f.kt",
"f.kts",
},
"/*\n * HYS\n */\n\n",
},
{
[]string{"f.js", "f.mjs", "f.cjs", "f.jsx", "f.tsx", "f.css", "f.scss", "f.sass", "f.ts"},
[]string{"f.js",
"f.mjs",
"f.cjs",
"f.jsx",
"f.tsx",
"f.css",
"f.scss",
"f.sass",
"f.ts",
},
"/**\n * HYS\n */\n\n",
},
{
[]string{"f.cc", "f.cpp", "f.cs", "f.go", "f.hcl", "f.hh", "f.hpp", "f.m", "f.mm", "f.proto",
"f.rs", "f.swift", "f.dart", "f.groovy", "f.v", "f.sv", "f.php"},
[]string{"f.cc",
"f.cpp",
"f.cs",
"f.go",
"f.hcl",
"f.hh",
"f.hpp",
"f.m",
"f.mm",
"f.proto",
"f.rs",
"f.swift",
"f.dart",
"f.groovy",
"f.v",
"f.sv",
"f.php",
},
"// HYS\n\n",
},
{
[]string{"f.py", "f.sh", "f.yaml", "f.yml", "f.dockerfile", "dockerfile", "f.rb", "gemfile", "f.tcl", "f.tf", "f.bzl", "f.pl", "f.pp", "build"},
[]string{"f.py",
"f.sh",
"f.yaml",
"f.yml",
"f.dockerfile",
"dockerfile",
"f.rb",
"gemfile",
"f.tcl",
"f.tf",
"f.bzl",
"f.pl",
"f.pp",
"build",
"f.build",
"f.awk",
"f.ex",
"f.exs",
"f.jl",
"f.raku",
},
"# HYS\n\n",
},
{
Expand All @@ -339,6 +391,10 @@ func TestLicenseHeader(t *testing.T) {
[]string{"f.ml", "f.mli", "f.mll", "f.mly"},
"(**\n HYS\n*)\n\n",
},
{
[]string{"f.vim"},
"\" HYS\n\n",
},
{
[]string{"cmakelists.txt", "f.cmake", "f.cmake.in"},
"# HYS\n\n",
Expand Down
19 changes: 19 additions & 0 deletions testdata/expected/file.vim
Original file line number Diff line number Diff line change
@@ -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.

if exists("b:my_file")
finish
endif
let s:keepcpo=&cpo
set cpo&vim
5 changes: 5 additions & 0 deletions testdata/initial/file.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if exists("b:my_file")
finish
endif
let s:keepcpo=&cpo
set cpo&vim