max-mapper / standard-format

converts your code into Standard JavaScript Format
264 stars 59 forks source link

else on next line is inconsistent #135

Closed pocesar closed 7 years ago

pocesar commented 8 years ago

Take this code before formatting (generated by Typescript):

    function has(obj, path, ownPropertiesOnly) {
        if (ownPropertiesOnly === void 0) { ownPropertiesOnly = exports.defaultOptions.ownPropertiesOnly; }
        if (isEmpty(obj, ownPropertiesOnly)) {
            return false;
        }
        if (isNumber(path)) {
            path = [path];
        }
        else if (isString(path)) {
            path = path.split('.');
        }
        if (isEmpty(path, ownPropertiesOnly) || path.length === 0) {
            return false;
        }
        for (var i = 0; i < path.length; i++) {
            var j = path[i];
            if (isObject(obj) || isArray(obj)) {
                if (ownPropertiesOnly) {
                    if (_hasOwnProperty.call(obj, j)) {
                        obj = obj[j];
                    }
                    else {
                        return false;
                    }
                }
                else {
                    if (j in obj) {
                        obj = obj[j];
                    }
                    else {
                        return false;
                    }
                }
            }
            else {
                return false;
            }
        }
        return true;
    }

after formatting, it becomes:

  function has (obj, path, ownPropertiesOnly) {
    if (ownPropertiesOnly === void 0) { ownPropertiesOnly = exports.defaultOptions.ownPropertiesOnly; }
    if (isEmpty(obj, ownPropertiesOnly)) {
      return false
    }
    if (isNumber(path)) {
      path = [path]
    }
    else if (isString(path)) {
      path = path.split('.')
    }
    if (isEmpty(path, ownPropertiesOnly) || path.length === 0) {
      return false
    }
    for (var i = 0; i < path.length; i++) {
      var j = path[i]
      if (isObject(obj) || isArray(obj)) {
        if (ownPropertiesOnly) {
          if (_hasOwnProperty.call(obj, j)) {
            obj = obj[j]
          } else {
            return false
          }
        } else {
          if (j in obj) {
            obj = obj[j]
          } else {
            return false
          }
        }
      } else {
        return false
      }
    }
    return true
  }

it did manage to fix a couple of elses, but somehow left some behind. then it complains:

g:\www\object-path\index.js:37:101: Extra semicolon.
g:\www\object-path\index.js:44:10: Closing curly brace does not appear on the same line as the subsequent block.

Plus it's not removing the semicolon on the ownPropertiesOnly = exports.defaultOptions.ownPropertiesOnly;

feross commented 7 years ago

You should use standard --fix instead of this package. standard-format isn't being actively maintained anymore.