- Note that this actually causes all the different
for (var i = 0;;)loops throw this warning. A possible solution is to declare those indices at the top of run() etc
new Function, eval, setTimeout(string), setInterval(string), and onevent attributes must not be used except when otherwise impossible in the web scope
while ((a = e * f)) {
Foxtrick.log(a);
}while (a = e * f) {
Foxtrick.log(a);
}Falsy values false, undefined, null, 0, and '' should be compared with === and !== or negated with ! when it does not matter
if (a === '') {
Foxtrick.log('We have ourselves an empty string');
}
if (!a) {
Foxtrick.log('We wanted something better');
// note that empty arrays are not included here!!!
}if (0 == '') {
Foxtrick.log('How did that happen?');
}a = function(param) {
if (param)
return true;
return false;
};a = function(param) {
if (param)
return true;
};var truth;
if (a)
truth = true;
else
truth = false;
var lie = a ? false : true;if (b)
var moreTruth = true;
else
var moreTruth = false;var makeLogger = function(i) {
return function(ev) {
Foxtrick.log('You clicked link number', i);
};
};
var links = doc.querySelectorAll('a');
var ct = links.length;
for (var index = 1; index <= ct; index++) {
Foxtrick.onClick(links[index], makeLogger(index));
}var links = doc.querySelectorAll('a');
var ct = links.length;
for (var index = 1; index <= ct; index++) {
Foxtrick.onClick(links[index], function(ev) {
Foxtrick.log('You clicked link number', index);
Foxtrick.log('I predict it was number', ct);
});
}a = 'multi' +
'line';a = 'multi \
line';var fnc = function() {
};var fnc = function() {
}a = 'a';
a = 'a "quote"';
a = 'a \'quote\'';
a = "a 'quote'";a = "a";if (true) {
Foxtrick.log('OK');
}
else {
Foxtrick.log('OK');
}
try {
throw new Error('Good error');
}
catch (e) {
Foxtrick.log(e);
}
for (; false;) {
Foxtrick.log('Not gonna happen');
}
while (false) {
Foxtrick.log('Not gonna happen');
}
do {
Foxtrick.log('Do once');
}
while (false);
switch ('a') {
case 'a':
Foxtrick.log('OK');
break;
default:
Foxtrick.log('OK');
break;
}
function getA() {
return 'a';
}if(true) {
Foxtrick.log('NOT OK');
}
else{
Foxtrick.log('NOT OK');
}
try{
throw new Error('Bad error');
}
catch(e) {
Foxtrick.log(e);
}
for(; false;) {
Foxtrick.log('Not gonna happen');
}
while(false) {
Foxtrick.log('Not gonna happen');
}
do{
Foxtrick.log('NOT OK');
}
while(false);
switch('a') {
case'a':
Foxtrick.log('NOT OK');
break;
default:
Foxtrick.log('NOT OK');
break;
}
function getA() {
return'a';
}if (x < 0) {
x++;
}
else {
x--;
}
if (x < 0) {
x++;
}
else if (true) {
x--;
}
try {
a = b;
}
catch (err) {}if (x < 0) {
x++;
} else {
x--;
}
try {
a = b;
} catch (err) {}if (true) {
Foxtrick.log('OK');
}if (true){
Foxtrick.log('NOT OK');
}try {
throw new Error('Good error');
}
catch (e) {
Foxtrick.log(e);
}
if (true)
Foxtrick.log('OK');
else
Foxtrick.log('OK');
do {
Foxtrick.log('OK, do once');
}
while (false);try throw new Error('Bad error');
catch (e) Foxtrick.log(e);
do Foxtrick.log('NOT OK');
while (false);try {
a = b;
}
catch (er) {}if (a == b) {}
else {
c = d;
}/**
* doc block
*/
if (true) {
(function(aLongVar,
anEvenLongerVar) {})(); // 1 tab + spaces
}if (true) {
if (false) {
Foxtrick.log('spaces with 1 tab');
}
}
if (true) {
if (false) {
Foxtrick.log('1 tab with spaces');
}
}
/* this one is caught only by google js linter */
if (true) {
Foxtrick.log('1 tab instead of 1 space');
}a = {
a: 1,
bcd: 2,
ef: 'str'
};a = {
a : 1,
bcd: 2,
ef : 'str'
};
/* this one is caught only by google js linter */
var sh = 's';
var longlonglong = 'longlonglong';a = (1 + 2) * 3;a = ( 1 + 2 ) * 3;a = [1];a = [ 1 ];a = { a: 1 };
a = { a: { b: 1 }};a = {a: 1};a = { a: 1 };a = { a : 1 };a = [
1,
2,
];
a = {
a: 'a',
b: 'b',
};a = {
one: 1,
two: 2
};
a = { three: 3, four: 4 };a = {
one: 1
, two: 2
};
var abc = 'abc'
, def = 'def';a = { a: 1, 'default': 2 };
a = { 'bad key name': true };a = { 'a': 1 };x = !y;
y = ++j;
x = y++;x = ! y;
y = ++ j;
x = y ++;a = [1, 2];a = [1,2];
a = [1 ,2];
a = [1 , 2];x = y;
x = y ? 1 : 2;
x = y + 1;
x = y * 2 + 1;
a = x !== y;
x += y;
a = x % 2;
a = x > y;
a = x && y;x= y;
x =y;
x=y;
x = y? 1 : 2;
x = y ?1 : 2;
x = y ? 1 :2;
x = y+ 1;
x = y +1;
x = y* 2 + 1;
x = y *2 + 1;
x = y*2 + 1;
a = x!== y;
a = x !==y;
a = x!==y;
x +=y;
x+= y;
x+=y;
a = x %2;
a = x% 2;
a = x%2;
a = x> y;
a = x >y;
a = x>y;
a = x&& y;
a = x &&y;
a = x &&y;
a = x&&y;
/* this one is caught only by google js linter */
x = y ? 1: 2;var x, y, j;
a = x +
y;
a = x %
y;
a = x =
y;
a = x +=
y;
a = x ===
y;
a = i &&
j;
a = i <
j;
x = y ? 1 : 2;
x = y ?
1 : 2;
x = y ?
1 :
2;
a =
-1; // unarya = x
+ y;
a = x
% y;
a = x
= y;
a = x
+= y;
a = x
=== y;
a = i
&& j;
a = i
< j;
x = y
? 1 : 2;
x = y ? 1
: 2;var a = (function() { return 1; })();
var b = (function() { return 2; }());
var c = (function() { return 3; }).call(this);
var d = (function() { return 3; }.call(this));
var e = (function() { return d; }).apply(this);
var f = (function() { return d; }.apply(this));var g = function() { return 1; }();
var h = function() { return 3; }.call(this);
var i = function() { return d; }.apply(this);a = new B();
a = new this();a = new e();Unfortunately due to limitations of SublimeCodeIntel, all namespaces must be 'defined' in all files where their members are added.
if (!Foxtrick)
var Foxtrick = {};
/**
* foo description
* @param {Type} arg1 param description
* @return {number}
*/
Foxtrick.foo = function(arg1) {
return 0;
};Parameter descriptions are not displayed in SublimeText. Best to explain the tricky parts in function description.
Type examples:
- number, string, array, boolean, object
- Number, String, Array, Boolean, Object
- document, element, node
- HTMLTableElement
- MyClass
array|numberis detected as arraystring[]and anything else with '[' is also detected as array w/o element type hinting- not possible to define nullability, optional params, default values etc
Foxtrick.Bar = {};
Foxtrick.Bar.foo = function(arg1) {
return 0;
};
Foxtrick.Bar.baz = function(arg1) {
return 0;
};Foxtrick.Bar = {
foo: function(arg1) {
return 0;
},
baz: function(arg1) {
return 0;
}
}- DocBlockr
- SublimeCodeIntel
- SublimeLinter
- SublimeLinter-gjslint
- SublimeLinter-jscs
- SublimeLinter-jshint
- https://developers.google.com/closure/utilities/docs/linter_howto
- https://github.com/SublimeLinter/SublimeLinter-jscs#linter-installation
- http://jshint.com/install/
{
"folders":
[
{
"path": "trunk"
}
],
"settings": {
"auto_indent": true,
"default_line_ending": "unix",
"detect_indentation": true,
"dictionary": "Packages/Language - English/en_US.dic",
"draw_white_space": "all",
"ensure_newline_at_eof_on_save": true,
"indent_to_bracket": true,
"indent_subsequent_lines": false,
"rulers":
[
80,
100
],
"show_encoding": true,
"show_line_endings": true,
"spell_check": true,
"smart_indent": true,
"tab_size": 4,
"translate_tabs_to_spaces": false,
"trim_trailing_white_space_on_save": true,
"word_wrap": true,
"wrap_width": 100
},
"SublimeLinter": {
"linters": {
"jshint": {
// "@disable": true,
"ignore_match": [
// spam
//"Line is too long",
//"Strings must use singlequote",
//"'.+' is already defined",
// "'.+' is defined but never used",
//"Use '[=!]==' to compare",
// "'.+' used out of scope",
// "Expected a conditional expression and instead saw an assignment",
// "Don't make functions within a loop",
// "Redefinition of 'Foxtrick'",
// ignore
"Use the function form of \"use strict\"" // global strict
"'.' is already defined", // loop indices
"'e(v|vent)?' is defined but never used" // event listeners
]
},
"jscs": {
// "@disable": true,
"ignore_match": [ // indentation problems
// "Illegal space before opening curly brace"
// "Expected indentation of"
]
},
"gjslint": {
// "@disable": true,
"max_line_length": 91, // counts tabs as 1
"ignore_match": [ // wants spaces instead of tabs
"Illegal tab in whitespace before",
"Illegal tab in comment",
"Missing @this JsDoc",
"Illegal comma at end of (object|array) literal"
]
}
}
}
}{
"codeintel": true,
"sublime_auto_complete": true,
"codeintel_tooltips": "popup",
"codeintel_snippets": true,
"codeintel_enabled_languages":
[
"JavaScript", "XUL", "Python", "HTML", "Python3",
"XML", "HTML5", "Perl", "CSS", "Node.js", "PHP"
],
"codeintel_live": true,
"codeintel_max_recursive_dir_depth": 10,
"codeintel_scan_files_in_project": true,
"codeintel_selected_catalogs": [
"jQuery", "HTML5", "Mozilla Toolkit"
],
"codeintel_config": {
"JavaScript": {
"codeintel_scan_extra_dir": [],
"codeintel_scan_exclude_dir":["/build/", "/min/"],
"codeintel_scan_files_in_project": true,
"codeintel_max_recursive_dir_depth": 5,
"codeintel_selected_catalogs": ["jQuery", "HTML5", "Mozilla Toolkit"]
}
}
}{
"bitwise": true,
"browser": true,
"devel": true,
"eqnull": true,
"freeze": true,
"globalstrict": true,
"immed": true,
"indent": 4,
"jquery": true,
"latedef": true,
"maxlen": 100,
"maxerr": 100,
"moz": true,
"newcap": true,
"noarg": true,
"noempty": true,
"nonew": true,
"nonstandard": true,
"quotmark": "single",
"smarttabs": true,
"strict": true,
"sub": true,
"trailing": true,
"undef": true,
"unused": "strict",
"globals": {"Foxtrick": false}
}{
"requireCurlyBraces": [
"try", "catch", "do"
]
,"requireSpaceAfterKeywords": [
"if", "else", "for", "while", "do", "switch", "return", "try", "catch", "case"
]
,"requireParenthesesAroundIIFE": true
,"disallowEmptyBlocks": true
,"disallowSpacesInsideArrayBrackets": true
,"disallowSpacesInsideParentheses": true
,"requireSpacesInsideObjectBrackets": "allButNested"
,"disallowQuotedKeysInObjects": "allButReserved"
,"disallowSpaceAfterObjectKeys": true
,"requireCommaBeforeLineBreak": true
,"requireOperatorBeforeLineBreak": [
"?", ":", "+", "/", "*", "%", "=", "+=", "-=", "/=", "*=", "%=", "==", "===", "!=", "!==", ">", ">=", "<", "<=", "&&", "||"
]
,"disallowLeftStickedOperators": [
"{", "?", "+", "/", "*", "%", "=", "+=", "-=", "/=", "*=", "%=", "==", "===", "!=", "!==", ">", ">=", "<", "<=", "&&", "||"
]
,"disallowRightStickedOperators": [
"?", ",", ":", "+", "/", "*", "%", "=", "+=", "-=", "/=", "*=", "%=", "==", "===", "!=", "!==", ">", ">=", "<", "<=", "&&", "||"
]
,"requireRightStickedOperators": ["!"]
,"requireLeftStickedOperators": [","]
,"disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"]
,"disallowSpaceBeforePostfixUnaryOperators": ["++", "--"]
,"requireSpaceBeforeBinaryOperators": [
"+", "-", "/", "*", "%", "=", "+=", "-=", "/=", "*=", "%=", "==", "===", "!=", "!==", ">", ">=", "<", "<=", "&&", "||"
]
,"requireSpaceAfterBinaryOperators": [
"+", "-", "/", "*", "%", "=", "+=", "-=", "/=", "*=", "%=", "==", "===", "!=", "!==", ">", ">=", "<", "<=", "&&", "||"
]
,"disallowKeywords": ["with"]
,"disallowMultipleLineStrings": true
,"validateLineBreaks": "LF"
,"validateIndentation": "\t"
,"disallowTrailingWhitespace": true
,"requireKeywordsOnNewLine": ["else", "catch"]
,"requireLineFeedAtFileEnd": true
,"requireCapitalizedConstructors": true
,"validateJSDoc": {
"checkParamNames": true,
"checkRedundantParams": true,
"requireParamTypes": true
}
}