Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(misc): code quality checks with Qodana #367

Merged
merged 7 commits into from
Oct 27, 2024
Merged
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
9 changes: 0 additions & 9 deletions .run/all (go).run.xml

This file was deleted.

7 changes: 0 additions & 7 deletions .run/all (node).run.xml

This file was deleted.

7 changes: 0 additions & 7 deletions .run/all (python).run.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .run/all (rust).run.xml

This file was deleted.

23 changes: 0 additions & 23 deletions .run/console.run.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .run/idp.run.xml

This file was deleted.

22 changes: 0 additions & 22 deletions .run/language.run.xml

This file was deleted.

22 changes: 0 additions & 22 deletions .run/migrations.run.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .run/ui.run.xml

This file was deleted.

6 changes: 3 additions & 3 deletions .run/api.run.xml → api/.run/api.run.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="api" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="voltaserve" />
<working_directory value="$PROJECT_DIR$/api" />
<module name="api" />
<working_directory value="$PROJECT_DIR$" />
<kind value="PACKAGE" />
<package value="github.com/kouprlabs/voltaserve/api" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$/api/main.go" />
<filePath value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
</component>
4 changes: 0 additions & 4 deletions api/client/conversion_client/pipeline_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ func NewPipelineClient() *PipelineClient {
}

const (
PipelinePDF = "pdf"
PipelineOffice = "office"
PipelineImage = "image"
PipelineVideo = "video"
PipelineInsights = "insights"
PipelineMosaic = "mosaic"
)
Expand Down
18 changes: 14 additions & 4 deletions api/infra/file_identifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ package infra
import (
"archive/zip"
"encoding/json"
"io"
"path/filepath"
"strings"

"github.com/kouprlabs/voltaserve/api/config"
"github.com/kouprlabs/voltaserve/api/log"
)

type FileIdentifier struct {
Expand Down Expand Up @@ -207,13 +209,17 @@ type GLTF struct {
} `json:"buffers"`
}

