nikoksr/proji

View on GitHub

Showing 37 of 37 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

func postRunPlugins(pluginsRootPath string, plugins []*domain.Plugin) error {
    for _, plugin := range plugins {
        if plugin.ExecNumber <= 0 {
            continue
        }
Severity: Minor
Found in pkg/project/service/create.go and 1 other location - About 40 mins to fix
pkg/project/service/create.go on lines 66..80

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 111.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Method Service.getRepository has 6 return statements (exceeds 4 allowed).
Open

func (s Service) getRepository(url *url.URL) (*repo, error) {
    if url.Hostname() != "github.com" {
        return nil, fmt.Errorf("invalid host %s", url.Hostname())
    }

Severity: Major
Found in pkg/remote/github/github.go - About 40 mins to fix

    Method packageStore.RemovePackage has 6 return statements (exceeds 4 allowed).
    Open

    func (ps packageStore) RemovePackage(label string) error {
        tx := ps.db.Begin()
        defer func() {
            if r := recover(); r != nil {
                tx.Rollback()
    Severity: Major
    Found in pkg/package/store/store.go - About 40 mins to fix

      Method repo.setBranch has 6 return statements (exceeds 4 allowed).
      Open

      func (r *repo) setBranch(ctx context.Context, isAuthenticated bool) error {
          // Skip if a branch was already set
          if r.branch != "" {
              return nil
          }
      Severity: Major
      Found in pkg/remote/github/repo.go - About 40 mins to fix

        Method projectService.CreateProject has 6 return statements (exceeds 4 allowed).
        Open

        func (ps projectService) CreateProject(configRootPath string, project *domain.Project) (err error) {
            // Create the root folder of the project.
            err = createProjectRootFolder(project.Path)
            if err != nil {
                return errors.Wrap(err, "create base folder")
        Severity: Major
        Found in pkg/project/service/create.go - About 40 mins to fix

          Function newProjectSetPathCommand has 5 return statements (exceeds 4 allowed).
          Open

          func newProjectSetPathCommand() *projectSetPath {
              cmd := &cobra.Command{
                  Use:                   "path OLD-PATH NEW-PATH",
                  Short:                 "Set a new path",
                  Aliases:               []string{"p"},
          Severity: Major
          Found in cmd/projectSetPath.go - About 35 mins to fix

            Method packageService.ImportPackagesFromCollection has 5 return statements (exceeds 4 allowed).
            Open

            func (ps packageService) ImportPackagesFromCollection(url *url.URL, exclude *regexp.Regexp) ([]*domain.Package, error) {
                // Get code repo
                codeRepo, err := remote.NewCodeRepository(url, ps.authentication)
                if err != nil {
                    return nil, errors.Wrap(err, "get code repository")
            Severity: Major
            Found in pkg/package/service/collection.go - About 35 mins to fix

              Function newProjectAddCommand has 5 return statements (exceeds 4 allowed).
              Open

              func newProjectAddCommand() *projectAddCommand {
                  cmd := &cobra.Command{
                      Use:                   "add LABEL PATH",
                      Short:                 "Add an existing project",
                      Aliases:               []string{"a"},
              Severity: Major
              Found in cmd/projectAdd.go - About 35 mins to fix

                Method packageService.ImportPackageFromConfig has 5 return statements (exceeds 4 allowed).
                Open

                func (ps packageService) ImportPackageFromConfig(path string) (*domain.Package, error) {
                    // Validate file path
                    err := isConfigPathValid(path)
                    if err != nil {
                        return nil, err
                Severity: Major
                Found in pkg/package/service/config.go - About 35 mins to fix

                  Function storePlugins has 5 return statements (exceeds 4 allowed).
                  Open

                  func storePlugins(tx *gorm.DB, plugins []*domain.Plugin, packageID uint) error {
                      var err error
                      insertPluginStmt := "INSERT OR IGNORE INTO plugins (created_at, updated_at, path, exec_number, description) VALUES (?, ?, ?, ?, ?)"
                      insertAssociationStmt := "INSERT OR IGNORE INTO package_plugins (package_id, plugin_id) VALUES (?, ?)"
                      queryIDStmt := "SELECT id from plugins WHERE path = ?"
                  Severity: Major
                  Found in pkg/package/store/store.go - About 35 mins to fix

                    Method packageStore.deepQueryPackage has 5 return statements (exceeds 4 allowed).
                    Open

                    func (ps packageStore) deepQueryPackage(conditions string, values ...string) (pkg *domain.Package, err error) {
                        rows, err := ps.db.Raw(defaultPackageDeepQueryBase+" "+conditions, values).Rows()
                        if err != nil {
                            return nil, err
                        }
                    Severity: Major
                    Found in pkg/package/store/store.go - About 35 mins to fix

                      Function newPackageRemoveCommand has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
                      Open

                      func newPackageRemoveCommand() *packageRemoveCommand {
                          var removeAllPackages, forceRemovePackages bool
                      
                          cmd := &cobra.Command{
                              Use:     "rm LABEL [LABEL...]",
                      Severity: Minor
                      Found in cmd/packageRm.go - About 35 mins to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

                      Function newPackageImportCommand has 5 return statements (exceeds 4 allowed).
                      Open

                      func newPackageImportCommand() *packageImportCommand {
                          var remoteRepos, directories, configs, packages, collections []string
                      
                          cmd := &cobra.Command{
                              Use:     "import FROM [FROM...]",
                      Severity: Major
                      Found in cmd/packageImport.go - About 35 mins to fix

                        Method projectStore.StoreProject has 5 return statements (exceeds 4 allowed).
                        Open

                        func (ps *projectStore) StoreProject(project *domain.Project) error {
                            err := ps.db.Where("path = ?", project.Path).First(project).Error
                            if err == nil {
                                return ErrProjectExists
                            }
                        Severity: Major
                        Found in pkg/project/store/store.go - About 35 mins to fix

                          Function storeTemplates has 5 return statements (exceeds 4 allowed).
                          Open

                          func storeTemplates(tx *gorm.DB, templates []*domain.Template, packageID uint) error {
                              insertTemplateStmt := "INSERT OR IGNORE INTO templates (created_at, updated_at, is_file, destination, path, description) VALUES (?, ?, ?, ?, ?, ?)"
                              insertAssociationStmt := "INSERT OR IGNORE INTO package_templates (package_id, template_id) VALUES (?, ?)"
                              queryIDStmt := "SELECT id from templates WHERE destination = ? AND path = ?"
                              for _, template := range templates {
                          Severity: Major
                          Found in pkg/package/store/store.go - About 35 mins to fix

                            Method packageService.ImportPackageFromRemote has 5 return statements (exceeds 4 allowed).
                            Open

                            func (ps packageService) ImportPackageFromRemote(url *url.URL) (*domain.Package, error) {
                                // Get code repo
                                codeRepo, err := remote.NewCodeRepository(url, ps.authentication)
                                if err != nil {
                                    return nil, errors.Wrap(err, "get code repository")
                            Severity: Major
                            Found in pkg/package/service/remote.go - About 35 mins to fix

                              Function newProjectRemoveCommand has 5 return statements (exceeds 4 allowed).
                              Open

                              func newProjectRemoveCommand() *projectRemoveCommand {
                                  var removeAllProjects, forceRemoveProjects bool
                              
                                  cmd := &cobra.Command{
                                      Use:     "rm PATH [PATH...]",
                              Severity: Major
                              Found in cmd/projectRm.go - About 35 mins to fix
                                Severity
                                Category
                                Status
                                Source
                                Language