Showing 27 of 39 total issues
Function NewEndpoint
has 172 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func NewEndpoint(serviceName, subdomain string) (oauth2.Endpoint, string, error) {
switch strings.ToLower(strings.TrimSpace(serviceName)) {
case ServiceAha:
subdomain = strings.TrimSpace(subdomain)
if len(subdomain) == 0 {
Function main
has 67 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func main() {
//err := config.LoadDotEnvSkipEmpty(os.Getenv("ENV_PATH"), "./.env")
_, err := config.LoadDotEnv([]string{"./.env"}, -1)
if err != nil {
panic(err)
Function sendTestEmail
has 65 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func sendTestEmail(cfg appConfig, client gosparkpost.Client) {
day := 811 // Change this to set the day. This currently uses single digit month + 2 digit day
seq := 0 // Sequence index. Start with 0 and increment. This demo doesn't support changing the day when changing sequence.
if len(strings.TrimSpace(cfg.SparkPostEmailRecipientDemo)) == 0 {
Method Credentials.NewClient
has 10 return statements (exceeds 4 allowed). Open
Open
func (creds *Credentials) NewClient(ctx context.Context) (*http.Client, error) {
switch creds.Type {
case TypeBasic:
if creds.Basic == nil {
return nil, ErrBasicAuthNotPopulated
Method CredentialsOAuth2.NewToken
has 8 return statements (exceeds 4 allowed). Open
Open
func (oc *CredentialsOAuth2) NewToken(ctx context.Context) (*oauth2.Token, error) {
if oc.Token != nil && len(strings.TrimSpace(oc.Token.AccessToken)) > 0 {
return oc.Token, nil
} else if strings.Contains(strings.ToLower(oc.GrantType), "jwt") {
return authutil.NewTokenOAuth2JWT(ctx, oc.Endpoint.TokenURL, oc.ClientID, oc.ClientSecret, oc.JWT)
Function NewClientFileStore
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
credentials []byte,
scopes []string,
tokenPath string,
useDefaultDir bool,
forceNewToken bool,
Function RetrieveRcToken
has 7 return statements (exceeds 4 allowed). Open
Open
func RetrieveRcToken(cfg oauth2.Config, params url.Values) (*RcToken, error) {
r, err := http.NewRequest(
http.MethodPost,
cfg.Endpoint.TokenURL,
strings.NewReader(params.Encode()))
Avoid deeply nested control flow statements. Open
Open
} else if oc.IsGrantType(authutil.GrantTypePassword) {
// cfg := oc.Config()
// return cfg.PasswordCredentialsToken(ctx, oc.Username, oc.Password)
return oc.NewTokenPasswordCredentials(ctx) // supports custom request params
} else if oc.IsGrantType(authutil.GrantTypeAuthorizationCode) {
Function NewClientFileStore
has 6 return statements (exceeds 4 allowed). Open
Open
func NewClientFileStore(
credentials []byte,
scopes []string,
tokenPath string,
useDefaultDir bool,
Function GetOneItem
has 6 return statements (exceeds 4 allowed). Open
Open
func GetOneItem(items []Item) Item {
if len(items) == 0 {
return Item{}
}
havePrimary := false
Function ParseJWTString
has 6 return statements (exceeds 4 allowed). Open
Open
func ParseJWTString(tokenString string, secretKey string, claims jwt.Claims) (*jwt.Token, error) {
// https://stackoverflow.com/questions/41077953/go-language-and-verify-jwt
if claims == nil {
if token, err := jwt.Parse(tokenString, func(token *jwt.Token) (any, error) {
return []byte(secretKey), nil
Function ContactsV1ExportWriteFiles
has 6 return statements (exceeds 4 allowed). Open
Open
func ContactsV1ExportWriteFiles(client *http.Client, fileprefix string, opts *ContactsListV1Opts) error {
if len(fileprefix) == 0 {
fileprefix = "hubspot_contacts_v1"
}
if opts != nil && opts.Count > LimitMax || opts.Count < 1 {
Method Config.NewClient
has 6 return statements (exceeds 4 allowed). Open
Open
func (cfg Config) NewClient() (*http.Client, error) {
tlsConfig, err := tlsutil.NewTLSConfigCerts("", "", []string{}, []string{}, false)
if err != nil {
return nil, err
}
Function ContactsV3ExportWriteFiles
has 6 return statements (exceeds 4 allowed). Open
Open
func ContactsV3ExportWriteFiles(client *http.Client, fileprefix string, opts *ContactsListV3Opts) error {
if len(fileprefix) == 0 {
fileprefix = "hubspot_contacts_v3"
}
if opts != nil && opts.Limit > LimitMax || opts.Limit < 1 {
Function NewClientWithTokenSet
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
func NewClientWithTokenSet(ctx context.Context, conf *oauth2.Config, token *oauth2.Token,
tokenSet TokenSet, tokenKey, serviceKey, serviceType string) (*http.Client, error) {
Function NewClientWebTokenStore
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
func NewClientWebTokenStore(ctx context.Context, conf *oauth2.Config, tStore *TokenStoreFile, forceNewToken bool, state string) (*http.Client, error) {
Method ClientUtil.GetSCIMUser
has 5 return statements (exceeds 4 allowed). Open
Open
func (apiutil *ClientUtil) GetSCIMUser() (scim.User, error) {
scimUser := scim.User{}
resp, err := apiutil.Client.Get(GoogleAPIURLUserinfo)
if err != nil {
Function main
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
Open
func main() {
//err := config.LoadDotEnvSkipEmpty(os.Getenv("ENV_PATH"), "./.env")
_, err := config.LoadDotEnv([]string{"./.env"}, -1)
if err != nil {
panic(err)
- Read upRead up
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 TokenClientCredentials
has 5 return statements (exceeds 4 allowed). Open
Open
func TokenClientCredentials(cfg clientcredentials.Config) (*oauth2.Token, error) {
body := url.Values{}
body.Add(ParamGrantType, GrantTypeClientCredentials)
for _, scope := range cfg.Scopes {
body.Add(ParamScope, scope)
Method CredentialsOAuth2.NewTokenPasswordCredentials
has 5 return statements (exceeds 4 allowed). Open
Open
func (oc *CredentialsOAuth2) NewTokenPasswordCredentials(ctx context.Context) (*oauth2.Token, error) {
if sreq, err := oc.newTokenPasswordCredentialsRequest(ctx); err != nil {
return nil, err
} else if hreq, err := sreq.HTTPRequest(ctx); err != nil {
return nil, err