Skip to content
Open
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
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ trim_trailing_whitespace = true
[*.go]
indent_style = tab

[*.{js,jsx,ts,tsx,json,html}]
[*.{js, jsx, ts, tsx, json, html}]
indent_style = space
indent_size = 4

[webapp/package.json]
indent_size = 2

[Makefile,*.mk]
[{Makefile, *.mk}]
Comment on lines -14 to +21
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not be doing these changes. The starter template is wrong. See mattermost/mattermost-plugin-starter-template#236

indent_style = tab

[*.md]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
uses: mattermost/actions-workflows/.github/workflows/plugin-ci.yml@main
secrets: inherit
with:
golang-version: "1.24.6"
golang-version: "1.24"
133 changes: 38 additions & 95 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,122 +1,65 @@
version: 2
version: "2"

run:
timeout: 5m
modules-download-mode: readonly

linters-settings:
goconst:
min-len: 3
min-occurrences: 2
gofmt:
simplify: true
goimports:
local-prefixes: github.com/mattermost/mattermost-plugin-github
govet:
enable-all: true
disable:
- fieldalignment
misspell:
locale: US
revive:

linters:
disable-all: true
default: none
enable:
- bidichk
- bodyclose
- errcheck
- gocritic
- gosec
- govet
- ineffassign
- makezero
- misspell
- modernize
- nakedret
- revive
- staticcheck
- unconvert
- unqueryvet
- unused
- whitespace
settings:
govet:
enable-all: true
disable:
- fieldalignment
revive:
rules:
- name: exported
disabled: true
- name: unused-parameter
disabled: true
unqueryvet:
check-sql-builders: true
exclusions:
rules:
- linters:
- revive
text: var-naming|error-naming|exported|increment-decrement|error-strings|if-return|unused-parameter|blank-imports|empty-block|package-comments
- linters:
- errcheck
text: Error return value
- linters:
- staticcheck
text: SA1019
- linters:
- staticcheck
text: ST1023
- linters:
- staticcheck
text: ST1012
- linters:
- staticcheck
text: ST1005
- linters:
- staticcheck
text: QF1011
- linters:
- staticcheck
text: QF1001
- linters:
- staticcheck
text: QF1003
- linters:
- staticcheck
text: QF1012
- linters:
- staticcheck
text: QT1019
- linters:
- staticcheck
text: QF1008
- linters:
- staticcheck
text: QF1004
- linters:
- staticcheck
text: ST1019
- linters:
- staticcheck
text: QF1006
- linters:
- staticcheck
text: QF1002
- linters:
- staticcheck
text: QF1007
- linters:
- gosec
text: G104
- linters:
- gosec
text: G304
- linters:
- gosec
text: G301
- path: server/plugin/manifest.go
linters:
- unused
- path: server/configuration.go
linters:
- unused
- path: _test\.go
linters:
- bodyclose

formatters:
disable-all: true
enable:
- gofmt
- gofumpt
- goimports

issues:
exclude-rules:
- path: server/manifest.go
linters:
- deadcode
- unused
- varcheck
- path: server/configuration.go
linters:
- unused
- path: _test\.go
linters:
- bodyclose
- goconst
- scopelint # https://github.com/kyoh86/scopelint/issues/4
settings:
gofmt:
simplify: true
rewrite-rules:
- pattern: interface{}
replacement: any
goimports:
local-prefixes:
- github.com/mattermost/mattermost-plugin-github
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.13.1
20.11
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,21 @@ all: check-style test dist
apply:
./build/bin/manifest apply

## Ensures the plugin manifest is valid
.PHONY: manifest-check
manifest-check:
./build/bin/manifest check

## Install go tools
install-go-tools:
@echo Installing go tools
$(GO) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.6.0
$(GO) install gotest.tools/gotestsum@v1.7.0
$(GO) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.8.0
$(GO) install gotest.tools/gotestsum@v1.13.0
$(GO) install github.com/mattermost/mattermost-govet/v2@7d8db289e508999dfcac47b97c9490a0fec12d66

## Runs eslint and golangci-lint
.PHONY: check-style
check-style: apply webapp/node_modules install-go-tools
check-style: manifest-check apply webapp/node_modules install-go-tools
@echo Checking for style guide compliance

ifneq ($(HAS_WEBAPP),)
Expand Down Expand Up @@ -362,7 +367,7 @@ endif
.PHONY: coverage
coverage: apply webapp/node_modules
ifneq ($(HAS_SERVER),)
$(GO) test $(GO_TEST_FLAGS) -coverprofile=server/coverage.txt ./...
$(GO) test $(GO_TEST_FLAGS) -coverprofile=server/coverage.txt ./server/...
$(GO) tool cover -html=server/coverage.txt
endif

Expand Down
32 changes: 16 additions & 16 deletions build/manifest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ package main
import (
"encoding/json"
"fmt"
"net/url"
"os"
"strings"

"github.com/pkg/errors"

"github.com/mattermost/mattermost/server/public/model"
"github.com/pkg/errors"
)

