diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9f0c8e9 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,27 @@ +root = true + +[*] +charset = utf-8 +end_of_line = LF +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = space +indent_size = 4 + +[Makefile] +indent_style = tab + +[*.md] +trim_trailing_whitespace = false + +[*.go] +indent_style = tab + +[*.yml] +indent_size = 2 + +[*.yaml] +indent_size = 2 + +[*.yml.dist] +indent_size = 2 diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..09d032b --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,16 @@ +version: 2 +updates: +- package-ecosystem: gomod + directory: "/" + schedule: + interval: weekly + time: "04:00" + open-pull-requests-limit: 10 + assignees: + - euskadi31 +- package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: weekly + assignees: + - euskadi31 diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..06af1bb --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,70 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ master ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ master ] + schedule: + - cron: '20 20 * * 6' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'go' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://git.io/codeql-language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v3 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..98ffab5 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,150 @@ +name: Go + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + + - name: Set up Go 1.x + uses: actions/setup-go@v5 + with: + go-version: "1.x" + id: go + + - name: Build + run: go build -race -v ./... + + - name: Test + run: go test -race -cover -coverprofile ./coverage.out ./... + + - name: Coverage + id: coverage + run: | + go tool cover -func ./coverage.out | tee -a coverage.txt + echo "COVERAGE_CONTENT<> $GITHUB_ENV + cat coverage.txt >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + + - uses: actions/github-script@v4 + if: github.event_name == 'pull_request' + continue-on-error: true + env: + COVERAGE_CONTENT: "${{ env.COVERAGE_CONTENT }}" + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const output = `Code Coverage\n + \`\`\`\n + ${process.env.COVERAGE_CONTENT} + \`\`\` + + *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Workflow: \`${{ github.workflow }}\`*`; + + const response = await github.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + }); + + var comments = response.data; + + console.log(comments); + + if (comments.length > 0) { + comments = comments.filter(comment => comment.body.includes('Code Coverage') && comment.user.type === 'Bot'); + } + + if (comments.length > 0) { + const comment = comments.shift(); + + github.issues.updateComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: comment.id, + body: output + }) + } else { + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: output + }) + } + + - name: Benchmark + id: benchmark + run: | + go test -benchmem -bench . | tee -a benchmark.txt + echo "BENCHMARK_CONTENT<> $GITHUB_ENV + cat benchmark.txt >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV + + - uses: actions/github-script@v4 + if: github.event_name == 'pull_request' + continue-on-error: true + env: + BENCHMARK_CONTENT: "${{ env.BENCHMARK_CONTENT }}" + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const output = `Benchmark\n + \`\`\`\n + ${process.env.BENCHMARK_CONTENT} + \`\`\` + + *Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Workflow: \`${{ github.workflow }}\`*`; + + const response = await github.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + }); + + var comments = response.data; + + console.log(comments); + + if (comments.length > 0) { + comments = comments.filter(comment => comment.body.includes('Benchmark') && comment.user.type === 'Bot'); + } + + if (comments.length > 0) { + const comment = comments.shift(); + + github.issues.updateComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: comment.id, + body: output + }) + } else { + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: output + }) + } + + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v6.1.1 + with: + version: v1.62.0 + skip-cache: true + + - name: Coveralls + uses: shogo82148/actions-goveralls@v1 + with: + path-to-profile: coverage.out diff --git a/.gitignore b/.gitignore index d163863..ba8a5b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,9 @@ -build/ \ No newline at end of file +.DS_Store +*.out + +.vscode/ +vendor/ +coverage/ +build/ + +*.swp diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..3288666 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,95 @@ +run: + concurrency: 4 + timeout: 1m + issues-exit-code: 1 + tests: false + +output: + formats: + - format: colored-line-number + print-issued-lines: true + print-linter-name: true + +issues: + exclude-use-default: true + exclude-case-sensitive: false + exclude-dirs-use-default: true + max-issues-per-linter: 50 + exclude-generated: strict + exclude-files: + - .*_mock\.go + - mock_.*\.go + - .*/pkg/mod/.*$ + - .*/go/src/.*\.go + +linters-settings: + errcheck: + check-type-assertions: false + check-blank: false + govet: + disable: + - shadow + revive: + ignore-generated-header: true + severity: warning + gofmt: + simplify: true + gocyclo: + min-complexity: 18 + dupl: + threshold: 99 + goconst: + min-len: 3 + min-occurrences: 2 + depguard: + rules: + main: + allow: + - $all + + misspell: + locale: US + ignore-words: + - cancelled + goimports: + local-prefixes: go.opentelemetry.io + + +linters: + disable-all: true + enable: + - errcheck + - goconst + - gocyclo + - gofmt + - revive + - govet + - ineffassign + - misspell + - typecheck + - unconvert + - gosimple + - staticcheck + - unused + - asciicheck + - bodyclose + - dogsled + - durationcheck + - errorlint + - exhaustive + - forbidigo + - forcetypeassert + - gocritic + - godot + - gosec + - nestif + - nilerr + - nlreturn + - noctx + - prealloc + - predeclared + - sqlclosecheck + - whitespace + - wrapcheck + - wsl + fast: false diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c9baeeb --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +.PHONY: all +all: test + +.PHONY: clean +clean: + @go clean -i ./... + +.PHONY: test +test: + @go test -race -cover -coverprofile ./coverage.out ./... + +.PHONY: cover +cover: test + @echo "" + @go tool cover -func ./coverage.out + +.PHONY: bench +bench: + @go test -benchmem -bench=. ./... + diff --git a/README.md b/README.md new file mode 100644 index 0000000..3dfb020 --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# Stopwords for Golang ![Last release](https://img.shields.io/github/release/golang-nlp/stopwords.svg) + +[![Go Report Card](https://goreportcard.com/badge/github.com/golang-nlp/stopwords)](https://goreportcard.com/report/github.com/golang-nlp/stopwords) + +| Branch | Status | Coverage | +| ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | +| master | [![Go](https://github.com/golang-nlp/stopwords/actions/workflows/go.yml/badge.svg)](https://github.com/golang-nlp/stopwords/actions/workflows/go.yml) | [![Coveralls](https://img.shields.io/coveralls/golang-nlp/stopwords/master.svg)](https://coveralls.io/github/golang-nlp/stopwords?branch=master) | + +```sh +go get -u github.com/golang-nlp/stopwords +``` + +```go +import ( + "fmt" + + "github.com/golang-nlp/stopwords" +) + +func main() { + fmt.Print(stopwords.IsStopWord("fr", "avec")) // true +} + +``` + +## License + +stopwords is licensed under [the MIT license](LICENSE.md). diff --git a/cmd/generate-data/main.go b/cmd/generate-data/main.go index 5769bbb..e6c3147 100644 --- a/cmd/generate-data/main.go +++ b/cmd/generate-data/main.go @@ -10,6 +10,7 @@ import ( "github.com/dave/jennifer/jen" ) +// nolint:forbidigo func main() { src := os.Args[1] @@ -60,7 +61,7 @@ func main() { func readWords(file string) ([]string, error) { f, err := os.Open(file) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to open file: %w", err) } defer f.Close() @@ -81,7 +82,7 @@ func readWords(file string) ([]string, error) { exists[word] = struct{}{} } - return words, scanner.Err() + return words, scanner.Err() // nolint:wrapcheck } func generateLangFile(lang string, words []string) (*jen.File, error) {