This is an automated email from the ASF dual-hosted git repository.
hufeng pushed a commit to branch dubbo3
in repository https://gitbox.apache.org/repos/asf/dubbo-js.git
The following commit(s) were added to refs/heads/dubbo3 by this push:
new 2110805 remove deprecated file operations
new 94e0266 Merge pull request #301 from zhangjin-007/dubbo3
2110805 is described below
commit 2110805822e8e0400a290292df5f5c2dc82f9bb2
Author: 章晋 <[email protected]>
AuthorDate: Thu Oct 27 23:35:14 2022 +0800
remove deprecated file operations
---
lint/lint_license.go | 13 +++++++------
lint/lint_license_test.go | 22 +++++++++++-----------
lint/lint_notice.go | 8 ++++----
lint/lint_notice_test.go | 4 ++--
4 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/lint/lint_license.go b/lint/lint_license.go
index 1bc44be..c85216e 100644
--- a/lint/lint_license.go
+++ b/lint/lint_license.go
@@ -19,7 +19,7 @@ package main
import (
"fmt"
- "io/ioutil"
+ "os"
"path/filepath"
"strings"
"sync"
@@ -46,7 +46,7 @@ func (l *LicenseLinter) lint() ([]string, error) {
wg.Add(1)
go func(f string) {
defer wg.Done()
- b, err := ioutil.ReadFile(f)
+ b, err := os.ReadFile(f)
if err != nil {
panic(err)
}
@@ -96,7 +96,7 @@ func (l *LicenseLinter) fix_file(f string) error {
}
// read file
- b, err := ioutil.ReadFile(f)
+ b, err := os.ReadFile(f)
if err != nil {
panic(err)
}
@@ -107,11 +107,12 @@ func (l *LicenseLinter) fix_file(f string) error {
x := `<?xml version="1.0" encoding="UTF-8"?>`
if ext == ".xml" && strings.Contains(s, x) {
nx := strings.Replace(s, x, x+"\n\n"+license.get(f)+"\n\n", 1)
- ioutil.WriteFile(f, []byte(nx), 0644)
+ if err := os.WriteFile(f, []byte(nx), 0644); err != nil {
+ return err
+ }
} else {
// common
- err = ioutil.WriteFile(f, []byte(fmt.Sprintf("%s\n\n%s",
license.get(f), b)), 0644)
- if err != nil {
+ if err := os.WriteFile(f, []byte(fmt.Sprintf("%s\n\n%s",
license.get(f), b)), 0644); err != nil {
return err
}
}
diff --git a/lint/lint_license_test.go b/lint/lint_license_test.go
index 9188bb4..3d8aea9 100644
--- a/lint/lint_license_test.go
+++ b/lint/lint_license_test.go
@@ -19,7 +19,7 @@ package main
import (
"errors"
- "io/ioutil"
+ "os"
"path/filepath"
"strings"
"testing"
@@ -63,16 +63,16 @@ func TestLicenseLinter_lint(t *testing.T) {
func TestLicenseLinter_fix(t *testing.T) {
// write test data
- ioutil.WriteFile("./__license__/fix.go", []byte("package main"), 0644)
- ioutil.WriteFile("./__license__/fix.js",
[]byte("console.log('hello');"), 0644)
- ioutil.WriteFile("./__license__/fix.ts",
[]byte("console.log('hello');"), 0644)
- ioutil.WriteFile("./__license__/fix.sh", []byte("echo 'hello'"), 0644)
- ioutil.WriteFile("./__license__/fix.yml", []byte(`version: 1`), 0644)
- ioutil.WriteFile("./__license__/Makefile", []byte(``), 0644)
- ioutil.WriteFile("./__license__/.npmignore", []byte(``), 0644)
- ioutil.WriteFile("./__license__/fix.java", []byte(`public class fix
{}`), 0644)
- ioutil.WriteFile("./__license__/fix.xml",
[]byte(`<project></project>`), 0644)
- ioutil.WriteFile("./__license__/fix_head.xml", []byte(`<?xml
version="1.0" encoding="UTF-8"?><project></project>`), 0644)
+ os.WriteFile("./__license__/fix.go", []byte("package main"), 0644)
+ os.WriteFile("./__license__/fix.js", []byte("console.log('hello');"),
0644)
+ os.WriteFile("./__license__/fix.ts", []byte("console.log('hello');"),
0644)
+ os.WriteFile("./__license__/fix.sh", []byte("echo 'hello'"), 0644)
+ os.WriteFile("./__license__/fix.yml", []byte(`version: 1`), 0644)
+ os.WriteFile("./__license__/Makefile", []byte(``), 0644)
+ os.WriteFile("./__license__/.npmignore", []byte(``), 0644)
+ os.WriteFile("./__license__/fix.java", []byte(`public class fix {}`),
0644)
+ os.WriteFile("./__license__/fix.xml", []byte(`<project></project>`),
0644)
+ os.WriteFile("./__license__/fix_head.xml", []byte(`<?xml version="1.0"
encoding="UTF-8"?><project></project>`), 0644)
l := &LicenseLinter{
Dir: "./__license__",
diff --git a/lint/lint_notice.go b/lint/lint_notice.go
index 3019567..f64bc4d 100644
--- a/lint/lint_notice.go
+++ b/lint/lint_notice.go
@@ -19,7 +19,7 @@ package main
import (
"fmt"
- "io/ioutil"
+ "os"
"regexp"
"strconv"
"strings"
@@ -33,7 +33,7 @@ type NoticeLinter struct {
func parseYear(file string) (string, error) {
// read notice file
- b, err := ioutil.ReadFile(file)
+ b, err := os.ReadFile(file)
if err != nil {
return "", fmt.Errorf("read %s error %s", file, err)
}
@@ -78,14 +78,14 @@ func (n *NoticeLinter) fix() error {
}
// read file content
- b, err := ioutil.ReadFile(n.File)
+ b, err := os.ReadFile(n.File)
if err != nil {
return err
}
// replace with current year
s := strings.Replace(string(b), y, strconv.Itoa(time.Now().Year()),
0644)
- if err := ioutil.WriteFile(n.File, []byte(s), 0644); err != nil {
+ if err := os.WriteFile(n.File, []byte(s), 0644); err != nil {
return err
}
diff --git a/lint/lint_notice_test.go b/lint/lint_notice_test.go
index 457999c..839a45f 100644
--- a/lint/lint_notice_test.go
+++ b/lint/lint_notice_test.go
@@ -18,7 +18,7 @@
package main
import (
- "io/ioutil"
+ "os"
"testing"
)
@@ -34,7 +34,7 @@ func TestNoticeLinter_lint(t *testing.T) {
func TestNoticeLinter_fixed(t *testing.T) {
// write test data
- ioutil.WriteFile("./__notice__/NOTICE_1", []byte("Copyright 2018-2021
The Apache Software Foundation"), 0644)
+ os.WriteFile("./__notice__/NOTICE_1", []byte("Copyright 2018-2021 The
Apache Software Foundation"), 0644)
// init notice linter
l := NoticeLinter{