const pluginIDGoFileTemplate = `// This file is automatically generated. Do not modify it manually.
Expand Down Expand Up @@ -91,6 +89,11 @@ func main() {
panic("failed to write manifest to dist directory: " + err.Error())
}

case "check":
if err := manifest.IsValid(); err != nil {
panic("failed to check manifest: " + err.Error())
}

default:
panic("unrecognized command: " + cmd)
}
Expand All @@ -101,11 +104,11 @@ func findManifest() (*model.Manifest, error) {
if err != nil {
return nil, errors.Wrap(err, "failed to find manifest in current working directory")
}
manifestFile, err := os.Open(manifestFilePath)
manifestFile, err := os.Open(manifestFilePath) //nolint:gosec
if err != nil {
return nil, errors.Wrapf(err, "failed to open %s", manifestFilePath)
}
defer manifestFile.Close()
defer func() { _ = manifestFile.Close() }()

// Re-decode the manifest, disallowing unknown fields. When we write the manifest back out,
// we don't want to accidentally clobber anything we won't preserve.
Expand All @@ -120,8 +123,8 @@ func findManifest() (*model.Manifest, error) {
// commit, and use the first version we find (to prevent causing errors)
if manifest.Version == "" {
var version string
tags := strings.Fields(BuildTagCurrent)
for _, t := range tags {
tags := strings.FieldsSeq(BuildTagCurrent)
for t := range tags {
if strings.HasPrefix(t, "v") {
version = t
break
Expand All @@ -139,10 +142,7 @@ func findManifest() (*model.Manifest, error) {

// If no release notes specified, generate one from the latest tag, if present.
if manifest.ReleaseNotesURL == "" && BuildTagLatest != "" {
manifest.ReleaseNotesURL, err = url.JoinPath(manifest.HomepageURL, "releases", "tag", BuildTagLatest)
if err != nil {
return nil, errors.Wrap(err, "failed to generate release notes URL")
}
manifest.ReleaseNotesURL = manifest.HomepageURL + "releases/tag/" + BuildTagLatest
Comment on lines -142 to +145
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a bug in the starter template. Submitted mattermost/mattermost-plugin-starter-template#236

}

return &manifest, nil
Expand Down Expand Up @@ -171,8 +171,8 @@ func applyManifest(manifest *model.Manifest) error {
// write generated code to file by using Go file template.
if err := os.WriteFile(
"server/plugin/manifest.go",
[]byte(fmt.Sprintf(pluginIDGoFileTemplate, manifestStr)),
0600,
fmt.Appendf(nil, pluginIDGoFileTemplate, manifestStr),
0o600,
); err != nil {
return errors.Wrap(err, "failed to write server/plugin/manifest.go")
}
Expand All @@ -194,8 +194,8 @@ func applyManifest(manifest *model.Manifest) error {
// write generated code to file by using JS file template.
if err := os.WriteFile(
"webapp/src/manifest.ts",
[]byte(fmt.Sprintf(pluginIDJSFileTemplate, manifestStr)),
0600,
fmt.Appendf(nil, pluginIDJSFileTemplate, manifestStr),
0o600,
); err != nil {
return errors.Wrap(err, "failed to open webapp/src/manifest.ts")
}
Expand All @@ -211,7 +211,7 @@ func distManifest(manifest *model.Manifest) error {
return err
}

if err := os.WriteFile(fmt.Sprintf("dist/%s/plugin.json", manifest.Id), manifestBytes, 0600); err != nil {
if err := os.WriteFile(fmt.Sprintf("dist/%s/plugin.json", manifest.Id), manifestBytes, 0o600); err != nil {
return errors.Wrap(err, "failed to write plugin.json")
}

Expand Down
2 changes: 1 addition & 1 deletion build/pluginctl/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func checkJSONLogsSetting(ctx context.Context, client *model.Client4) error {
return fmt.Errorf("failed to fetch config: %w", err)
}
if cfg.LogSettings.FileJson == nil || !*cfg.LogSettings.FileJson {
return errors.New("JSON output for file logs are disabled. Please enable LogSettings.FileJson via the configuration in Mattermost.") //nolint:revive,stylecheck
return errors.New("JSON output for file logs are disabled. Please enable LogSettings.FileJson via the configuration in Mattermost.") //nolint:staticcheck,revive
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions build/pluginctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ func getUnixClient(socketPath string) (*model.Client4, bool) {
// deploy attempts to upload and enable a plugin via the Client4 API.
// It will fail if plugin uploads are disabled.
func deploy(ctx context.Context, client *model.Client4, pluginID, bundlePath string) error {
pluginBundle, err := os.Open(bundlePath)
pluginBundle, err := os.Open(bundlePath) //nolint:gosec // bundlePath is validated input
if err != nil {
return fmt.Errorf("failed to open %s: %w", bundlePath, err)
}
defer pluginBundle.Close()
defer pluginBundle.Close() //nolint:errcheck

log.Print("Uploading plugin via API.")
_, _, err = client.UploadPluginForced(ctx, pluginBundle)
Expand Down
2 changes: 0 additions & 2 deletions build/setup.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
GO_BUILD_FLAGS ?=

# Ensure that go is installed. Note that this is independent of whether or not a server is being
# built, since the build script itself uses go.
ifeq ($(GO),)
Expand Down
4 changes: 2 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (c *Client) GetConfiguration() (*plugin.Configuration, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()
defer resp.Body.Close() //nolint:errcheck

respBody, err := io.ReadAll(resp.Body)
if err != nil {
Expand Down Expand Up @@ -111,7 +111,7 @@ func (c *Client) GetToken(userID string) (*oauth2.Token, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()
defer resp.Body.Close() //nolint:errcheck

respBody, err := io.ReadAll(resp.Body)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestRoundTripper(t *testing.T) {

resp, err := roundTripper.RoundTrip(req)
require.NoError(t, err)
defer resp.Body.Close()
defer resp.Body.Close() //nolint:errcheck
require.Equal(t, http.StatusOK, resp.StatusCode)
})

Expand All @@ -46,7 +46,7 @@ func TestRoundTripper(t *testing.T) {

resp, err := roundTripper.RoundTrip(req)
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
defer resp.Body.Close() //nolint:errcheck
}
require.Nil(t, resp)
require.Error(t, err)
Expand Down
Loading
Loading