Showing 254 of 254 total issues

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

          <FormControl display="flex" alignItems="center">
            <Switch
              isChecked={alerts.sound}
              onChange={e => handleChangeAlert('sound', e.target.checked)}
              mx="1rem"
Severity: Major
Found in new-client/src/components/WindowSettings.tsx and 3 other locations - About 3 hrs to fix
new-client/src/components/WindowSettings.tsx on lines 111..121
new-client/src/components/WindowSettings.tsx on lines 122..132
new-client/src/components/WindowSettings.tsx on lines 133..143

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

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 init has 72 lines of code (exceeds 25 allowed). Consider refactoring.
Open

exports.init = async function init(user, session, maxBacklogLines, cachedUpto) {
  await settingsService.sendUpdateSettings(user, session.id);
  await friendsService.sendUpdateFriends(user, session.id);
  await friendsService.sendConfirmFriends(user, session.id);
  await friendsService.informStateChange(user, 'login');
Severity: Major
Found in server/services/session.js - About 2 hrs to fix

    Function handleMode has 66 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    async function handleMode(user, msg) {
      // :ilkka9!~ilkka9@localhost.myrootshell.com MODE #sunnuntai +k foobar3
      const target = msg.params[0];
    
      if (!isChannel(target)) {
    Severity: Major
    Found in server/backends/irc/controller.js - About 2 hrs to fix

      Function didInsertElement has 65 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        didInsertElement() {
          this.sendAction('register', this);
          this.set('elementInserted', true);
      
          this.$messagePanel = this.$('.window-messages');
      Severity: Major
      Found in client/app/pods/components/discussion-window/component.js - About 2 hrs to fix

        Function RegisterModal has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

        export const RegisterModal: FunctionComponent<RegisterModalProps> = ({ isOpen, onClose }: RegisterModalProps) => {
          const validateName = (value: string) => {
            if (!value) {
              return 'Name is required';
            } else if (value.length < 6) {
        Severity: Minor
        Found in website/src/components/RegisterModal.tsx - About 2 hrs 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 configTransports has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

        function configTransports() {
          const transports = [];
        
          if (get('log:file')) {
            let logDirectory = path.normalize(get('log:directory'));
        Severity: Minor
        Found in server/lib/log.ts - About 2 hrs 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

        File create-db.ts has 273 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        //
        //   Copyright 2015 Ilkka Oksanen <iao@iki.fi>
        //
        //   Licensed under the Apache License, Version 2.0 (the "License");
        //   you may not use this file except in compliance with the License.
        Severity: Minor
        Found in server/bin/create-db.ts - About 2 hrs to fix

          File MessageRenderer.tsx has 271 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          import React, { FunctionComponent, useContext, useState, KeyboardEvent } from 'react';
          import {
            Button,
            Box,
            Flex,
          Severity: Minor
          Found in new-client/src/components/MessageRenderer.tsx - About 2 hrs to fix

            Function WindowSettings has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
            Open

            const WindowSettings: FunctionComponent = () => {
              const { windowStore } = useContext(ServerContext);
              const window = windowStore.activeWindow;
              const [topic, setTopic] = useState<string | null>(null);
              const [requestedNotificationPermission, setRequestedNotificationPermission] = useState<boolean>(false);
            Severity: Minor
            Found in new-client/src/components/WindowSettings.tsx - About 2 hrs 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 updateNick has 55 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            async function updateNick(user, network, oldNick, newNick) {
              let changed = false;
              let targetUserGId = null;
              const nickUser = await nicksService.getUser(oldNick, network);
            
            
            Severity: Major
            Found in server/backends/irc/controller.js - About 2 hrs to fix

              File Message.js has 257 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              import { computed, observable } from 'mobx';
              import marked from 'marked';
              import emojione from 'emojione';
              import moment from 'moment';
              import URI from 'urijs';
              Severity: Minor
              Found in client/app/models/Message.js - About 2 hrs to fix

                Function _dragWindowEnd has 54 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  _dragWindowEnd(event) {
                    const cursor = this.cursor;
                
                    this.set('draggedWindow', false);
                    this.movingWindow.$().removeClass('moving').css('z-index', '');
                Severity: Major
                Found in client/app/pods/components/window-grid/component.js - About 2 hrs to fix

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

                    if (!userRecord.valid) {
                      Object.keys(userRecord.errors).forEach(field => {
                        form.fields[field].error = userRecord.errors[field];
                      });
                  
                  
                  Severity: Major
                  Found in server/controllers/register.js and 1 other location - About 2 hrs to fix
                  server/controllers/register.js on lines 233..240

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

                  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

                    if (!user.valid) {
                      Object.keys(user.errors).forEach(field => {
                        form.fields[field].error = user.errors[field];
                      });
                  
                  
                  Severity: Major
                  Found in server/controllers/register.js and 1 other location - About 2 hrs to fix
                  server/controllers/register.js on lines 284..291

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

                  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 constructor has 53 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    constructor() {
                      if (!this.cookie) {
                        console.error(`Session cookie not found or corrupted. Exiting.`);
                        this._logout();
                      }
                  Severity: Major
                  Found in client/app/utils/socket.js - About 2 hrs to fix

                    Function Sidebar has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                    Open

                    const Sidebar: FunctionComponent<SidebarProps> = ({ fullScreen = false, showDesktops }: SidebarProps) => {
                      const { windowStore } = useContext(ServerContext);
                    
                      const sortWindows = (windows: WindowModel[]) => {
                        return windows.sort((a, b) => {
                    Severity: Minor
                    Found in new-client/src/components/Sidebar.tsx - About 2 hrs 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 LoginModal has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                    Open

                    export const LoginModal: FunctionComponent<LoginModalProps> = ({ isOpen, onClose }: LoginModalProps) => {
                      const [mode, setMode] = useState<Mode>(Mode.Login);
                    
                      const googleRedirect = () => {
                        window.location.pathname = '/auth/google';
                    Severity: Minor
                    Found in website/src/components/LoginModal.tsx - About 2 hrs 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 updateNick has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                    Open

                    async function updateNick(user, network, oldNick, newNick) {
                      let changed = false;
                      let targetUserGId = null;
                      const nickUser = await nicksService.getUser(oldNick, network);
                    
                    
                    Severity: Minor
                    Found in server/backends/irc/controller.js - About 2 hrs 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

                    File requests.ts has 252 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    import { Network, MessageRecord, AlertsRecord } from './notifications';
                    
                    export interface CreateRequest {
                      id: 'CREATE';
                      name: string;
                    Severity: Minor
                    Found in new-client/src/types/requests.ts - About 2 hrs to fix

                      Function setup has 51 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      function setup() {
                        if (conf.get('googleauth:enabled')) {
                          const GoogleStrategy = require('passport-google-oauth').OAuth2Strategy;
                          const jwt = require('jwt-simple');
                      
                      
                      Severity: Major
                      Found in server/lib/passport.js - About 2 hrs to fix
                        Severity
                        Category
                        Status
                        Source
                        Language