/* Inspects a ZIP archive to see if it contains a glTF 2.0 structure. */
// IsGLTF inspects a ZIP archive to see if it contains a glTF 2.0 structure.
func (fi *FileIdentifier) IsGLTF(path string) (bool, error) {
zipFile, err := zip.OpenReader(path)
if err != nil {
return false, err
}
defer zipFile.Close()
defer func(zipFile *zip.ReadCloser) {
if err := zipFile.Close(); err != nil {
log.GetLogger().Error(err)
}
}(zipFile)
var hasGLTF, hasBin bool
var gltfFile *zip.File
for _, file := range zipFile.File {
Expand All @@ -231,7 +237,11 @@ func (fi *FileIdentifier) IsGLTF(path string) (bool, error) {
if err != nil {
return false, err
}
defer rc.Close()
defer func(rc io.ReadCloser) {
if err := rc.Close(); err != nil {
log.GetLogger().Error(err)
}
}(rc)
var gltf GLTF
if err := json.NewDecoder(rc).Decode(&gltf); err != nil {
return false, err
Expand All @@ -244,7 +254,7 @@ func (fi *FileIdentifier) IsGLTF(path string) (bool, error) {
}
}
}
return hasGLTF && (!hasBin || (hasBin && gltfFile != nil)), nil
return hasGLTF && (!hasBin || gltfFile != nil), nil
}

func (fi *FileIdentifier) GetProcessingLimitMB(path string) int {
Expand Down
1 change: 0 additions & 1 deletion api/model/snapshot_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const (
SnapshotStatusWaiting = "waiting"
SnapshotStatusProcessing = "processing"
SnapshotStatusReady = "ready"
SnapshotStatusError = "error"
)

type Snapshot interface {
Expand Down
2 changes: 0 additions & 2 deletions api/model/task_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ package model
const (
TaskStatusWaiting = "waiting"
TaskStatusRunning = "running"
TaskStatusSuccess = "success"
TaskStatusError = "error"
)

type Task interface {
Expand Down
29 changes: 29 additions & 0 deletions api/qodana.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#-------------------------------------------------------------------------------#
# Qodana analysis is configured by qodana.yaml file #
# https://www.jetbrains.com/help/qodana/qodana-yaml.html #
#-------------------------------------------------------------------------------#
version: "1.0"

#Specify inspection profile for code analysis
profile:
name: qodana.starter

#Enable inspections
#include:
# - name: <SomeEnabledInspectionId>

#Disable inspections
#exclude:
# - name: <SomeDisabledInspectionId>
# paths:
# - <path/where/not/run/inspection>

#Execute shell command before Qodana execution (Applied in CI/CD pipeline)
#bootstrap: sh ./prepare-qodana.sh

#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline)
#plugins:
# - id: <plugin.id> #(plugin id can be found at https://plugins.jetbrains.com)

#Specify Qodana linter for analysis (Applied in CI/CD pipeline)
linter: jetbrains/qodana-go:latest
2 changes: 1 addition & 1 deletion api/router/user_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (r *UserRouter) DownloadPicture(c *fiber.Ctx) error {
return errorpkg.NewUserPictureNotFoundError(nil)
}
c.Set("Content-Type", *mime)
c.Set("Content-Disposition", fmt.Sprintf("filename=\"picture%s\"", ext))
c.Set("Content-Disposition", fmt.Sprintf("filename=\"picture%s\"", *ext))
return c.Send(b)
}

Expand Down
2 changes: 1 addition & 1 deletion api/search/user_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (s *UserSearch) Query(query string, opts infra.QueryOptions) ([]model.User,
if err != nil {
return nil, err
}
res := []model.User{}
res := make([]model.User, 0)
for _, v := range hits {
b, err := json.Marshal(v)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions api/service/file_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ func (svc *FileService) DeleteOne(id string, userID string) error {
for _, treeID := range treeIDs {
if err := svc.fileCache.Delete(treeID); err != nil {
// Here we intentionally don't return an error or panic, we just print the error
fmt.Println(err)
log.GetLogger().Error(err)
}
}
}(treeIDs)
Expand All @@ -1381,7 +1381,7 @@ func (svc *FileService) DeleteOne(id string, userID string) error {
go func(ids []string) {
if err := svc.fileSearch.Delete(treeIDs); err != nil {
// Here we intentionally don't return an error or panic, we just print the error
fmt.Println(err)
log.GetLogger().Error(err)
}
}(treeIDs)

Expand Down
29 changes: 29 additions & 0 deletions console/qodana.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#-------------------------------------------------------------------------------#
# Qodana analysis is configured by qodana.yaml file #
# https://www.jetbrains.com/help/qodana/qodana-yaml.html #
#-------------------------------------------------------------------------------#
version: "1.0"

#Specify inspection profile for code analysis
profile:
name: qodana.starter

#Enable inspections
#include:
# - name: <SomeEnabledInspectionId>

#Disable inspections
#exclude:
# - name: <SomeDisabledInspectionId>
# paths:
# - <path/where/not/run/inspection>

#Execute shell command before Qodana execution (Applied in CI/CD pipeline)
#bootstrap: sh ./prepare-qodana.sh

#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline)
#plugins:
# - id: <plugin.id> #(plugin id can be found at https://plugins.jetbrains.com)

#Specify Qodana linter for analysis (Applied in CI/CD pipeline)
linter: jetbrains/qodana-python:latest
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="conversion" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="voltaserve" />
<working_directory value="$PROJECT_DIR$/conversion" />
<module name="conversion" />
<working_directory value="$PROJECT_DIR$" />
<kind value="PACKAGE" />
<package value="github.com/kouprlabs/voltaserve/conversion" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$/conversion/main.go" />
<filePath value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
</component>
2 changes: 0 additions & 2 deletions conversion/client/api_client/snapshot_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ type SnapshotPatchOptions struct {
}

const (
SnapshotStatusWaiting = "waiting"
SnapshotStatusProcessing = "processing"
SnapshotStatusReady = "ready"
SnapshotStatusError = "error"
Expand All @@ -61,7 +60,6 @@ const (
SnapshotFieldMosaic = "mosaic"
SnapshotFieldThumbnail = "thumbnail"
SnapshotFieldStatus = "status"
SnapshotFieldLanguage = "language"
SnapshotFieldTaskID = "taskId"
)

Expand Down
11 changes: 3 additions & 8 deletions conversion/client/api_client/task_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ type TaskCreateOptions struct {
}

const (
TaskStatusWaiting = "waiting"
TaskStatusRunning = "running"
TaskStatusSuccess = "success"
TaskStatusError = "error"
Expand Down Expand Up @@ -83,13 +82,9 @@ type TaskPatchOptions struct {
}

const (
TaskFieldName = "name"
TaskFieldError = "error"
TaskFieldPercentage = "percentage"
TaskFieldIsIndeterminate = "isIndeterminate"
TaskFieldUserID = "userId"
TaskFieldStatus = "status"
TaskFieldPayload = "payload"
TaskFieldName = "name"
TaskFieldError = "error"
TaskFieldStatus = "status"
)

func (cl *TaskClient) Patch(id string, opts TaskPatchOptions) error {
Expand Down
Loading
Loading