ActivityWatch/aw-server

View on GitHub

Showing 12 of 12 total issues

File api.py has 309 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import functools
import json
import logging
from datetime import datetime
from pathlib import Path
Severity: Minor
Found in aw_server/api.py - About 3 hrs to fix

    File rest.py has 308 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import json
    import traceback
    from functools import wraps
    from threading import Lock
    from typing import Dict
    Severity: Minor
    Found in aw_server/rest.py - About 3 hrs to fix

      ServerAPI has 21 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class ServerAPI:
          def __init__(self, db, testing) -> None:
              self.db = db
              self.settings = Settings(testing)
              self.testing = testing
      Severity: Minor
      Found in aw_server/api.py - About 2 hrs to fix

        Function heartbeat has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            def heartbeat(self, bucket_id: str, heartbeat: Event, pulsetime: float) -> Event:
                """
                Heartbeats are useful when implementing watchers that simply keep
                track of a state, how long it's in that state and when it changes.
                A single heartbeat always has a duration of zero.
        Severity: Minor
        Found in aw_server/api.py - About 1 hr 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 parse_settings has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        def parse_settings():
            import argparse
        
            """ CLI Arguments """
            parser = argparse.ArgumentParser(description="Starts an ActivityWatch server")
        Severity: Minor
        Found in aw_server/main.py - About 1 hr to fix

          Function parse_settings has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

          def parse_settings():
              import argparse
          
              """ CLI Arguments """
              parser = argparse.ArgumentParser(description="Starts an ActivityWatch server")
          Severity: Minor
          Found in aw_server/main.py - About 55 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 __init__ has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def __init__(
          Severity: Major
          Found in aw_server/server.py - About 50 mins to fix

            Function _start has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def _start(
            Severity: Minor
            Found in aw_server/server.py - About 45 mins to fix

              Function create_bucket has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  def create_bucket(
              Severity: Minor
              Found in aw_server/api.py - About 45 mins to fix

                Function update_bucket has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def update_bucket(
                Severity: Minor
                Found in aw_server/api.py - About 35 mins to fix

                  Function host_header_check has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                  def host_header_check(f):
                      """
                      Protects against DNS rebinding attacks (see https://github.com/ActivityWatch/activitywatch/security/advisories/GHSA-v9fg-6g9j-h4x4)
                  
                      Some discussion in Syncthing how they do it: https://github.com/syncthing/syncthing/issues/4819
                  Severity: Minor
                  Found in aw_server/rest.py - 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 get_tag_exact has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                  def get_tag_exact():
                      rev = get_rev()
                      p = subprocess.run(
                          ["git", "describe", "--tags", "--abbrev=0", "--exact-match", rev],
                          capture_output=True,
                  Severity: Minor
                  Found in aw_server/__about__.py - About 25 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

                  Severity
                  Category
                  Status
                  Source
                  Language