|
Lines 7701-7706
Link Here
|
| 7701 |
); |
7701 |
); |
| 7702 |
}); |
7702 |
}); |
| 7703 |
}); |
7703 |
}); |
|
|
7704 |
//NO-UNDEF-EXPRESSION ----------------------------------------------------- |
| 7705 |
describe('no-undef-expression', function() { |
| 7706 |
var RULE_ID = "no-undef-expression"; |
| 7707 |
//------------------------------------------------------------------------------ |
| 7708 |
// Test undeclared globals |
| 7709 |
//------------------------------------------------------------------------------ |
| 7710 |
it("Single file undeclared member", function(callback) { |
| 7711 |
var topic = "var v = {a: function(){}}; v.b();"; |
| 7712 |
var config = { rules: {} }; |
| 7713 |
config.rules[RULE_ID] = 1; |
| 7714 |
validate({buffer: topic, callback: callback, config: config}).then( |
| 7715 |
function (problems) { |
| 7716 |
assertProblems(problems, [ |
| 7717 |
{ |
| 7718 |
id: RULE_ID, |
| 7719 |
severity: 'warning', |
| 7720 |
description: "'b' is undefined.", |
| 7721 |
nodeType: "Identifier" |
| 7722 |
}]); |
| 7723 |
}, |
| 7724 |
function (error) { |
| 7725 |
worker.getTestState().callback(error); |
| 7726 |
}); |
| 7727 |
}); |
| 7728 |
it("Single file declared member", function(callback) { |
| 7729 |
var topic = "var v = {a: function(){}}; v.a();"; |
| 7730 |
var config = { rules: {} }; |
| 7731 |
config.rules[RULE_ID] = 1; |
| 7732 |
validate({buffer: topic, callback: callback, config: config}).then( |
| 7733 |
function (problems) { |
| 7734 |
assertProblems(problems, [] |
| 7735 |
); |
| 7736 |
}, |
| 7737 |
function (error) { |
| 7738 |
worker.getTestState().callback(error); |
| 7739 |
}); |
| 7740 |
}); |
| 7741 |
// Right now we assume a type with no properties means that Tern is missing the necessary information |
| 7742 |
it("Single file undeclared member object has no properties", function(callback) { |
| 7743 |
var topic = "var v = {}; v.a;"; |
| 7744 |
var config = { rules: {} }; |
| 7745 |
config.rules[RULE_ID] = 1; |
| 7746 |
validate({buffer: topic, callback: callback, config: config}).then( |
| 7747 |
function (problems) { |
| 7748 |
assertProblems(problems, []); |
| 7749 |
}, |
| 7750 |
function (error) { |
| 7751 |
worker.getTestState().callback(error); |
| 7752 |
}); |
| 7753 |
}); |
| 7754 |
it("Single file multiple undeclared members", function(callback) { |
| 7755 |
var topic = "var v = {a: function(){}}; v.b(); v.c()"; |
| 7756 |
var config = { rules: {} }; |
| 7757 |
config.rules[RULE_ID] = 1; |
| 7758 |
validate({buffer: topic, callback: callback, config: config}).then( |
| 7759 |
function (problems) { |
| 7760 |
assertProblems(problems, [ |
| 7761 |
{ |
| 7762 |
id: RULE_ID, |
| 7763 |
severity: 'warning', |
| 7764 |
description: "'b' is undefined.", |
| 7765 |
nodeType: "Identifier" |
| 7766 |
}, |
| 7767 |
{ |
| 7768 |
id: RULE_ID, |
| 7769 |
severity: 'warning', |
| 7770 |
description: "'c' is undefined.", |
| 7771 |
nodeType: "Identifier" |
| 7772 |
}]); |
| 7773 |
}, |
| 7774 |
function (error) { |
| 7775 |
worker.getTestState().callback(error); |
| 7776 |
}); |
| 7777 |
}); |
| 7778 |
it.skip("Single file wrong undeclared members", function(callback) { |
| 7779 |
var topic = "var v = {a: function(){}}; v.b(); v.c()"; |
| 7780 |
var config = { rules: {} }; |
| 7781 |
config.rules[RULE_ID] = 1; |
| 7782 |
validate({buffer: topic, callback: callback, config: config}).then( |
| 7783 |
function (problems) { |
| 7784 |
assertProblems(problems, [ |
| 7785 |
{ |
| 7786 |
id: RULE_ID, |
| 7787 |
severity: 'warning', |
| 7788 |
description: "'b' is undefined.", |
| 7789 |
nodeType: "Identifier" |
| 7790 |
}, |
| 7791 |
{ |
| 7792 |
id: RULE_ID, |
| 7793 |
severity: 'warning', |
| 7794 |
description: "'c' is undefined.", |
| 7795 |
nodeType: "Identifier" |
| 7796 |
}]); |
| 7797 |
}, |
| 7798 |
function (error) { |
| 7799 |
worker.getTestState().callback(error); |
| 7800 |
}); |
| 7801 |
}); |
| 7802 |
it("Single file multiple member expression", function(callback) { |
| 7803 |
var topic = "var v = {a: {b: {c: function(){}}}}; v.a.b.d(); v.b();"; |
| 7804 |
var config = { rules: {} }; |
| 7805 |
config.rules[RULE_ID] = 1; |
| 7806 |
validate({buffer: topic, callback: callback, config: config}).then( |
| 7807 |
function (problems) { |
| 7808 |
assertProblems(problems, [ |
| 7809 |
{ |
| 7810 |
id: RULE_ID, |
| 7811 |
severity: 'warning', |
| 7812 |
description: "'d' is undefined.", |
| 7813 |
nodeType: "Identifier" |
| 7814 |
}, |
| 7815 |
{ |
| 7816 |
id: RULE_ID, |
| 7817 |
severity: 'warning', |
| 7818 |
description: "'b' is undefined.", |
| 7819 |
nodeType: "Identifier" |
| 7820 |
}]); |
| 7821 |
}, |
| 7822 |
function (error) { |
| 7823 |
worker.getTestState().callback(error); |
| 7824 |
}); |
| 7825 |
}); |
| 7826 |
// TODO Tern only finds the property of v if you run open Decl on a() |
| 7827 |
it.skip("Single file member declared inline", function(callback) { |
| 7828 |
var topic = "var v = {}; v.a = function(){}; v.a();"; |
| 7829 |
var config = { rules: {} }; |
| 7830 |
config.rules[RULE_ID] = 1; |
| 7831 |
validate({buffer: topic, callback: callback, config: config}).then( |
| 7832 |
function (problems) { |
| 7833 |
assertProblems(problems, [ |
| 7834 |
{ |
| 7835 |
id: RULE_ID, |
| 7836 |
severity: 'warning', |
| 7837 |
description: "'a' is undefined.", |
| 7838 |
nodeType: "Identifier" |
| 7839 |
}]); |
| 7840 |
}, |
| 7841 |
function (error) { |
| 7842 |
worker.getTestState().callback(error); |
| 7843 |
}); |
| 7844 |
}); |
| 7845 |
// TODO We check that the property exists, not the actual property type |
| 7846 |
it.skip("Single file declared property is wrong type", function(callback) { |
| 7847 |
var topic = "var v = {a: {}}; v.a();"; |
| 7848 |
var config = { rules: {} }; |
| 7849 |
config.rules[RULE_ID] = 1; |
| 7850 |
validate({buffer: topic, callback: callback, config: config}).then( |
| 7851 |
function (problems) { |
| 7852 |
assertProblems(problems, [ |
| 7853 |
{ |
| 7854 |
id: RULE_ID, |
| 7855 |
severity: 'warning', |
| 7856 |
description: "'a' is undefined.", |
| 7857 |
nodeType: "Identifier" |
| 7858 |
}]); |
| 7859 |
}, |
| 7860 |
function (error) { |
| 7861 |
worker.getTestState().callback(error); |
| 7862 |
}); |
| 7863 |
}); |
| 7864 |
//------------------------------------------------------------------------------ |
| 7865 |
// Test references to globals in other files that Tern knows about |
| 7866 |
//------------------------------------------------------------------------------ |
| 7867 |
it("Multi file 1 - undeclared member", function(callback) { |
| 7868 |
worker.postMessage({request: 'addFile', args: {file: "noUndefExprTest1.js", source: "var noUndefExpr1 = {a: function(){}};"}}); |
| 7869 |
var topic = "noUndefExpr1.b();"; |
| 7870 |
var config = { rules: {} }; |
| 7871 |
config.rules[RULE_ID] = 1; |
| 7872 |
validate({buffer: topic, callback: callback, config: config}).then( |
| 7873 |
function (problems) { |
| 7874 |
assertProblems(problems, [{ |
| 7875 |
id: RULE_ID, |
| 7876 |
severity: 'warning', |
| 7877 |
description: "'b' is undefined.", |
| 7878 |
nodeType: "Identifier" |
| 7879 |
}]); |
| 7880 |
}, |
| 7881 |
function (error) { |
| 7882 |
worker.getTestState().callback(error); |
| 7883 |
} |
| 7884 |
); |
| 7885 |
}); |
| 7886 |
it("Multi file 2 - declared member", function(callback) { |
| 7887 |
worker.postMessage({request: 'addFile', args: {file: "noUndefExprTest2.js", source: "var noUndefExpr2 = {a: function(){}};"}}); |
| 7888 |
var topic = "noUndefExpr2.a();"; |
| 7889 |
var config = { rules: {} }; |
| 7890 |
config.rules[RULE_ID] = 1; |
| 7891 |
validate({buffer: topic, callback: callback, config: config}).then( |
| 7892 |
function (problems) { |
| 7893 |
assertProblems(problems, []); |
| 7894 |
}, |
| 7895 |
function (error) { |
| 7896 |
worker.getTestState().callback(error); |
| 7897 |
} |
| 7898 |
); |
| 7899 |
}); |
| 7900 |
it("Multi file 3 - undeclared member no properties", function(callback) { |
| 7901 |
worker.postMessage({request: 'addFile', args: {file: "noUndefExprTest3.js", source: "var noUndefExpr3 = {};"}}); |
| 7902 |
var topic = "noUndefExpr3.a();"; |
| 7903 |
var config = { rules: {} }; |
| 7904 |
config.rules[RULE_ID] = 1; |
| 7905 |
validate({buffer: topic, callback: callback, config: config}).then( |
| 7906 |
function (problems) { |
| 7907 |
assertProblems(problems, []); |
| 7908 |
}, |
| 7909 |
function (error) { |
| 7910 |
worker.getTestState().callback(error); |
| 7911 |
} |
| 7912 |
); |
| 7913 |
}); |
| 7914 |
}); |
| 7704 |
//NO-UNDEF-INIT ------------------------------------------------- |
7915 |
//NO-UNDEF-INIT ------------------------------------------------- |
| 7705 |
describe('no-unreachable', function() { |
7916 |
describe('no-unreachable', function() { |
| 7706 |
var RULE_ID = "no-undef-init"; |
7917 |
var RULE_ID = "no-undef-init"; |