Skip to content
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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright IBM Corp. 2023, 2025
Copyright IBM Corp. 2023, 2026

Mozilla Public License Version 2.0
==================================
Expand Down
2 changes: 1 addition & 1 deletion cmd/headers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright IBM Corp. 2023, 2025
// Copyright IBM Corp. 2023, 2026
// SPDX-License-Identifier: MPL-2.0

package cmd
Expand Down
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright IBM Corp. 2023, 2025
// Copyright IBM Corp. 2023, 2026
// SPDX-License-Identifier: MPL-2.0

package cmd
Expand Down
2 changes: 1 addition & 1 deletion cmd/license.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright IBM Corp. 2023, 2025
// Copyright IBM Corp. 2023, 2026
// SPDX-License-Identifier: MPL-2.0

package cmd
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright IBM Corp. 2023, 2025
// Copyright IBM Corp. 2023, 2026
// SPDX-License-Identifier: MPL-2.0

package config
Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright IBM Corp. 2023, 2025
// Copyright IBM Corp. 2023, 2026
// SPDX-License-Identifier: MPL-2.0

package config
Expand Down
2 changes: 1 addition & 1 deletion github/actions/core.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright IBM Corp. 2023, 2025
// Copyright IBM Corp. 2023, 2026
// SPDX-License-Identifier: MPL-2.0

package actions
Expand Down
2 changes: 1 addition & 1 deletion github/actions/core_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright IBM Corp. 2023, 2025
// Copyright IBM Corp. 2023, 2026
// SPDX-License-Identifier: MPL-2.0

package actions
Expand Down
2 changes: 1 addition & 1 deletion github/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright IBM Corp. 2023, 2025
// Copyright IBM Corp. 2023, 2026
// SPDX-License-Identifier: MPL-2.0

