go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/copyright/constants.go (about) 1 /* 2 3 Copyright (c) 2023 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package copyright 9 10 import ( 11 "errors" 12 "regexp" 13 ) 14 15 // DefaultCopyrightHolder is the default copyright holder to inject into the notice template. 16 // 17 // As of writing, it's blank. You'll want to provide it! 18 const DefaultCopyrightHolder = "" 19 20 // DefaultOpenSourceLicense is the default open source license. 21 const DefaultOpenSourceLicense = "MIT" 22 23 // DefaultNoticeBodyTemplate is the default notice body template. 24 const DefaultNoticeTemplate = `Copyright (c) {{ .Year }} - Present. {{ .CopyrightHolder }}. All rights reserved. 25 {{- if .Restrictions }} 26 {{ .Restrictions }} 27 {{- end -}}` 28 29 // DefaultRestrictionsOpenSource are the default open source restrictions. 30 const DefaultRestrictionsTemplate = `Use of this source code is governed by a {{ .License }} license that can be found in the LICENSE file at the root of the repository.` 31 32 // DefaultRestrictionsTemplateInternal are the default copyright restrictions to inject into the notice template. 33 const DefaultRestrictionsTemplateInternal = "{{ if .CopyrightHolder }}{{ .CopyrightHolder }} {{ end }}Confidential - Restricted" 34 35 const ( 36 TemplateFieldYear = "Year" 37 TemplateFieldCopyrightHolder = "CopyrightHolder" 38 TemplateFieldLicense = "License" 39 TemplateFieldRestrictions = "Restrictions" 40 ) 41 42 // Extension is a string enum for known extensions. 43 type Extension string 44 45 // Extensions 46 const ( 47 ExtensionUnknown Extension = "" 48 ExtensionCSS Extension = ".css" 49 ExtensionGo Extension = ".go" 50 ExtensionHTML Extension = ".html" 51 ExtensionJS Extension = ".js" 52 ExtensionJSX Extension = ".jsx" 53 ExtensionPy Extension = ".py" 54 ExtensionSASS Extension = ".sass" 55 ExtensionSCSS Extension = ".scss" 56 ExtensionTS Extension = ".ts" 57 ExtensionTSX Extension = ".tsx" 58 ExtensionYAML Extension = ".yaml" 59 ExtensionYML Extension = ".yml" 60 ExtensionSQL Extension = ".sql" 61 ExtensionProto Extension = ".proto" 62 ) 63 64 var ( 65 // KnownExtensions is a list of all the known extensions. 66 KnownExtensions = []Extension{ 67 ExtensionCSS, 68 ExtensionGo, 69 ExtensionHTML, 70 ExtensionJS, 71 ExtensionJSX, 72 ExtensionPy, 73 ExtensionSCSS, 74 ExtensionSASS, 75 ExtensionTS, 76 ExtensionTSX, 77 ExtensionYAML, 78 ExtensionYML, 79 ExtensionSQL, 80 ExtensionProto, 81 } 82 83 // DefaultExtensionInjectionTemplates is a mapping between file extension (including the prefix dot) to the injection templates. 84 DefaultExtensionInjectionTemplates = map[Extension]string{ 85 ExtensionCSS: cssInjectionTemplate, 86 ExtensionGo: goInjectionTemplate, 87 ExtensionHTML: htmlInjectionTemplate, 88 ExtensionJS: jsInjectionTemplate, 89 ExtensionJSX: jsInjectionTemplate, 90 ExtensionPy: pythonInjectionTemplate, 91 ExtensionSASS: sassInjectionTemplate, 92 ExtensionSCSS: scssInjectionTemplate, 93 ExtensionTS: tsInjectionTemplate, 94 ExtensionTSX: tsInjectionTemplate, 95 ExtensionYAML: yamlInjectionTemplate, 96 ExtensionYML: yamlInjectionTemplate, 97 ExtensionSQL: sqlInjectionTemplate, 98 ExtensionProto: protoInjectionTemplate, 99 } 100 101 // DefaultExcludes is the default excluded directories. 102 DefaultExcludes = []string{ 103 ".git/*", 104 ".github/*", 105 "*/_config", 106 "*/_config/*", 107 "*/dist/*", 108 "*/node_modules/*", 109 "*/testdata", 110 "*/testdata/*", 111 "*/vendor/*", 112 "node_modules/*", 113 "protogen/*", 114 "*.pb.go", 115 "vendor/*", 116 "venv/*", 117 "*/venv/*", 118 ".vscode/*", 119 "*/.vscode/*", 120 "*/_nextjs/*", 121 "*/_nextjs", 122 "*/_public/*", 123 "*/_public", 124 "*/_dist/*", 125 "*/_dist", 126 } 127 128 // DefaultIncludes is the default included files list. 129 DefaultIncludes = []string{ 130 "*.css", 131 "*.go", 132 "*.html", 133 "*.js", 134 "*.jsx", 135 "*.py", 136 "*.sass", 137 "*.scss", 138 "*.ts", 139 "*.tsx", 140 "*.yaml", 141 "*.yml", 142 "*.sql", 143 "*.proto", 144 } 145 ) 146 147 // Error Strings 148 var ( 149 ErrVerifyFormat = "%s: copyright header missing or invalid" 150 ) 151 152 // Error sentinels 153 var ( 154 ErrWalkSkip = errors.New("walk skip; we should not process this file or path") 155 ErrFailure = errors.New("failure; one or more steps failed") 156 ) 157 158 const ( 159 // goNoticeTemplate is the notice template specific to go files 160 // note: it _must_ end in two newlines to prevent linting / compiler failures. 161 goInjectionTemplate = `/* 162 163 {{ .Notice }} 164 165 */ 166 167 ` 168 169 yamlInjectionTemplate = `# 170 {{ .Notice | prefix "# " }} 171 # 172 ` 173 174 htmlInjectionTemplate = `<!-- 175 {{ .Notice }} 176 --> 177 ` 178 179 jsInjectionTemplate = `/** 180 {{ .Notice | prefix " * " }} 181 */ 182 ` 183 184 tsInjectionTemplate = `/** 185 {{ .Notice | prefix " * " }} 186 */ 187 ` 188 189 cssInjectionTemplate = `/* 190 {{ .Notice | prefix " * " }} 191 */ 192 ` 193 194 scssInjectionTemplate = `/* 195 {{ .Notice | prefix " * " }} 196 */ 197 ` 198 199 sassInjectionTemplate = `/* 200 {{ .Notice | prefix " * " }} 201 */ 202 ` 203 204 pythonInjectionTemplate = `# 205 {{ .Notice | prefix "# " }} 206 # 207 208 ` 209 210 sqlInjectionTemplate = `-- 211 {{ .Notice | prefix "-- " }} 212 -- 213 ` 214 215 protoInjectionTemplate = `// 216 {{ .Notice | prefix "// " }} 217 // 218 219 ` 220 ) 221 222 const ( 223 goBuildTagExpr = `^(\/\/(go:build| \+build).*\n)+\n` 224 tsReferenceTagsExpr = `^(\/\/\/ \<reference path=\"(.*)\" \/\>\n)+` 225 yearExpr = `([0-9]{4,}?)` 226 shebangExpr = `(?s)^(\s*)#!([^\n]+)\n` 227 ) 228 229 var ( 230 goBuildTagMatch = regexp.MustCompile(goBuildTagExpr) 231 tsReferenceTagsMatch = regexp.MustCompile(tsReferenceTagsExpr) 232 yearMatch = regexp.MustCompile(yearExpr) 233 shebangMatch = regexp.MustCompile(shebangExpr) 234 )