prey/prey-node-client

View on GitHub

Showing 551 of 551 total issues

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

function clear_current_request() {
  if (current_request) {
    logger.debug('Clearing current request');
    if (current_request.request) {
      logger.debug('Aborting current request');
Severity: Major
Found in lib/agent/control-panel/long-polling/index.js and 1 other location - About 1 hr to fix
lib/conf/long-polling.js on lines 128..137

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

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

function clear_current_request() {
  if (current_request) {
    logger.debug("Clearing current request");
  if (current_request.request) {
    logger.debug("Aborting current request");
Severity: Major
Found in lib/conf/long-polling.js and 1 other location - About 1 hr to fix
lib/agent/control-panel/long-polling/index.js on lines 232..241

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

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

const watch_stopped = function () {
  if (!watching) return;

  hooks.on('action', (event, id) => {
    if (event == 'stopped' || event == 'failed') {
Severity: Minor
Found in lib/agent/commands.js - About 1 hr to fix

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

              (errStorageDo) => {
                if (errStorageDo) {
                  logger.error(`Error storing triggers: ${errStorageDo}`);
                }
                if (index === triggers.length - 1) {
    Severity: Major
    Found in lib/agent/actions/triggers/index.js and 1 other location - About 1 hr to fix
    lib/agent/actions/triggers/index.js on lines 594..602

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

    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

    const saveData = (data) => {
      storage.do('set', { type: 'keys', id: 'last_wifi_location', data: { value: JSON.stringify(data) } }, (err) => {
        if (err) logger.error('Unable to save last_wifi_location data');
      });
    };
    Severity: Major
    Found in lib/agent/providers/geo/strategies.js and 1 other location - About 1 hr to fix
    lib/agent/providers/hardware/index.js on lines 84..88

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

    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

              (errStorageDo) => {
                if (errStorageDo) {
                  logger.error(`Error updating triggers: ${errStorageDo}`);
                }
                if (index === triggers.length - 1) {
    Severity: Major
    Found in lib/agent/actions/triggers/index.js and 1 other location - About 1 hr to fix
    lib/agent/actions/triggers/index.js on lines 608..616

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

    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

      const saveData = () => {
        storage.do('set', { type: 'keys', id: 'hardware', data: { value: JSON.stringify(dataTrack) } }, (err) => {
          if (err) logger.error('Unable to save hardware data');
        });
      };
    Severity: Major
    Found in lib/agent/providers/hardware/index.js and 1 other location - About 1 hr to fix
    lib/agent/providers/geo/strategies.js on lines 47..51

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

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

    exports.get_active_access_point = (callback) => {
      exports.isWifiPermissionActive((itWorks) => {
        if (itWorks) {
          const processActiveAp = (stdout) => {
            if (stdout.includes('AirPort: Off') || !stdout.includes('SSID')) {
    Severity: Minor
    Found in lib/agent/providers/network/mac.js - About 1 hr to fix

      Function start has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      exports.start = function (cb) {
      
        var count,
          last_err,
          folders_removed = [];
      Severity: Minor
      Found in lib/conf/tasks/clear_folders.js - About 1 hr to fix

        Function start has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        exports.start = function (cb) {
        
          var count,
            last_err,
            files_removed = [];
        Severity: Minor
        Found in lib/conf/tasks/clear_files_prey_temp.js - About 1 hr to fix

          Function gather has 41 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          const gather = (reportName, list, cb) => {
            const data = {};
            let gathered = false;
            let count = list.length;
            let listReports = [...list];
          Severity: Minor
          Found in lib/agent/reports.js - About 1 hr to fix

            Function correctPreyConf has 41 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            const correctPreyConf = (preyConfDataToWrite, callback) => {
              let allFileContents = '';
            
              allFileContents = getFileContent(join(__dirname, '../../../../prey.conf.default'));
              if (allFileContents === '') {
            Severity: Minor
            Found in lib/agent/utils/prey-configuration/preyconf.js - About 1 hr to fix

              Function start has 40 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              const start = function (type, id, name, opts, cb) {
                // Action with same id is not executed
                if (running[id]) {
                  const err = new Error(`Already running: ${running[id].name} with id: ${id}`);
                  hooks.emit('error', err);
              Severity: Minor
              Found in lib/agent/actions.js - About 1 hr to fix

                Function update_version_attempt has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                package.update_version_attempt = (old_version, new_version, attempt_plus, set_notified, error, cb) => {
                  var create_version = function(version, cb) {
                    // Before creating the registry the table it's cleared
                    storage.do('clear', {type: 'versions'}, (err) => {
                      if (err) return cb(new Error("Unable to edit local database, update cancelled"));
                Severity: Minor
                Found in lib/package.js - About 1 hr to fix

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

                        }, (errUpdate) => {
                          if (errUpdate) {
                            logger.error(`Error while updating restarts_preyconf: ${errUpdate}`);
                            return callback(errUpdate, null);
                          }
                  Severity: Major
                  Found in lib/agent/utils/prey-configuration/validationpreyconf.js and 1 other location - About 1 hr to fix
                  lib/agent/utils/prey-configuration/validationpreyconf.js on lines 61..67

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

                  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

                          }, (errUpdate) => {
                            if (errUpdate) {
                              logger.error(`Error while updating restarts_preyconf: ${errUpdate}`);
                              return callback(errUpdate, null);
                            }
                  Severity: Major
                  Found in lib/agent/utils/prey-configuration/validationpreyconf.js and 1 other location - About 1 hr to fix
                  lib/agent/utils/prey-configuration/validationpreyconf.js on lines 28..34

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

                  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

                  _PositionSource = function () {
                    this.cellular = 0;
                    this.satellite = 1;
                    this.wiFi = 2;
                    this.iPAddress = 3;
                  lib/agent/providers/geo/win32/windows.devices.geolocation/lib/NodeRT_Windows_Devices_Geolocation.d.js on lines 44..50

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

                  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

                  _AltitudeReferenceSystem = function () {
                    this.unspecified = 0;
                    this.terrain = 1;
                    this.ellipsoid = 2;
                    this.geoid = 3;
                  lib/agent/providers/geo/win32/windows.devices.geolocation/lib/NodeRT_Windows_Devices_Geolocation.d.js on lines 29..35

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

                  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 get_tree has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                  Open

                  module.exports.get_tree = function(options, cb) {
                  
                    var dir = options.path;
                  
                    // We need to run the tree walker script personifying
                  Severity: Minor
                  Found in lib/agent/providers/files/index.js - 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 check_and_show has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                  Open

                  exports.check_and_show = function(values, cb) {
                    var force      = values['-f'] === true;
                    var old_config = (values['-c'] || values['--check-file']) && values.positional[0];
                  
                    var show = function() {
                  Severity: Minor
                  Found in lib/conf/gui/index.js - 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

                  Severity
                  Category
                  Status
                  Source
                  Language