ActivityWatch/aw-webui

View on GitHub

Showing 53 of 53 total issues

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

        const hostnames = bucketsStore.hosts.filter(
          // require that the host has afk buckets,
          // and that the host is not a fakedata host,
          // unless we're explicitly querying fakedata
          host =>
Severity: Major
Found in src/stores/activity.ts and 1 other location - About 2 hrs to fix
src/stores/activity.ts on lines 256..264

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 76.

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

Function canonicalEvents has 44 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function canonicalEvents(params: DesktopQueryParams | AndroidQueryParams): string {
  // Needs escaping for regex patterns like '\w' to work (JSON.stringify adds extra unecessary escaping)
  const categories_str = params.categories
    ? JSON.stringify(params.categories).replace(/\\\\/g, '\\')
    : '';
Severity: Minor
Found in src/queries.ts - About 1 hr to fix

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

        async load({ save }: { save?: boolean } = {}) {
          if (typeof localStorage === 'undefined') {
            console.error('localStorage is not supported');
            return;
          }
    Severity: Minor
    Found in src/stores/settings.ts - 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 buildTooltip has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function buildTooltip(bucket, e) {
      // WARNING: XSS risk, make sure to sanitize properly
      // FIXME: Not actually tested against XSS attacks, implementation needs to be verified in tests.
      let inner = 'Unknown bucket type';
    
    
    Severity: Minor
    Found in src/util/tooltip.js - About 1 hr to fix

      Function overlappingEvents has 42 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function overlappingEvents(events1, events2): Overlap[] {
        events1 = events1.sort((a, b) => a.timestamp - b.timestamp);
        events2 = events2.sort((a, b) => a.timestamp - b.timestamp);
      
        let i = 0;
      Severity: Minor
      Found in src/util/transforms.ts - About 1 hr to fix

        Function drawLegend has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function drawLegend() {
          // Dimensions of legend item: width, height, spacing, radius of rounded rect.
          const li = {
            w: 75,
            h: 30,
        Severity: Minor
        Found in src/visualizations/sunburst-clock.ts - About 1 hr to fix

          Function fullDesktopQuery has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export function fullDesktopQuery(params: DesktopQueryParams): string[] {
            return querystr_to_array(
              `
              ${canonicalEvents({
                ...params,
          Severity: Minor
          Found in src/queries.ts - About 1 hr to fix

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

              timeline
                .append('text')
                .attr('x', '0')
                .attr('y', '3')
                .text(text)
            Severity: Major
            Found in src/visualizations/timeline-simple.js and 1 other location - About 1 hr to fix
            src/visualizations/timeline.js on lines 61..68

            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 64.

            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

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

              timeline
                .append('text')
                .attr('x', '0')
                .attr('y', '3')
                .text(text)
            Severity: Major
            Found in src/visualizations/timeline.js and 1 other location - About 1 hr to fix
            src/visualizations/timeline-simple.js on lines 24..31

            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 64.

            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

            Function overlappingEvents has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

            export function overlappingEvents(events1, events2): Overlap[] {
              events1 = events1.sort((a, b) => a.timestamp - b.timestamp);
              events2 = events2.sort((a, b) => a.timestamp - b.timestamp);
            
              let i = 0;
            Severity: Minor
            Found in src/util/transforms.ts - 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 load has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                async load({ save }: { save?: boolean } = {}) {
                  if (typeof localStorage === 'undefined') {
                    console.error('localStorage is not supported');
                    return;
                  }
            Severity: Minor
            Found in src/stores/settings.ts - About 1 hr to fix

              Function buildBarchartDataset has 34 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              export function buildBarchartDataset(data_by_hour: HourlyData[], classes: Category[]): Dataset[] {
                const SEP = '>>>';
                const data = data_by_hour;
                if (data) {
                  const category_names: Set<string> = new Set(
              Severity: Minor
              Found in src/util/datasets.ts - About 1 hr to fix

                Function bucketsByDevice has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    bucketsByDevice: function () {
                      let devices = _.mapValues(
                        _.groupBy(this.buckets, b => b.hostname || b.device_id),
                        d => {
                          const hostnames = _.uniq(_.map(d, b => b.hostname || b.data.hostname));
                Severity: Minor
                Found in src/stores/buckets.ts - About 1 hr to fix

                  Function buildBarchartDataset has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                  Open

                  export function buildBarchartDataset(data_by_hour: HourlyData[], classes: Category[]): Dataset[] {
                    const SEP = '>>>';
                    const data = data_by_hour;
                    if (data) {
                      const category_names: Set<string> = new Set(
                  Severity: Minor
                  Found in src/util/datasets.ts - 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 create has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function create(el: HTMLElement) {
                    // Clear the svg in case we are redrawing
                    rootEl = d3.select(el);
                    rootEl.selectAll('svg').remove();
                  
                  
                  Severity: Minor
                  Found in src/visualizations/sunburst-clock.ts - About 1 hr to fix

                    Function split_by_hour_into_data has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    export function split_by_hour_into_data(events) {
                      if (events === undefined || events === null || events.length == 0) return [];
                      const d = moment(events[0].timestamp).startOf('day');
                      const hoursOffset = get_hour_offset();
                      return _.range(0, 24).map(h => {
                    Severity: Minor
                    Found in src/util/transforms.ts - About 1 hr to fix

                      Function query_active_history has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          async query_active_history({ timeperiod, ...query_options }: QueryOptions) {
                            const settingsStore = useSettingsStore();
                            const bucketsStore = useBucketsStore();
                            // Filter out periods that are already in the history, and that are in the future
                            const periods = timeperiodStrsAroundTimeperiod(timeperiod).filter(tp_str => {
                      Severity: Minor
                      Found in src/stores/activity.ts - About 1 hr to fix

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

                          beforeCreate: function () {
                            const that = this;
                            const methods = this.$options.methods || {};
                            for (const key in methods) {
                              const original = methods[key];
                        Severity: Minor
                        Found in src/mixins/asyncErrorCaptured.js - 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 getTitleAttr has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                        export function getTitleAttr(bucket: IBucket, e: IEvent) {
                          if (bucket.type == 'currentwindow') {
                            return e.data.app;
                          } else if (bucket.type == 'web.tab.current') {
                            const domainRegex = /^.+:\/\/(?:www.)?([^/]+)/;
                        Severity: Minor
                        Found in src/util/color.ts - About 45 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 updateSummedEvents has 6 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                          container: HTMLElement,
                          summedEvents: IEvent[],
                          titleKeyFunc: (event: IEvent) => string,
                          hoverKeyFunc: (event: IEvent) => string,
                          colorKeyFunc: (event: IEvent) => string,
                        Severity: Minor
                        Found in src/visualizations/summary.ts - About 45 mins to fix
                          Severity
                          Category
                          Status
                          Source
                          Language