Skip to content

Commit

Permalink
Remove ioutil uses, remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnStarich committed Apr 21, 2023
1 parent 3592462 commit 86b56b5
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 33 deletions.
5 changes: 2 additions & 3 deletions cmd/editor/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package main

import (
"io/ioutil"
"os"
"syscall/js"

Expand Down Expand Up @@ -45,7 +44,7 @@ func (j *jsEditor) onEdit(js.Value, []js.Value) interface{} {
if err == nil {
perm = info.Mode()
}
err = ioutil.WriteFile(j.filePath, []byte(contents), perm)
err = os.WriteFile(j.filePath, []byte(contents), perm)
if err != nil {
log.Error("Failed to write file contents: ", err)
}
Expand All @@ -64,7 +63,7 @@ func (j *jsEditor) CurrentFile() string {
}

func (j *jsEditor) ReloadFile() error {
contents, err := ioutil.ReadFile(j.filePath)
contents, err := os.ReadFile(j.filePath)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/editor/ide/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package ide
import (
_ "embed"
"go/format"
"io/ioutil"
"os"
"strings"
"syscall/js"

Expand Down Expand Up @@ -100,7 +100,7 @@ func New(elem *dom.Element, editorBuilder EditorBuilder, consoleBuilder ConsoleB
}

go func() {
src, err := ioutil.ReadFile(path)
src, err := os.ReadFile(path)
if err != nil {
log.Errorf("Failed to read Go file %q: %v", path, err)
return
Expand All @@ -110,7 +110,7 @@ func New(elem *dom.Element, editorBuilder EditorBuilder, consoleBuilder ConsoleB
log.Errorf("Failed to format Go file %q: %v", path, err)
return
}
err = ioutil.WriteFile(path, out, 0)
err = os.WriteFile(path, out, 0)
if err != nil {
log.Errorf("Failed to write Go file %q: %v", path, err)
return
Expand Down
3 changes: 1 addition & 2 deletions cmd/editor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package main

import (
"flag"
"io/ioutil"
"os"
"syscall/js"

Expand Down Expand Up @@ -86,7 +85,7 @@ func main() {
fmt.Println("Hello from Wasm!", datasize.Gigabytes(4))
}
`
err := ioutil.WriteFile("main.go", []byte(mainGoContents), 0600)
err := os.WriteFile("main.go", []byte(mainGoContents), 0600)
if err != nil {
log.Error("Failed to write to main.go: ", err)
return
Expand Down
6 changes: 3 additions & 3 deletions cmd/editor/plaineditor/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package plaineditor

import (
"io/ioutil"
"os"
"syscall/js"

"github.com/hack-pad/hackpad/cmd/editor/dom"
Expand Down Expand Up @@ -51,7 +51,7 @@ func (e *textAreaEditor) CurrentFile() string {
}

func (e *textAreaEditor) ReloadFile() error {
contents, err := ioutil.ReadFile(e.filePath)
contents, err := os.ReadFile(e.filePath)
if err != nil {
return err
}
Expand All @@ -60,7 +60,7 @@ func (e *textAreaEditor) ReloadFile() error {
}

func (e *textAreaEditor) edited(newContents func() string) {
err := ioutil.WriteFile(e.filePath, []byte(newContents()), 0600)
err := os.WriteFile(e.filePath, []byte(newContents()), 0600)
if err != nil {
log.Errorf("Failed to write %s: %s", e.filePath, err.Error())
return
Expand Down
8 changes: 4 additions & 4 deletions cmd/editor/plaineditor/typer.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ func handleKeydown(event js.Value) {
if code == KeyEnter {
// TODO restore cmd+enter triggering run button
// if metaKey {
//preventDefault()
//runPlayground()
//return
//}
// preventDefault()
// runPlayground()
// return
// }

lastNewLine := strings.LastIndexByte(slice(text, 0, selectionStart), '\n')
if lastNewLine != -1 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/sh/main.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package main

import (
"io/ioutil"
"io"
"log"
"os"

"github.com/hack-pad/hush"
)

func main() {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
exitCode := hush.Run()
os.Exit(exitCode)
}
2 changes: 0 additions & 2 deletions internal/fs/pipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ func newPipe(newFID func() FID) (r, w *fileDescriptor) {
}

type pipeChan struct {
unimplementedFile

buf chan byte
done chan struct{}
reader, writer FID
Expand Down
13 changes: 2 additions & 11 deletions internal/interop/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,8 @@ func NewEventTarget() EventTarget {
}

type Event struct {
Target js.Value
Type string
stopPropagation bool
}

func (e Event) StopPropagation() {
e.stopPropagation = true
}

func (e Event) Stopped() bool {
return e.stopPropagation
Target js.Value
Type string
}

type eventTarget struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/interop/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func ProfileJS(this js.Value, args []js.Value) interface{} {
MemoryProfileJS(this, args)
// Re-enable once these profiles actually work in the browser. Currently produces 0 samples.
// TraceProfileJS(this, args)
//StartCPUProfileJS(this, args)
// StartCPUProfileJS(this, args)
}()
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions internal/log/js_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ func logJSValues(kind consoleType, args ...interface{}) int {
}
jsArgs = append(jsArgs, jsArg)
}
console.Call(kind.String(), jsArgs...)
_, _ = console.Call(kind.String(), jsArgs...)
return 0
}

func writeLog(c consoleType, s string) {
console.Call(c.String(), s)
_, _ = console.Call(c.String(), s)
}

0 comments on commit 86b56b5

Please sign in to comment.