Skip to content
Merged

Lint #492

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
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ trim_trailing_whitespace = true

[*.go]
indent_style = tab

[{*.yml,*.yaml}]
indent_size = 2
47 changes: 47 additions & 0 deletions .github/workflows/analysis-scorecard.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: OpenSSF Scorecard

on:
branch_protection_rule:
push:
branches: [master]
schedule:
- cron: "30 0 * * 5"

permissions:
contents: read

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

permissions:
actions: read
contents: read
id-token: write
security-events: write

steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false

- name: Run analysis
uses: ossf/scorecard-action@f49aabe0b5af0936a0987cfb85d86b75731b0186 # v2.4.1
with:
results_file: results.sarif
results_format: sarif
publish_results: true

- name: Upload results as artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: OpenSSF Scorecard results
path: results.sarif
retention-days: 5

- name: Upload results to GitHub Security tab
uses: github/codeql-action/upload-sarif@cdcdbb579706841c47f7063dda365e292e5cad7a # v2.13.4
with:
sarif_file: results.sarif
16 changes: 14 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ jobs:
go-version: "1.24"

- name: Lint
uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
with:
version: v1.64.7
version: v2.0.2

dependency-review:
name: Dependency review
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'

steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Dependency Review
uses: actions/dependency-review-action@3b139cfc5fae8b618d3eae3675e383bb1769c019 # v4.5.0
62 changes: 46 additions & 16 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,48 @@
linters-settings:
gci:
sections:
- standard
- default
- prefix(github.com/spf13/afero)
version: "2"

run:
timeout: 10m

linters:
disable-all: true
enable:
- gci
- gofmt
- gofumpt
- staticcheck

issues:
exclude-dirs:
- gcsfs/internal/stiface
enable:
- govet
- ineffassign
- misspell
- nolintlint
# - revive
- staticcheck
- unused

disable:
- errcheck
# - staticcheck

settings:
misspell:
locale: US
nolintlint:
allow-unused: false # report any unused nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped

exclusions:
paths:
- gcsfs/internal/stiface

formatters:
enable:
- gci
- gofmt
- gofumpt
- goimports
- golines

settings:
gci:
sections:
- standard
- default
- localmodule

exclusions:
paths:
- gcsfs/internal/stiface
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

A FileSystem Abstraction System for Go

