15
complexity issues
complexity issues
1
duplications
duplications
13
style issues
style issues
1376
lines of code
lines of code
-
code coverage
code coverage
Don't wait to improve your code. Do it now!
After analysing purplecat we've found issues with the biggest overall impact on your project's
health.Try to refactor these hot spots first and see how your GPA improves.
- site/static/demo.js
- 5152535455
const showError = (message) => {
const messageArea = document.getElementById(
'message'
)
messageArea.innerText = message
messageArea.classList.add(
"warning"
)
}
- 4546474849
const showMessage = (message) => {
const messageArea = document.getElementById(
'message'
)
messageArea.innerText = message
messageArea.classList.remove(
"warning"
)
}
- cmd/purplecat/server.go
- 211212213214215216217218219220221222
func
createRestAPI(cache purplecat.CacheDB) *mux.Router {
router := mux.NewRouter()
subRouter := router.PathPrefix(
"/purplecat/api/"
).Subrouter()
subRouter.HandleFunc(
"/licenses"
, runPurplecatGetHandler(cache)).Methods(
"GET"
)
subRouter.HandleFunc(
"/licenses"
, runPurplecatPostHandler(cache)).Methods(
"POST"
)
subRouter.HandleFunc(
"/licenses"
, optionsHandler).Methods(
"OPTIONS"
)
subRouter.HandleFunc(
"/caches"
, clearCacheHandler(cache)).Methods(
"DELETE"
)
subRouter.HandleFunc(
"/caches"
, wholeCacheHandler(cache)).Methods(
"GET"
)
subRouter.HandleFunc(
"/caches"
, optionsHandler).Methods(
"OPTIONS"
)
router.PathPrefix(
"/purplecat/"
).Handler(createFileServer())
return
router
}
- writer.go
- 139140141142143144145146147148149150151152153154155156157158159160161162163
func
(xw *xmlWriter) string(tree *Project, indent string) string {
xmlLicenses := []string{}
for
_, license :=
range
tree.Licenses() {
xmlLicenses = append(xmlLicenses, indent+
" <license-name>"
+license.Name+
"</license-name>"
)
}
project := fmt.Sprintf(`%s<project-name>%s</project-name>
%s<license-names>
%s
%s</license-names>`, indent, tree.Name(), indent, strings.Join(xmlLicenses,
"\n"
), indent)
array := []string{}
for
_, dep :=
range
tree.Dependencies() {
if
dep != nil {
array = append(array, fmt.Sprintf(`%s <dependency>
%s
%s </dependency>`, indent, xw.string(dep, indent+
" "
), indent))
}
}
if
len(array) > 0 {
project = fmt.Sprintf(`%s
%s<dependencies>
%s
%s</dependencies>`, project, indent, strings.Join(array,
"\n"
), indent)
}
return
project
}
- maven.go
- 164165166167168169170171172173174175176177
func
constructProject(root *xmlquery.Node, path *Path, context *Context, currentDepth int) (*Project, error) {
artifact := parseProjectInfo(root)
if
dep, ok := hitCache(artifact, context); ok {
return
dep, nil
}
readProperties(root, artifact)
licenses, ok := findLicensesFromPom(artifact, root)
if
!ok && artifact.parent != nil {
licenses = findParentLicense(artifact.parent, context, currentDepth)
}
project := context.NewProject(artifact.Name(), licenses)
context.RegisterCache(project)
return
readDependencies(artifact, project, root)
}
- maven.go
- 118119120121122123124125126127128129130131132133134
func
parsePomProject(doc *xmlquery.Node, pomPath *Path, context *Context, currentDepth int) (*Project, error) {
project, err := constructProject(doc, pomPath.Dir(), context, currentDepth)
if
err != nil {
return
nil, err
}
for
_, dep :=
range
project.Deps {
if
_, ok := context.SearchCache(dep); ok {
continue
}
path, err := generatePomPath(dep, context)
if
err == nil {
parsePom(path, context, currentDepth+1)
}
}
return
project, nil
// return constructDependencyTree(doc, pomPath.Dir(), context, currentDepth)
}