Code Monkey home page Code Monkey logo

tern-lint's People

Contributors

angelozerr avatar davidosomething avatar dmitriikovchin avatar metamemoryt avatar rkistner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

tern-lint's Issues

[Lint]: 'callback' is not a function

for code

/**
 * @param {number} millis
 * @param {function} callback
 * */
function sleep(millis, callback) {
    setTimeout(function() {
        callback();
    }, millis);
}



sleep('a','b');

sleep('a','b');

I got only one error for callback(); line:

[Lint]: 'callback' is not a function

.tern-project

{   "ide":{},
    "doc_comment":{"strong":true},
    "lint":{},
    "plugins":{
        "lint":{
            "config":{}
        },
        "node":{}
    },
    "libs": ["ecma5","browser"]
}

I tried with 0.10 and
1.0.0.201507101609

Tern lint shows warning when actual parameter is subtype of expected parameter.

We have type definition for appendChild function from https://github.com/marijnh/tern/blob/master/defs/browser.json:
"appendChild": { "!type": "fn(newElt: +Element) -> +Element", "!url": "https://developer.mozilla.org/en/docs/DOM/Node.appendChild", "!doc": "Adds a node to the end of the list of children of a specified parent node. If the node already exists it is removed from current parent node, then added to new parent node." },
Text.prototype = Node
Node.prototype = Element
So Text is subtype of Element. In parameter validation should we check that actual parameter is subtype of expected type rather than exact expected type?

screenshot from 2015-10-15 13 36 34

New Validation: Incorrect function call

Produce a builder marker when a function is called with the incorrect number and/or type of arguments, based on the @param declarations in the JSDoc (needs to have support for optional parameters and parameters of multiple types (@param {type1|type2|type3} paramname ))

Support validation for RegExp.

Today lint add message error Invalid argument at 1 : cannot convert String.prototype to RegExp.prototype for

var s = '';
s.match('/(chapter \d+(\.\d)*)/i');

although this JS code is valid. Ignore this error and perhaps check the validity of the regexp?

Issue with reassignment of variable

var b = {test: ''};
var a = '';
a = {test: function() {}};
a.test();

This produces an error "'test' is not a function" on the last line, since it thinks that a.test is a string.

This appears to be a bug in Tern itself. When autocompleting, it lists test as a function on a. However, afterwards, it thinks a.test is a string.

This issue is not critical, since it only happens when a variable is reassigned to something of a different type.

Bracket notation

Incorrectly handles properties accessed via the bracket notation.

Imgur

Multiple signatures in jQuery

As described in ternjs/tern#543, using any other jQuery function than the defined jQuery( selector [, context ] ) gives the following error:

$(function() {
  // do something
}
// => Invalid argument at 1: cannot convert from Function.prototype to String.prototype

There are probably many more problems like this.

jQuery end() function is not valid

Use jQuery library with below code:

$( "#content" )
.find( "h3" )
.eq( 2 )
    .html( "new text for the third h3!" )
    .end() // Restores the selection to all h3s in #content
.eq( 0 )
    .html( "new text for the first h3!" );

The end() method is marked as invalid with error: Unknown property 'end'

How to integrate with vim

Hello thanks for this project which seems pretty cool
I guess that if you haven't added in the README how to integrate it with vim it's because you don't know, but if somebody out there feel like explaining how to do it, I will be really thankful :)

Issue with assigning a variable of unknown type

Example:

var a = {};
function test(p) {
   a.t = p;
   var b = a.t;
};

This incorrectly produces "Unknown property t", both for a.t = p and var b = a.t.

Not sure how this can be solved yet. It seems like we'll need to do a check on something other than the type of the property, but instead check if the property is defined on the parent (I think you did something like this originally).

Configure level of severity

Today severity level is hard coded. It should be good when lint plugin is initialized to customize level of severity

  • warning
  • error
  • ignore

for each validation rules :

  • unknow property
  • unknow identifier
  • other?

Validate parameters of function call

It should be good to validate parameters of function call, when function is know. For instance :

document.getElementById('myId')

is OK

document.getElementById(100)

is not OK because the parameter of getElementById is a string

[JSDoc] validate variable declaration

When doc_comment is used with strong, the following code should highlight 'hello' because the variable type waited is Boolean and not a String:

/**
 * @type {Boolean}
 */
 var test = 'hello'

Unknown method 'f'

When we write :

var a = {};
a.f

we have the warning Unknown property 'f' which is displayed. It's OK.

But if we write :

var a = {};
a.f()

we have the warning Unknown property 'f' too which is displayed. It's OK.

It should be perhaps better to have Unknown method 'f'

@rkistner what do you think about that?

Validation JSDoc does not work

I tried https://github.com/angelozerr/tern-lint/wiki/Validation-JSDoc

/**
 * @param {number} millis
 * @param {function} callback
 * */
function sleep(millis, callback) {
    setTimeout(function() {
        callback();
    }, millis);
}



sleep('a','b');

sleep('a','b');

using .tern-project as

{"libs":["ecma5"],"plugins":{
    "doc_comment":{"strong": true},
    "lint": {}
    "node":{}},"ide":{}
}

and then again going to project properties Tern -> Validation -> Lint
and with result like this:

{   "ide":{},
    "doc_comment":{"strong":true},
    "lint":{},
    "plugins":{
        "lint":{
            "config":{}
        },
        "node":{}
    },
    "libs":["ecma5"]
}

How to make it work?

I tried with 0.10 and
1.0.0.201507101609

[JSDoc] Validation for Array

/**
 * @type {Array.<Boolean|String>}
 */
var arr;
arr = [10, "", 10, "", true, {}]; // here 10 and {} raises errors

Validate string content according used tern plugin

Validation stringaccording used tern plugin , can be useful. For instance for node.js, we could validate used module with require :

var fs = require('fs')

is OK, because 'fs' is known module

But

var module = require('Unknown module')

is not OK, because 'Unknown module' isan unknown module

Support AngularJS Dependency Injection (multiple signatures)

When using both the lint and the angular plugins for ternjs and using strict dependency injection I get warnings about invalid parameters.

Example code:

angular
.module("app.greeting", [
  // module deps
])
.directive("helloWorld",
[ // deps as strings go here    <=====  linter complains here
function(/*deps as local params*/) {
}]
.

I get the following linter warning:

Invalid argument at 2: cannot convert from Array.prototype to Function.prototype

Not sure if this is an issue with the angular plugin or the lint plugin or both.
I found the tern type info in the angular plugin here:

It would be nice if we could figure out a way to make functions with more than one signature work properly though.

I can't really use the lint plugin for any of my large projects until this works.

Unknown property 'x'

When we write :

var a = {}
a.

Warning Unknown property 'x' is displayed.

A solution to ignore this error is to do the following test :

node.property.name != "✖"

But it means that we ignore the error although a. is not a valid JS.

@rkistner have you an idea how we could manage this error : ignore it? display other warning label?

Just for your information, I have created the lint demo https://github.com/angelozerr/tern.lint/blob/master/demos/tern-lint.html which contains the same JS content than the tern.js demo http://ternjs.net/doc/demo.html

I have discovered the problem described in this issue. Perhaps we will discover other problem with this demo.

Type mismatch error messages should show actual type rather than type.protoype.

I found that function getTypeName(type) returns type.prototype.name, but I expect to see actual type. For some cases it looks too weird:
wrongtypeisdisplaying

Here since both Employee and Customer have the same proto we get 'Can't convert Person to Person'. But if we used actual types it would be 'Can't convert Employee to Customer', that makes much more sense for me.
I would suggest to change functiongetTypeName(type) in lint.js: 'return (type.proto) ? type.proto.name : "Unknown type";' -> 'return type.name;'

Validate JSDoc argument number

Validate if argument is required or not in JSDoc.
For example:

    /**
     * Return string based on error code
     * @param {number} id - error id
     * @param {string=} message - error message
     * @return {string} localized error string
     */
    error(id, message) { ... }

Here, error() should be marked as invalid, as id is required, whereas error(5) would be valid.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.