Skip to content

Commit c764e51

Browse files
committed
fix: lint
Signed-off-by: ashing <[email protected]>
1 parent e06480b commit c764e51

File tree

8 files changed

+308
-3
lines changed

8 files changed

+308
-3
lines changed

go.sum

Lines changed: 202 additions & 0 deletions
Large diffs are not rendered by default.

scripts/go-copyright/main.go

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package main
1414

1515
import (
16+
"flag"
1617
"fmt"
1718
"go/ast"
1819
"go/parser"
@@ -43,6 +44,7 @@ var (
4344
excludes = []string{
4445
"test/conformance",
4546
}
47+
addFlag = flag.Bool("add", false, "automatically add copyright headers to files that are missing them")
4648
)
4749

4850
func checkCopyright() ([]string, error) {
@@ -136,15 +138,44 @@ func isGenerated(fset *token.FileSet, file *ast.File) bool {
136138
return false
137139
}
138140

141+
func addCopyright(filename string) error {
142+
content, err := os.ReadFile(filename)
143+
if err != nil {
144+
return err
145+
}
146+
147+
// Prepare the copyright header with proper comment formatting
148+
header := "// " + strings.ReplaceAll(copyright, "\n", "\n// ") + "\n\n"
149+
150+
// Add the header to the beginning of the file
151+
newContent := header + string(content)
152+
153+
return os.WriteFile(filename, []byte(newContent), 0644)
154+
}
155+
139156
func main() {
157+
flag.Parse()
158+
140159
files, err := checkCopyright()
141160
if err != nil {
142161
log.Fatal(err)
143162
}
144163
if len(files) > 0 {
145-
fmt.Printf("[ERROR] invalid copyright files (%d):\n", len(files))
146-
fmt.Println(strings.Join(files, "\n"))
147-
os.Exit(1)
164+
if *addFlag {
165+
fmt.Printf("Adding copyright headers to %d files:\n", len(files))
166+
for _, file := range files {
167+
fmt.Printf(" %s\n", file)
168+
if err := addCopyright(file); err != nil {
169+
log.Printf("Failed to add copyright to %s: %v", file, err)
170+
continue
171+
}
172+
}
173+
fmt.Printf("Successfully added copyright headers to %d files!\n", len(files))
174+
} else {
175+
fmt.Printf("[ERROR] invalid copyright files (%d):\n", len(files))
176+
fmt.Println(strings.Join(files, "\n"))
177+
os.Exit(1)
178+
}
148179
return
149180
}
150181
fmt.Println("Good files !")

test/e2e/framework/api7_framework.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
113
package framework
214

315
import (

test/e2e/framework/apisix_consts.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
113
package framework
214

315
import (

test/e2e/scaffold/api7_deployer.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
113
package scaffold
214

315
import (

test/e2e/scaffold/apisix_deployer.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
113
package scaffold
214

315
import (

test/e2e/scaffold/deployer.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
113
package scaffold
214

315
// Deployer defines the interface for deploying data plane components

test/e2e/scaffold/utils.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
113
package scaffold
214

315
import (

0 commit comments

Comments
 (0)