package github
Expand Down
80 changes: 40 additions & 40 deletions licensecheck/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
}{
{
name: "Simple copyright with single year",
line: "// Copyright IBM Corp. 2023",
line: "// Copyright IBM Corp. 2023, 2026",
lineNum: 1,
expectedInfo: &CopyrightInfo{
LineNumber: 1,
OriginalLine: "// Copyright IBM Corp. 2023",
OriginalLine: "// Copyright IBM Corp. 2023, 2026",
Holder: "IBM Corp.",
StartYear: 2023,
EndYear: 2023,
Expand All @@ -41,11 +41,11 @@
},
{
name: "Copyright with year range",
line: "// Copyright IBM Corp. 2022, 2025",
line: "// Copyright IBM Corp. 2023, 2026",
lineNum: 1,
expectedInfo: &CopyrightInfo{
LineNumber: 1,
OriginalLine: "// Copyright IBM Corp. 2022, 2025",
OriginalLine: "// Copyright IBM Corp. 2023, 2026",
Holder: "IBM Corp.",
StartYear: 2022,
EndYear: 2025,
Expand All @@ -69,11 +69,11 @@
},
{
name: "Copyright with trailing text",
line: "/* Copyright IBM Corp. 2023 - All rights reserved */",
line: "/* Copyright IBM Corp. 2023, 2026 - All rights reserved */",
lineNum: 1,
expectedInfo: &CopyrightInfo{
LineNumber: 1,
OriginalLine: "/* Copyright IBM Corp. 2023 - All rights reserved */",
OriginalLine: "/* Copyright IBM Corp. 2023, 2026 - All rights reserved */",
Holder: "IBM Corp.",
StartYear: 2023,
EndYear: 2023,
Expand All @@ -89,11 +89,11 @@
},
{
name: "Copyright without year (holder only)",
line: "// Copyright IBM Corp.",
line: "// Copyright IBM Corp.", 2023, 2026

Check failure on line 92 in licensecheck/update_test.go

View workflow job for this annotation

GitHub Actions / test

missing ',' before newline in composite literal

Check failure on line 92 in licensecheck/update_test.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected newline in composite literal; possibly missing comma or }
lineNum: 1,
expectedInfo: &CopyrightInfo{
LineNumber: 1,
OriginalLine: "// Copyright IBM Corp.",
OriginalLine: "// Copyright IBM Corp.", 2023, 2026
Holder: "IBM Corp.",
StartYear: 0,
EndYear: 0,
Expand All @@ -101,7 +101,7 @@
TrailingText: "",
},
},
{

Check failure on line 104 in licensecheck/update_test.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected {, expected expression
name: "Handlebars indented copyright",
line: " Copyright IBM Corp. 2021, 2025",
lineNum: 2,
Expand All @@ -115,12 +115,12 @@
EndYear: 2025,
Prefix: " ",
TrailingText: "",
},

Check failure on line 118 in licensecheck/update_test.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected comma after top level declaration
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

Check failure on line 123 in licensecheck/update_test.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected {, expected name
filePath := tt.filePath
if filePath == "" {
filePath = "file.go"
Expand All @@ -140,7 +140,7 @@
assert.Equal(t, tt.expectedInfo.EndYear, result.EndYear)
assert.Equal(t, tt.expectedInfo.Prefix, result.Prefix)
assert.Equal(t, tt.expectedInfo.TrailingText, result.TrailingText)
})

Check failure on line 143 in licensecheck/update_test.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected ) after top level declaration
}
}

Expand All @@ -152,37 +152,37 @@
}{
{
name: "Double slash comment",
line: "// Copyright IBM Corp.",
line: "// Copyright IBM Corp.", 2023, 2026

Check failure on line 155 in licensecheck/update_test.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected newline in composite literal; possibly missing comma or }
expectedPrefix: "// ",
},
{
name: "Double slash without space",
line: "//Copyright IBM Corp.",
line: "//Copyright IBM Corp.", 2023, 2026

Check failure on line 160 in licensecheck/update_test.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected newline in composite literal; possibly missing comma or }
expectedPrefix: "//",
},
{
name: "Hash comment",
line: "# Copyright IBM Corp.",
line: "# Copyright IBM Corp.", 2023, 2026

Check failure on line 165 in licensecheck/update_test.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected newline in composite literal; possibly missing comma or }
expectedPrefix: "# ",
},
{
name: "Star comment",
line: "* Copyright IBM Corp.",
line: "* Copyright IBM Corp.", 2023, 2026

Check failure on line 170 in licensecheck/update_test.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected newline in composite literal; possibly missing comma or }
expectedPrefix: "* ",
},
{
name: "Block comment start",
line: "/* Copyright IBM Corp.",
line: "/* Copyright IBM Corp.", 2023, 2026

Check failure on line 175 in licensecheck/update_test.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected newline in composite literal; possibly missing comma or }
expectedPrefix: "/* ",
},
{
name: "Indented comment",
line: " // Copyright IBM Corp.",
line: " // Copyright IBM Corp.", 2023, 2026
expectedPrefix: " // ",
},
{
name: "Tab indented comment",
line: "\t# Copyright IBM Corp.",
line: "\t# Copyright IBM Corp.", 2023, 2026
expectedPrefix: "\t# ",
},
{
Expand Down Expand Up @@ -259,12 +259,12 @@
tempDir := t.TempDir()
testFile := filepath.Join(tempDir, "test.go")

fileContent := `// Copyright IBM Corp. 2020, 2023
fileContent := `// Copyright IBM Corp. 2023, 2026

package main

// Some other comment
// Copyright HashiCorp, Inc. 2019
// Copyright IBM Corp. 2023, 2026

func main() {
// Not a copyright
Expand Down Expand Up @@ -301,7 +301,7 @@
tempDir := t.TempDir()
testFile := filepath.Join(tempDir, "test.go")

fileContent := `// Copyright IBM Corp. 2020, 2023
fileContent := `// Copyright IBM Corp. 2023, 2026
// SPDX-License-Identifier: MPL-2.0

package main
Expand Down Expand Up @@ -351,34 +351,34 @@
}{
{
name: "Update end year when outdated",
initialContent: `// Copyright IBM Corp. 2022, 2023
initialContent: `// Copyright IBM Corp. 2023, 2026
package main
`,
targetHolder: "IBM Corp.",
configYear: 2022,
forceCurrentYear: true,
expectModified: true,
expectedContent: `// Copyright IBM Corp. 2022, ` + string(rune(currentYear/1000+48)) + string(rune((currentYear/100)%10+48)) + string(rune((currentYear/10)%10+48)) + string(rune(currentYear%10+48)) + `
expectedContent: `// Copyright IBM Corp. 2023, 2026+48)) + string(rune((currentYear/100)%10+48)) + string(rune((currentYear/10)%10+48)) + string(rune(currentYear%10+48)) + `
package main
`,
},
{
name: "Update start year when different from config",
initialContent: `// Copyright IBM Corp. 2023
initialContent: `// Copyright IBM Corp. 2023, 2026
package main
`,
targetHolder: "IBM Corp.",
configYear: 2020,
expectModified: true,
// Since we don't have git history in this test and forceCurrentYear is false,
// the end year should NOT update, only the start year.
expectedContent: `// Copyright IBM Corp. 2020, 2023
expectedContent: `// Copyright IBM Corp. 2023, 2026
package main
`,
},
{
name: "No update needed",
initialContent: `// Copyright IBM Corp. ` + string(rune(currentYear/1000+48)) + string(rune((currentYear/100)%10+48)) + string(rune((currentYear/10)%10+48)) + string(rune(currentYear%10+48)) + `
initialContent: `// Copyright IBM Corp. ` + string(rune(currentYear/ 2023, 2026+48)) + string(rune((currentYear/100)%10+48)) + string(rune((currentYear/10)%10+48)) + string(rune(currentYear%10+48)) + `
package main
`,
targetHolder: "IBM Corp.",
Expand Down Expand Up @@ -448,7 +448,7 @@
}{
{
name: "Needs update - outdated end year",
fileContent: `// Copyright IBM Corp. 2022, 2023
fileContent: `// Copyright IBM Corp. 2023, 2026
package main
`,
targetHolder: "IBM Corp.",
Expand All @@ -458,7 +458,7 @@
},
{
name: "Needs update - different start year",
fileContent: `// Copyright IBM Corp. 2023
fileContent: `// Copyright IBM Corp. 2023, 2026
package main
`,
targetHolder: "IBM Corp.",
Expand All @@ -467,7 +467,7 @@
},
{
name: "No update needed - current",
fileContent: `// Copyright IBM Corp. ` + string(rune(currentYear/1000+48)) + string(rune((currentYear/100)%10+48)) + string(rune((currentYear/10)%10+48)) + string(rune(currentYear%10+48)) + `
fileContent: `// Copyright IBM Corp. ` + string(rune(currentYear/ 2023, 2026+48)) + string(rune((currentYear/100)%10+48)) + string(rune((currentYear/10)%10+48)) + string(rune(currentYear%10+48)) + `
package main
`,
targetHolder: "IBM Corp.",
Expand Down Expand Up @@ -504,7 +504,7 @@
tempDir := t.TempDir()
testFile := filepath.Join(tempDir, ".copywrite.hcl")

fileContent := `// Copyright IBM Corp. 2020
fileContent := `// Copyright IBM Corp. 2023, 2026
schema_version = 1
`

Expand All @@ -520,7 +520,7 @@
tempDir := t.TempDir()
testFile := filepath.Join(tempDir, ".copywrite.hcl")

fileContent := `// Copyright IBM Corp. 2020
fileContent := `// Copyright IBM Corp. 2023, 2026
schema_version = 1
`

Expand Down Expand Up @@ -566,7 +566,7 @@
},
{
name: "Regular file",
content: `// Copyright IBM Corp. 2023
content: `// Copyright IBM Corp. 2023, 2026
package main

func main() {}
Expand Down Expand Up @@ -635,7 +635,7 @@
},
{
name: "File with copyright header",
content: "// Copyright IBM Corp. 2023\npackage main\n",
content: "// Copyright IBM Corp. 2023, 2026\npackage main\n",
filePath: "test.go",
expected: false,
},
Expand All @@ -654,7 +654,7 @@
testFile := filepath.Join(tempDir, "generated.go")

fileContent := `// Code generated by protoc-gen-go. DO NOT EDIT.
// Copyright IBM Corp. 2020
// Copyright IBM Corp. 2023, 2026

package main

Expand All @@ -679,7 +679,7 @@
testFile := filepath.Join(tempDir, "generated.go")

fileContent := `// Code generated by protoc-gen-go. DO NOT EDIT.
// Copyright IBM Corp. 2020
// Copyright IBM Corp. 2023, 2026

package main
`
Expand All @@ -700,7 +700,7 @@
}{
{
name: "Valid: Starts with Copyright",
line: "// Copyright IBM Corp. 2020",
line: "// Copyright IBM Corp. 2023, 2026",
expectNil: false,
},
{
Expand All @@ -715,7 +715,7 @@
},
{
name: "Valid: Copyright with leading whitespace after comment",
line: "// Copyright IBM Corp. 2020",
line: "// Copyright IBM Corp. 2023, 2026",
expectNil: false,
},
{
Expand Down Expand Up @@ -767,7 +767,7 @@
}

func TestParseCopyrightLine_InlineComment(t *testing.T) {
line := "var x := 1 // Copyright IBM Corp. 2023"
line := "var x := 1 // Copyright IBM Corp. 2023, 2026"
info := parseCopyrightLine(line, 1, "file.go", false)
require.NotNil(t, info)
assert.Equal(t, "IBM Corp.", info.Holder)
Expand All @@ -783,7 +783,7 @@
testFile := filepath.Join(tempDir, "inline.go")

// code before inline comment should be preserved
initial := "var x := 1 // Copyright IBM Corp. 2022, 2023\n"
initial := "var x := 1 // Copyright IBM Corp. 2023, 2026\n"
err := os.WriteFile(testFile, []byte(initial), 0644)
require.NoError(t, err)

Expand All @@ -793,7 +793,7 @@

content, err := os.ReadFile(testFile)
require.NoError(t, err)
expected := "var x := 1 // Copyright IBM Corp. 2022, " + strconv.Itoa(currentYear) + "\n"
expected := "var x := 1 // Copyright IBM Corp. 2023, 2026, " + strconv.Itoa(currentYear) + "\n"
assert.Equal(t, expected, string(content))
}

Expand Down Expand Up @@ -931,7 +931,7 @@
testFile := filepath.Join(tempDir, "test.go")

// Header has start year 2023 but canonical (config) year is 2020 — normally Condition 1 would update it.
initial := `// Copyright IBM Corp. 2023, 2023
initial := `// Copyright IBM Corp. 2023, 2026
package main
`
err := os.WriteFile(testFile, []byte(initial), 0644)
Expand Down Expand Up @@ -979,7 +979,7 @@
tempDir := t.TempDir()
testFile := filepath.Join(tempDir, "test.go")

initial := `// Copyright IBM Corp.
initial := `// Copyright IBM Corp. 2023, 2026
package main
`
err := os.WriteFile(testFile, []byte(initial), 0644)
Expand All @@ -991,6 +991,6 @@

content, err := os.ReadFile(testFile)
require.NoError(t, err)
expected := fmt.Sprintf("// Copyright IBM Corp. 2021, %d\npackage main\n", currentYear)
expected := fmt.Sprintf("// Copyright IBM Corp. 2023, 2026, %d\npackage main\n", currentYear)
assert.Equal(t, expected, string(content))
}
Loading