angelozerr / tern-lint Goto Github PK
View Code? Open in Web Editor NEWTern plugin to validate JavaScripts files to collect semantic errors
Home Page: http://ternjs.net/
License: MIT License
Tern plugin to validate JavaScripts files to collect semantic errors
Home Page: http://ternjs.net/
License: MIT License
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
Add file origin inside result message
Is it possible to support syntax error like jshint or eslint https://github.com/eslint/eslint ?
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?
I was not carefully looking at this, but after http://stackoverflow.com/questions/22218964/jsdoc-how-to-check-types-for-javascript I see that it is actually applying JSDoc
I feel that JSDoc should be shown in a name, or at least within first few line of README
Publish tern-lint 0.1.0 in the npm registry.
Have this code (node.js + chai)
function(done) {
User.create().exec(function(error, record) {
expect(error).to.exist;
done();
});
});
and get this error: Invalid argument at 1: cannot convert from Function.prototype to String.prototype
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?
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.
Manage this case :
var a = [];
var len = a.length(); // Error, since length is not a function
Produce a builder marker when a variable gets assigned a value of a type that is not the same as the type defined in the JSDoc
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.
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'
Support full lint validation to validate the whole JS files of the tern server. This feature will be helpfull for angelozerr/tern.java#174
originally as angelozerr/tern.java#145 and Nodeclipse/nodeclipse#170
Today lint supports validation messages . I think it should be cool if he could support too quickfix messages. Those quickfix message could be used by the editor to show a popup with list of fixes.
See sample with Eclipse IDE at http://www.tutorialspoint.com/eclipse/eclipse_quick_fix.htm
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 :)
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).
Today severity level is hard coded. It should be good when lint plugin is initialized to customize level of severity
for each validation rules :
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
Today 'indentifier' is an error validation message. Ignore it.
I am creating a pull request to solve this issue
Produce a builder marker when a function returns a different type as specified by it's JSDoc
Just want to let you know, that I've hacked up an Emacs package for tern.lint.
https://github.com/katspaugh/tern-lint.el
It is probably better to write a Flycheck extension, but for now it's just using overlays.
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'
Please give explanation in README about how does this relate to JSHint and ESLint
Support this JSDoc validation :
/**
* @param {number} millis
* @param {function} callback
* */
function sleep(millis, callback) {
setTimeout(function() {
callback();
}, millis);
}
sleep('aaa', 'sdsdsd'); // 'aaa' and 'sdsdsd' must raise an error
This sample comes from http://stackoverflow.com/questions/22218964/jsdoc-how-to-check-types-for-javascript
function f() {
let a = ""; // ERROR: here a is marked as Unused
console.log(a) // ERROR: here a is marked as Unkkwonw
}
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?
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
What is command line installation and usage?
/usr/local/lib/node_modules/tern-lint/bin/lint:94
var found = require.resolve("tern/plugin/" + file); // findFile(plugin +
^
ReferenceError: file is not defined
/**
* @type {Array.<Boolean|String>}
*/
var arr;
arr = [10, "", 10, "", true, {}]; // here 10 and {} raises errors
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
Write the same tests than https://github.com/facebook/flow/tree/master/tests
Ignore warning for this.size :
function CTor() { this.size = 10; }
CTor.prototype.hallo = "hallo";
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.
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.
When run with Node test/run.js outputs "Running all tests:", but it is not clear if it means OK
Produce a builder marker when a function returns mixed types
There should be link to source and who says
e.g. Link to JSDoc declaration (what about if it in in other file?)
and "tern-lint. [configure project](configure project)"
docs https://github.com/angelozerr/tern-lint/wiki/Validation-JSDoc
I found that function getTypeName(type) returns type.prototype.name, but I expect to see actual type. For some cases it looks too weird:
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 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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.