[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/spf13/afero/ci.yaml?branch=master&style=flat-square)](https://github.com/spf13/afero/actions?query=workflow%3ACI)
[![Join the chat at https://gitter.im/spf13/afero](https://badges.gitter.im/Dev%20Chat.svg)](https://gitter.im/spf13/afero?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Go Report Card](https://goreportcard.com/badge/github.com/spf13/afero?style=flat-square)](https://goreportcard.com/report/github.com/spf13/afero)
![Go Version](https://img.shields.io/badge/go%20version-%3E=1.23-61CFDD.svg?style=flat-square)
[![PkgGoDev](https://pkg.go.dev/badge/mod/github.com/spf13/afero)](https://pkg.go.dev/mod/github.com/spf13/afero)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/spf13/afero/ci.yaml?style=flat-square)](https://github.com/spf13/afero/actions/workflows/ci.yaml)
[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/mod/github.com/spf13/afero)
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/spf13/afero?style=flat-square&color=61CFDD)
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/spf13/afero/badge?style=flat-square)](https://deps.dev/go/github.com%252Fspf13%252Fafero)

# Overview

Expand Down
27 changes: 23 additions & 4 deletions afero_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ func TestRead0(t *testing.T) {
for _, fs := range Fss {
f := tmpFile(fs)
defer f.Close()
f.WriteString("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.")
f.WriteString(
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
)

var b []byte
// b := make([]byte, 0)
Expand Down Expand Up @@ -103,7 +105,12 @@ func TestOpenFile(t *testing.T) {
contents, _ := io.ReadAll(f)
expectedContents := "initial|append"
if string(contents) != expectedContents {
t.Errorf("%v: appending, expected '%v', got: '%v'", fs.Name(), expectedContents, string(contents))
t.Errorf(
"%v: appending, expected '%v', got: '%v'",
fs.Name(),
expectedContents,
string(contents),
)
}
f.Close()

Expand Down Expand Up @@ -158,7 +165,11 @@ func TestCreate(t *testing.T) {
continue
}
if string(buf) != secondContent {
t.Error(fs.Name(), "Content should be", "\""+secondContent+"\" but is \""+string(buf)+"\"")
t.Error(
fs.Name(),
"Content should be",
"\""+secondContent+"\" but is \""+string(buf)+"\"",
)
f.Close()
continue
}
Expand Down Expand Up @@ -351,7 +362,15 @@ func TestSeek(t *testing.T) {
// http://code.google.com/p/go/issues/detail?id=91
break
}
t.Errorf("#%d: Seek(%v, %v) = %v, %v want %v, nil", i, tt.in, tt.whence, off, err, tt.out)
t.Errorf(
"#%d: Seek(%v, %v) = %v, %v want %v, nil",
i,
tt.in,
tt.whence,
off,
err,
tt.out,
)
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions basepath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,14 @@ func TestNestedBasePaths(t *testing.T) {
t.Errorf("Got error %s", err.Error())
}

if s.BaseFs == level3Fs {
switch s.BaseFs {
case level3Fs:
pathToExist := filepath.Join(ds.Dir3, s.FileName)
if _, err := level2Fs.Stat(pathToExist); err != nil {
t.Errorf("Got error %s (path %s)", err.Error(), pathToExist)
}
} else if s.BaseFs == level2Fs {

case level2Fs:
pathToExist := filepath.Join(ds.Dir2, ds.Dir3, s.FileName)
if _, err := level1Fs.Stat(pathToExist); err != nil {
t.Errorf("Got error %s (path %s)", err.Error(), pathToExist)
Expand Down
9 changes: 7 additions & 2 deletions copyOnWriteFs.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func (u *CopyOnWriteFs) isBaseFile(name string) (bool, error) {
_, err := u.base.Stat(name)
if err != nil {
if oerr, ok := err.(*os.PathError); ok {
if oerr.Err == os.ErrNotExist || oerr.Err == syscall.ENOENT || oerr.Err == syscall.ENOTDIR {
if oerr.Err == os.ErrNotExist || oerr.Err == syscall.ENOENT ||
oerr.Err == syscall.ENOTDIR {
return false, nil
}
}
Expand Down Expand Up @@ -237,7 +238,11 @@ func (u *CopyOnWriteFs) OpenFile(name string, flag int, perm os.FileMode) (File,
return u.layer.OpenFile(name, flag, perm)
}

return nil, &os.PathError{Op: "open", Path: name, Err: syscall.ENOTDIR} // ...or os.ErrNotExist?
return nil, &os.PathError{
Op: "open",
Path: name,
Err: syscall.ENOTDIR,
} // ...or os.ErrNotExist?
}
if b {
return u.base.OpenFile(name, flag, perm)
Expand Down
5 changes: 4 additions & 1 deletion gcsfs/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ func (o *GcsFile) Seek(newOffset int64, whence int) (int64, error) {
if (whence == 0 && newOffset == o.fhOffset) || (whence == 1 && newOffset == 0) {
return o.fhOffset, nil
}
log.Printf("WARNING: Seek behavior triggered, highly inefficent. Offset before seek is at %d\n", o.fhOffset)
log.Printf(
"WARNING: Seek behavior triggered, highly inefficent. Offset before seek is at %d\n",
o.fhOffset,
)

// Fore the reader/writers to be reopened (at correct offset)
err := o.Sync()
Expand Down
12 changes: 9 additions & 3 deletions gcsfs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ func (fs *Fs) Create(name string) (*GcsFile, error) {
}

func (fs *Fs) Mkdir(name string, _ os.FileMode) error {
name = fs.ensureNoLeadingSeparator(fs.ensureTrailingSeparator(fs.normSeparators(ensureNoPrefix(name))))
name = fs.ensureNoLeadingSeparator(
fs.ensureTrailingSeparator(fs.normSeparators(ensureNoPrefix(name))),
)
if err := validateName(name); err != nil {
return err
}
Expand All @@ -181,7 +183,9 @@ func (fs *Fs) Mkdir(name string, _ os.FileMode) error {
}

func (fs *Fs) MkdirAll(path string, perm os.FileMode) error {
path = fs.ensureNoLeadingSeparator(fs.ensureTrailingSeparator(fs.normSeparators(ensureNoPrefix(path))))
path = fs.ensureNoLeadingSeparator(
fs.ensureTrailingSeparator(fs.normSeparators(ensureNoPrefix(path))),
)
if err := validateName(path); err != nil {
return err
}
Expand Down Expand Up @@ -404,7 +408,9 @@ func (fs *Fs) Chmod(_ string, _ os.FileMode) error {
}

func (fs *Fs) Chtimes(_ string, _, _ time.Time) error {
return errors.New("method Chtimes is not implemented. Create, Delete, Updated times are read only fields in GCS and set implicitly")
return errors.New(
"method Chtimes is not implemented. Create, Delete, Updated times are read only fields in GCS and set implicitly",
)
}

func (fs *Fs) Chown(_ string, _, _ int) error {
Expand Down
12 changes: 10 additions & 2 deletions gcsfs/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ func NewGcsFS(ctx context.Context, opts ...option.ClientOption) (afero.Fs, error
}

// NewGcsFSWithSeparator is the same as NewGcsFS, but the files system will use the provided folder separator.
func NewGcsFSWithSeparator(ctx context.Context, folderSeparator string, opts ...option.ClientOption) (afero.Fs, error) {
func NewGcsFSWithSeparator(
ctx context.Context,
folderSeparator string,
opts ...option.ClientOption,
) (afero.Fs, error) {
client, err := storage.NewClient(ctx, opts...)
if err != nil {
return nil, err
Expand All @@ -65,7 +69,11 @@ func NewGcsFSFromClient(ctx context.Context, client *storage.Client) (afero.Fs,
}

// NewGcsFSFromClientWithSeparator is the same as NewGcsFSFromClient, but the file system will use the provided folder separator.
func NewGcsFSFromClientWithSeparator(ctx context.Context, client *storage.Client, folderSeparator string) (afero.Fs, error) {
func NewGcsFSFromClientWithSeparator(
ctx context.Context,
client *storage.Client,
folderSeparator string,
) (afero.Fs, error) {
c := stiface.AdaptClient(client)

return &GcsFs{NewGcsFsWithSeparator(ctx, c, folderSeparator)}, nil
Expand Down
20 changes: 17 additions & 3 deletions gcsfs/gcs_mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ func (o *objectMock) NewWriter(_ context.Context) stiface.Writer {
return &writerMock{name: o.name, fs: o.fs}
}

func (o *objectMock) NewRangeReader(_ context.Context, offset, length int64) (stiface.Reader, error) {
func (o *objectMock) NewRangeReader(
_ context.Context,
offset, length int64,
) (stiface.Reader, error) {
if o.name == "" {
return nil, ErrEmptyObjectName
}
Expand Down Expand Up @@ -126,7 +129,11 @@ func (o *objectMock) Attrs(_ context.Context) (*storage.ObjectAttrs, error) {
return nil, err
}

res := &storage.ObjectAttrs{Name: normSeparators(o.name), Size: info.Size(), Updated: info.ModTime()}
res := &storage.ObjectAttrs{
Name: normSeparators(o.name),
Size: info.Size(),
Updated: info.ModTime(),
}

if info.IsDir() {
// we have to mock it here, because of FileInfo logic
Expand Down Expand Up @@ -240,7 +247,14 @@ func (it *objectItMock) Next() (*storage.ObjectAttrs, error) {
if err != nil {
return nil, err
}
it.infos = append(it.infos, &storage.ObjectAttrs{Name: normSeparators(info.Name()), Size: info.Size(), Updated: info.ModTime()})
it.infos = append(
it.infos,
&storage.ObjectAttrs{
Name: normSeparators(info.Name()),
Size: info.Size(),
Updated: info.ModTime(),
},
)
} else {
var fInfos []os.FileInfo
fInfos, err = it.dir.Readdir(0)
Expand Down
Loading
Loading