meedan/check-bot

View on GitHub

Showing 35 of 102 total issues

Function process has 223 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const process = function(event, callback, teamConfig) {
  const mainRegexp = new RegExp(escapeRegExp(config.checkWeb.url), 'g');
  const checkURLPattern = escapeRegExp(config.checkWeb.url) + '(?:\/([^/]+)\/project\/([0-9]+)\/media\/([0-9]+)|\/([^/]+)\/media\/([0-9]+))';
  const regexp = new RegExp(checkURLPattern, 'g');

Severity: Major
Found in index.js - About 1 day to fix

    File index.test.js has 496 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    const btoa = require('btoa');
    const atob = require('atob');
    let aws = require('aws-sdk');
    const awsMock = require('aws-sdk-mock');
    const md5 = require('js-md5');
    Severity: Minor
    Found in index.test.js - About 7 hrs to fix

      File index.js has 460 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      const config = require('./config.js'),
            https = require('https'),
            request = require('request'),
            qs = require('querystring'),
            aws = require('aws-sdk'),
      Severity: Minor
      Found in index.js - About 7 hrs to fix

        Function process has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
        Open

        const process = function(event, callback, teamConfig) {
          const mainRegexp = new RegExp(escapeRegExp(config.checkWeb.url), 'g');
          const checkURLPattern = escapeRegExp(config.checkWeb.url) + '(?:\/([^/]+)\/project\/([0-9]+)\/media\/([0-9]+)|\/([^/]+)\/media\/([0-9]+))';
          const regexp = new RegExp(checkURLPattern, 'g');
        
        
        Severity: Minor
        Found in index.js - About 4 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 formatMessageFromData has 96 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const formatMessageFromData = function(data) {
        
          // Build a list of verification statuses (core or custom) to be selected
          // Get the current status (label and color)
        
        
        Severity: Major
        Found in helpers.js - About 3 hrs to fix

          File slash-response.js has 310 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          // This function adds a ProjectMedia to Check and sends a message back to Slack
          
          const config = require('./config.js'),
                request = require('request'),
                util = require('util'),
          Severity: Minor
          Found in slash-response.js - About 3 hrs to fix

            Function sendActionToSmoochBot has 60 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            const sendActionToSmoochBot = function(payload, redisKey, callback, action) {
              let message = ''
              const redis = getRedisClient();
              redis.on('connect', function() {
                redis.get(redisKey, function(err, reply) {
            Severity: Major
            Found in slash-response.js - About 2 hrs to fix

              File slash-response.test.js has 259 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              const btoa = require('btoa');
              const fetch = require('node-fetch');
              let config = require('./config');
              const sr = require('./slash-response');
              
              
              Severity: Minor
              Found in slash-response.test.js - About 2 hrs to fix

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

                const process = function(body, token, callback) {
                  const setProjectRegexp = new RegExp(/set <(.+)>/, 'g');
                  const showProjectRegexp = new RegExp(/^show/, 'g');
                  const addUrlRegexp = new RegExp(/<(.+)>/, 'g');
                  const activateBotRegexp = new RegExp(/^bot activate/, 'g');
                Severity: Minor
                Found in slash.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 helpers.js has 253 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                const config = require('./config.js'),
                      Lokka = require('lokka').Lokka,
                      Transport = require('lokka-transport-http').Transport,
                      header = require('basic-auth-header'),
                      request = require('request'),
                Severity: Minor
                Found in helpers.js - About 2 hrs to fix

                  Function changeStatus has 49 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  const changeStatus = function(data, token, callback) {
                    const value = JSON.parse(data.callback_id);
                    const vars = {
                      id: value.last_status_id,
                      setFields: JSON.stringify({
                  Severity: Minor
                  Found in buttons.js - About 1 hr to fix

                    Function process has 49 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    const process = function(data, callback, context) {
                      if (data.token === VERIFICATION_TOKEN) {
                    
                        getCheckSlackUser(data.user.id,
                          function(err) {
                    Severity: Minor
                    Found in buttons.js - About 1 hr to fix

                      Function handler has 48 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      exports.handler = function(data, context, callback) {
                        let options = {
                          url: 'https://www.google.com/searchbyimage',
                          qs: { image_url: data.image_url, sbisrc: '4chanx', safe: 'off' },
                          headers: { 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36', 'accept-language': 'en-US,en;q=0.5' }
                      Severity: Minor
                      Found in google-image-search.js - About 1 hr to fix

                        Function process has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        const process = function(body, token, callback) {
                          const setProjectRegexp = new RegExp(/set <(.+)>/, 'g');
                          const showProjectRegexp = new RegExp(/^show/, 'g');
                          const addUrlRegexp = new RegExp(/<(.+)>/, 'g');
                          const activateBotRegexp = new RegExp(/^bot activate/, 'g');
                        Severity: Minor
                        Found in slash.js - About 1 hr to fix

                          Function updateTitleOrDescription has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          const updateTitleOrDescription = function(attribute, event, data, token, callback, done) {
                            const id = data.last_status_id,
                                  text = event.text;
                          
                            const mutationQuery = `($setFields: String!, $id: ID!, $clientMutationId: String!) {
                          Severity: Minor
                          Found in index.js - About 1 hr to fix

                            Function getProjectMedia has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            const getProjectMedia = function(teamSlug, projectId, projectMediaId, callback, done) {
                              const client = getGraphqlClient(teamSlug, config.checkApi.apiKey, callback);
                            
                              const projectMediaQuery = `
                              query project_media($ids: String!) {
                            Severity: Minor
                            Found in index.js - About 1 hr to fix

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

                              const sendSmoochImage = function(payload, callback) {
                                const redis = getRedisClient();
                                redis.on('connect', function() {
                                  const redisKey = 'slack_channel_smooch:' + config.redisPrefix + ':' + payload.body.channel;
                                  redis.get(redisKey, function(err, reply) {
                              Severity: Minor
                              Found in slash-response.js - About 1 hr to fix

                                Function showTips has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                const showTips = function(payload, callback) {
                                  let message = {
                                    response_type: 'ephemeral',
                                    text: ':wave: ' + t('need_some_help_with') + ' `' + payload.body.command + '`?',
                                    attachments: [
                                Severity: Minor
                                Found in slash-response.js - About 1 hr to fix

                                  Function testEditMedia has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                  const testEditMedia = async (field) => {
                                    let outputData = '';
                                    storeLog = inputs => (outputData += inputs);
                                    console['log'] = jest.fn(storeLog);
                                  
                                  
                                  Severity: Minor
                                  Found in index.test.js - About 1 hr to fix

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

                                          const fieldCallback = function(resp) {
                                            if (!resp && n < 60) {
                                              n++;
                                              setTimeout(function() { getField(query, callback, fieldCallback) }, 5000);
                                            }
                                    Severity: Minor
                                    Found in index.js - About 1 hr to fix
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language