diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml new file mode 100644 index 0000000..68fe2d8 --- /dev/null +++ b/.github/workflows/pull.yml @@ -0,0 +1,35 @@ +name: PullLint +on: [ pull_request ] +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - name: Set up Go + uses: actions/setup-go@master + with: + go-version: 1.19 + + - name: Check out code into the Go module directory + uses: actions/checkout@master + + - name: golangci-lint + uses: golangci/golangci-lint-action@master + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: latest + + # Optional: working directory, useful for monorepos + # working-directory: somedir + + # Optional: golangci-lint command line arguments. + # args: --issues-exit-code=0 + + # Optional: show only new issues if it's a pull request. The default value is `false`. + # only-new-issues: true + + # Optional: if set to true then the action don't cache or restore ~/go/pkg. + # skip-pkg-cache: true + + # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. + # skip-build-cache: true diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000..e65e50a --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,33 @@ +name: PushLint +on: [ push ] +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - name: Set up Go + uses: actions/setup-go@master + with: + go-version: 1.19 + + - name: Check out code into the Go module directory + uses: actions/checkout@master + + - name: golangci-lint + uses: golangci/golangci-lint-action@master + with: + version: latest + + - name: Commit back + if: ${{ !github.head_ref }} + continue-on-error: true + run: | + git config --local user.name 'github-actions[bot]' + git config --local user.email '41898282+github-actions[bot]@users.noreply.github.com' + git add --all + git commit -m "🎨 改进代码样式" + + - name: Create Pull Request + if: ${{ !github.head_ref }} + continue-on-error: true + uses: peter-evans/create-pull-request@v4 diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..bda3f4e --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,76 @@ +linters-settings: + errcheck: + ignore: fmt:.* + ignoretests: true + + goimports: + local-prefixes: github.com/fumiama/docxlib + + forbidigo: + # Forbid the following identifiers + forbid: + - ^fmt\.Errorf$ # consider errors.Errorf in github.com/pkg/errors + +linters: + # please, do not use `enable-all`: it's deprecated and will be removed soon. + # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint + disable-all: true + fast: false + enable: + - bodyclose + - depguard + - dogsled + - errcheck + - exportloopref + - exhaustive + #- funlen + #- goconst + - gocritic + #- gocyclo + - gofmt + - goimports + - goprintffuncname + #- gosec + - gosimple + - govet + - ineffassign + #- misspell + - nolintlint + - rowserrcheck + - staticcheck + - stylecheck + - typecheck + - unconvert + - unparam + - unused + - whitespace + - prealloc + - predeclared + - asciicheck + - revive + - forbidigo + - makezero + +run: + # default concurrency is a available CPU number. + # concurrency: 4 # explicitly omit this value to fully utilize available resources. + deadline: 5m + issues-exit-code: 1 + tests: false + skip-dirs: + - order + go: '1.19' + +# output configuration options +output: + format: "colored-line-number" + print-issued-lines: true + print-linter-name: true + uniq-by-line: true + +issues: + # Fix found issues (if it's supported by the linter) + fix: true + exclude-use-default: false + exclude: + - "Error return value of .((os.)?std(out|err)..*|.*Close|.*Seek|.*Flush|os.Remove(All)?|.*print(f|ln)?|os.(Un)?Setenv). is not check" diff --git a/structpara.go b/structpara.go index effe6b4..41936df 100644 --- a/structpara.go +++ b/structpara.go @@ -82,7 +82,7 @@ func (p *Paragraph) MarshalXML(e *xml.Encoder, start xml.StartElement) error { } } for _, c := range p.Children { - e.Encode(c) + err = e.Encode(c) if err != nil { return err } diff --git a/structrun.go b/structrun.go index aab8573..bee1dac 100644 --- a/structrun.go +++ b/structrun.go @@ -71,6 +71,11 @@ func (r *Run) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { } +// WTab is the literal tab +type WTab struct { + XMLName xml.Name `xml:"w:tab,omitempty"` +} + // RunProperties encapsulates visual properties of a run type RunProperties struct { XMLName xml.Name `xml:"w:rPr,omitempty"`