aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-01-11 21:27:58 +0700
committerShulhan <ms@kilabit.info>2026-01-11 21:36:20 +0700
commit069380e6b34d36ca2ace9c0d7e2ec4efdc4a2736 (patch)
tree2c0f0c75021eaa3a7e61fe2553ae2040ccd3f946
parente5daeb13cbd446a4fe882fb722d8d3359dd9bef9 (diff)
downloadspdxconv-069380e6b34d36ca2ace9c0d7e2ec4efdc4a2736.tar.xz
all: exclude file that contains both SPDX license and copyright text
If the file already contains SPDX-License-Identifier and SPDX-FileCopyrightText, in any order, ignore it from being included during scan.
-rw-r--r--report.go3
-rw-r--r--spdxconv_test.go1
-rw-r--r--testdata/Apply_test.txt22
-rw-r--r--testdata/scan/with_spdx.go4
4 files changed, 26 insertions, 4 deletions
diff --git a/report.go b/report.go
index 6ec3f7f..55e18d9 100644
--- a/report.go
+++ b/report.go
@@ -128,6 +128,9 @@ func (rep *report) scan(conv *SPDXConv, listFile []string) (err error) {
rep.listUnknown = append(rep.listUnknown, f)
continue
}
+ if f.licenseID == valExist && f.copyrightText == valExist {
+ continue
+ }
rep.listRegular = append(rep.listRegular, f)
}
return nil
diff --git a/spdxconv_test.go b/spdxconv_test.go
index b58f7a0..0e3d635 100644
--- a/spdxconv_test.go
+++ b/spdxconv_test.go
@@ -45,7 +45,6 @@ func TestScan(t *testing.T) {
exp := `//spdxconv:version:v1
//spdxconv:header:path,license_id,idx_license_id,year,copyright_id,idx_copyright_id
//spdxconv:regular
-.gitignore,exist,0,unknown,exist,1,# ,
test.go,match,1,unknown,match,0,// ,
test.html,default,0,unknown,default,0,<!-- ," -->"
test.sh,match,1,unknown,match,0,# ,
diff --git a/testdata/Apply_test.txt b/testdata/Apply_test.txt
index ba51ede..3ee49f4 100644
--- a/testdata/Apply_test.txt
+++ b/testdata/Apply_test.txt
@@ -59,17 +59,33 @@ pattern = "^(//+|#+)\\s+Copyright\\s+(?<year>\\d{4}),?\\s+(?<author>.*)\\s+<*(?<
2
3
->>> with_no_order.txt
-// SPDX-FileCopyrightText: 2026 M. Shulhan <ms@kilabit.info>
+>>> with_spdx.txt
+// SPDX-License-Identifier: BSD-3-Clause
+// SPDX-FileCopyrightText: 2018 Shulhan <ms@kilabit.info>
+
+1
+2
+3
+
+<<< with_spdx.txt
// SPDX-License-Identifier: BSD-3-Clause
+// SPDX-FileCopyrightText: 2018 Shulhan <ms@kilabit.info>
1
2
3
-<<< with_no_order.txt
+>>> with_spdx_no_order.txt
+// SPDX-FileCopyrightText: 2026 M. Shulhan <ms@kilabit.info>
// SPDX-License-Identifier: BSD-3-Clause
+
+1
+2
+3
+
+<<< with_spdx_no_order.txt
// SPDX-FileCopyrightText: 2026 M. Shulhan <ms@kilabit.info>
+// SPDX-License-Identifier: BSD-3-Clause
1
2
diff --git a/testdata/scan/with_spdx.go b/testdata/scan/with_spdx.go
new file mode 100644
index 0000000..c30ff8f
--- /dev/null
+++ b/testdata/scan/with_spdx.go
@@ -0,0 +1,4 @@
+// SPDX-License-Identifier: GPL-3.0-only
+// SPDX-FileCopyrightText: 2026 M. Shulhan <ms@kilabit.info>
+
+package spdxconv