Skip to content

A few examples don't pass JSHint #46

@pdehaan

Description

@pdehaan

I parsed the Markdown files, converted them to markdown, extracted the <pre><code>...</code></pre> tags, and ran the inner code through JSHint (using Node.js, but I excluded all the warnings about missing semicolons)...

Not sure how many are valid, versus expected warnings for null type checking.

https://raw.github.com/raganwald/homoiconic/master/2012/12/combinators_1.md

var inventory = {
  apples: 0,
  oranges 144,
  eggs: 36
};

get('oranges')(inventory)
  //=> 144

Errors:

  1. line:3 char:11 -- Expected ':' and instead saw '144'.
  2. line:3 char:14 -- Expected an identifier and instead saw ','.
  3. line:4 char:3 -- Expected '}' to match '{' from line 1 and instead saw 'eggs'.
  4. line:4 char:7 -- Expected '(end)' and instead saw ':'.

function isSomething (value) {
  return value != null
}

function checksForSomething (value) {
  if (isSomething(value)) {
    // function's true logic
  }
}

Errors:

  1. line:2 char:16 -- Use '!==' to compare with 'null'.

function maybe (fn) {
  return function () {
    var i;

    if (arguments.length === 0) {
      return
    }
    else {
      for (i = 0; i < arguments.length; ++i) {
        if (arguments[i] == null) return arguments[i]
      }
      return fn.apply(this, arguments)
    }
  }
}

Errors:

  1. line:10 char:26 -- Use '===' to compare with 'null'.

function checksForSomething = maybe(function (value) {
  // function's true logic
});

Errors:

  1. line:1 char:29 -- Expected '(' and instead saw '='.
  2. line:1 char:36 -- Expected ')' to match '=' from line 1 and instead saw '('.
  3. line:1 char:37 -- Expected '{' and instead saw 'function'.
  4. line:1 char:46 -- Missing name in function declaration.
  5. line:3 char:2 -- Expected an identifier and instead saw ')'.
  6. line:3 char:2 -- Expected an assignment or function call and instead saw an expression.

https://raw.github.com/raganwald/homoiconic/master/2012/12/combinators_2md

function (boundmethod) { 
  return boundmethod() 
}

Errors:

  1. line:1 char:10 -- Missing name in function declaration.

function Cake () {}

extend(Cake.prototype, {
  setFlavour: function (flavour) { 
    return this.flavour = flavour 
  },
  setLayers: function (layers) { 
    return this.layers = layers 
  },
  bake: function () {
    // do some baking
  }
});

var cake = new Cake();
cake.setFlavour('chocolate');
cake.setLayers(3);
cake.bake();

Errors:

  1. line:5 char:26 -- Did you mean to return a conditional instead of an assignment?
  2. line:8 char:25 -- Did you mean to return a conditional instead of an assignment?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions