Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 493276 | Differences between
and this patch

Collapse All | Expand All

(-)a/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/load-rules-async.js (-4 / +10 lines)
Lines 265-272 define([ Link Here
265
    							if(!comments || comments.leading.length < 1) {
265
    							if(!comments || comments.leading.length < 1) {
266
    							    //TODO see https://github.com/jquery/esprima/issues/1071
266
    							    //TODO see https://github.com/jquery/esprima/issues/1071
267
							        comments = context.getComments(node.id);
267
							        comments = context.getComments(node.id);
268
    							} 
268
    							}
269
    							if(!validComment(comments)) {
269
    							if(!validComment(comments) && node.parent && node.parent.type !== "ExportNamedDeclaration") {
270
    								context.report(node.id, ProblemMessages['missing-doc'], {0:node.id.name}, { type: 'decl' });  //$NON-NLS-1$
270
    								context.report(node.id, ProblemMessages['missing-doc'], {0:node.id.name}, { type: 'decl' });  //$NON-NLS-1$
271
    							}
271
    							}
272
        						break;
272
        						break;
Lines 287-293 define([ Link Here
287
        							}
287
        							}
288
        						}
288
        						}
289
        						break;
289
        						break;
290
        				}
290
        					case 'ExportNamedDeclaration' :
291
    							comments = context.getComments(node);
292
    							if(!validComment(comments) && node.declaration && node.declaration.type === "FunctionDeclaration") {
293
    								context.report(node.declaration.id, ProblemMessages['missing-doc'], {0:node.declaration.id.name}, { type: 'decl' });  //$NON-NLS-1$
294
    							}
295
    					}
291
        			}
296
        			}
292
        			catch(ex) {
297
        			catch(ex) {
293
        				Logger.log(ex);
298
        				Logger.log(ex);
Lines 297-303 define([ Link Here
297
        		return {
302
        		return {
298
        			"Property": checkDoc,
303
        			"Property": checkDoc,
299
        			"FunctionDeclaration": checkDoc,
304
        			"FunctionDeclaration": checkDoc,
300
        			"ExpressionStatement": checkDoc
305
        			"ExpressionStatement": checkDoc,
306
        			"ExportNamedDeclaration": checkDoc
301
        		};
307
        		};
302
        },
308
        },
303
        /** @callback */
309
        /** @callback */
(-)a/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/source-code.js (-9 / +14 lines)
Lines 141-149 SourceCode.prototype = { Link Here
141
        if (node) {
141
        if (node) {
142
            return (this.text !== null) ? this.text.slice(Math.max(node.range[0] - (beforeCount || 0), 0),
142
            return (this.text !== null) ? this.text.slice(Math.max(node.range[0] - (beforeCount || 0), 0),
143
                node.range[1] + (afterCount || 0)) : null;
143
                node.range[1] + (afterCount || 0)) : null;
144
        } else {
145
            return this.text;
146
        }
144
        }
145
        return this.text;
147
146
148
    },
147
    },
149
148
Lines 179-188 SourceCode.prototype = { Link Here
179
         * leadingComments/trailingComments. Comments are only left in the
178
         * leadingComments/trailingComments. Comments are only left in the
180
         * Program node comments array if there is no executable code.
179
         * Program node comments array if there is no executable code.
181
         */
180
         */
182
        if (node.type === "Program") {
181
        switch(node.type) {
183
            if (node.body.length === 0) {
182
        	case "Program" :
184
                leadingComments = node.comments;
183
	            if (node.body.length === 0) {
185
            }
184
	                leadingComments = node.comments;
185
	            }
186
	            break;
187
	        case "FunctionDeclaration" :
188
	            var parent = node.parent;
189
	            if (looksLikeExport(parent)) {
190
	               leadingComments = parent.leadingComments || [];
191
	               trailingComments = parent.trailingComments || [];
192
	            }
186
        }
193
        }
187
194
188
        return {
195
        return {
Lines 207-216 SourceCode.prototype = { Link Here
207
            case "FunctionDeclaration":
214
            case "FunctionDeclaration":
208
                if (looksLikeExport(parent)) {
215
                if (looksLikeExport(parent)) {
209
                    return findJSDocComment(parent.leadingComments, line);
216
                    return findJSDocComment(parent.leadingComments, line);
210
                } else {
211
                    return findJSDocComment(node.leadingComments, line);
212
                }
217
                }
213
                break;
218
                return findJSDocComment(node.leadingComments, line);
214
219
215
            case "ClassDeclaration":
220
            case "ClassDeclaration":
216
                return findJSDocComment(node.leadingComments, line);
221
                return findJSDocComment(node.leadingComments, line);
(-)a/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/generateDocCommand.js (-2 / +20 lines)
Lines 28-34 define([ Link Here
28
		this.astManager = ASTManager;
28
		this.astManager = ASTManager;
29
		this.cuprovider = CUProvider;
29
		this.cuprovider = CUProvider;
30
	}
30
	}
31
	
31
32
	/**
33
	 * Check to see if its a ES6 export declaration
34
	 * @param {ASTNode} astNode - any node
35
	 * @returns {boolean} whether the given node represents a export declaration
36
	 * @private
37
	 */
38
	function looksLikeExport(astNode) {
39
	    return astNode.type === "ExportDefaultDeclaration" || astNode.type === "ExportNamedDeclaration" ||
40
	        astNode.type === "ExportAllDeclaration" || astNode.type === "ExportSpecifier";
41
	}
42
32
	Objects.mixin(GenerateDocCommand.prototype, {
43
	Objects.mixin(GenerateDocCommand.prototype, {
33
		/**
44
		/**
34
		 * @callback
45
		 * @callback
Lines 72-78 define([ Link Here
72
					var template;
83
					var template;
73
					var start = parent.range[0];
84
					var start = parent.range[0];
74
					if(parent.type === 'FunctionDeclaration') {
85
					if(parent.type === 'FunctionDeclaration') {
75
						template = this._genTemplate(parent.id.name, parent.params, false, parent.range[0], text);
86
						var len = parent.parents.length-1;
87
						var funcParent = parent.parents[len];
88
						if (funcParent && looksLikeExport(funcParent)) {
89
							template = this._genTemplate(parent.id.name, parent.params, false, funcParent.range[0], text);
90
							start = funcParent.range[0];
91
						} else {
92
							template = this._genTemplate(parent.id.name, parent.params, false, parent.range[0], text);
93
						}
76
					} else if(parent.type === 'Property') {
94
					} else if(parent.type === 'Property') {
77
						template = this._genTemplate(parent.key.name ? parent.key.name : parent.key.value, parent.value.params, true, parent.range[0], text);
95
						template = this._genTemplate(parent.key.name ? parent.key.name : parent.key.value, parent.value.params, true, parent.range[0], text);
78
					} else if(parent.type === 'VariableDeclarator') {
96
					} else if(parent.type === 'VariableDeclarator') {
(-)a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/ternWorkerCore.js (+4 lines)
Lines 428-433 function(Tern, defaultOptions, Deferred, Objects, Serialize, Messages, i18nUtil) Link Here
428
			if (args.env) {
428
			if (args.env) {
429
				query.config.env = args.env;
429
				query.config.env = args.env;
430
			}
430
			}
431
			if (!ternserver.options) {
432
				ternserver.options = Object.create(null);
433
			}
434
			ternserver.options.sourceType = args.sourceType ? args.sourceType : "script";
431
			ternserver.request(
435
			ternserver.request(
432
				{
436
				{
433
					query: query,
437
					query: query,
(-)a/bundles/org.eclipse.orion.client.javascript/web/javascript/validator.js (-3 / +8 lines)
Lines 248-260 define([ Link Here
248
		_validate: function(meta, text, env, deferred, configuration) {
248
		_validate: function(meta, text, env, deferred, configuration) {
249
			// When validating snippets in an html file ignore undefined rule because other scripts may add to the window object
249
			// When validating snippets in an html file ignore undefined rule because other scripts may add to the window object
250
			var rules = config.rules;
250
			var rules = config.rules;
251
			if (configuration) {
251
			if (configuration && configuration.rules) {
252
				rules = configuration.rules;
252
				rules = configuration.rules;
253
			}
253
			}
254
			var files = [{type: 'full', name: meta.location, text: text}]; //$NON-NLS-1$
254
			var files = [{type: 'full', name: meta.location, text: text}]; //$NON-NLS-1$
255
			var args =  {meta: {location: meta.location}, env: env, files: files, rules: rules};
255
			var args =  {meta: {location: meta.location}, env: env, files: files, rules: rules};
256
			if (configuration && configuration.ecmaFeatures) {
256
			if (configuration) {
257
				args.ecmaFeatures = configuration.ecmaFeatures;
257
				if (configuration.ecmaFeatures) {
258
					args.ecmaFeatures = configuration.ecmaFeatures;
259
				}
260
				if (configuration.sourceType) {
261
					args.sourceType = configuration.sourceType;
262
				}
258
			}
263
			}
259
			var request = {request: 'lint', args: args}; //$NON-NLS-1$
264
			var request = {request: 'lint', args: args}; //$NON-NLS-1$
260
			var start = Date.now();
265
			var start = Date.now();
(-)a/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/quickfixTests.js (-1 / +22 lines)
Lines 158-164 define([ Link Here
158
			 */
158
			 */
159
			function getFixes(options) {
159
			function getFixes(options) {
160
				var obj = setup(options);
160
				var obj = setup(options);
161
				return obj.validator.computeProblems(obj.editorContext, {contentType: obj.contentType, rule: options.rule}).then(
161
				return obj.validator.computeProblems(obj.editorContext, {contentType: obj.contentType, rule: options.rule}, options.config).then(
162
					function(problems) {
162
					function(problems) {
163
						try {
163
						try {
164
							var pbs = problems.problems;
164
							var pbs = problems.problems;
Lines 488-493 define([ Link Here
488
					contentType: 'text/html'
488
					contentType: 'text/html'
489
				});
489
				});
490
			});
490
			});
491
			it("export named declaration", function(done) {
492
				var rule = createTestRule("missing-doc");
493
				var expected = {
494
					value: "/**\n"+
495
							" * @name myFunc\n"+
496
							" * @description description\n"+
497
							" * @returns returns\n"+
498
							" */\n",
499
					start: 21,
500
					end: 21
501
				};
502
				return getFixes({
503
					buffer: "var MYCONSTANT = \"\";\nexport function myFunc() { return MYCONSTANT; }",
504
					rule: rule,
505
					expected: expected,
506
					callback: done,
507
					config: {
508
						sourceType: "module"
509
					}
510
				});
511
			}); 
491
		});
512
		});
492
		//CURLY
513
		//CURLY
493
		describe("curly", function() {
514
		describe("curly", function() {
(-)a/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/validatorTests.js (+21 lines)
Lines 1136-1141 define([ Link Here
1136
				// MISSING-DOC DECL------------------------------------------------
1136
				// MISSING-DOC DECL------------------------------------------------
1137
				describe("missing-doc - function declaration", function(){
1137
				describe("missing-doc - function declaration", function(){
1138
					var RULE_ID = "missing-doc";
1138
					var RULE_ID = "missing-doc";
1139
					this.timeout(10000000);
1139
					it("should not flag for root function declaration", function(callback) {
1140
					it("should not flag for root function declaration", function(callback) {
1140
						var config = { rules: {} };
1141
						var config = { rules: {} };
1141
						config.rules[RULE_ID] = [1, {decl: 1}];
1142
						config.rules[RULE_ID] = [1, {decl: 1}];
Lines 1346-1351 define([ Link Here
1346
								worker.getTestState().callback(error);
1347
								worker.getTestState().callback(error);
1347
							});
1348
							});
1348
					});
1349
					});
1350
					it("should flag missing doc for export named declaration", function(callback) {
1351
						var config = { rules: {} };
1352
						config.rules[RULE_ID] = [1, {decl: 1}];
1353
						var features = Object.create(null);
1354
						features.modules = true;
1355
						config.ecmaFeatures = features;
1356
						config.sourceType = "module";
1357
						validate({buffer: "var i = 0; export function myFunc() { return i; };", callback: callback, config: config}).then(
1358
							function (problems) {
1359
								assertProblems(problems, [{
1360
										id: RULE_ID,
1361
										severity: 'warning',
1362
										description: "Missing documentation for function \'myFunc\'.",
1363
										nodeType: "Identifier"
1364
								}]);
1365
							},
1366
							function (error) {
1367
								worker.getTestState().callback(error);
1368
							});
1369
					});
1349
				});
1370
				});
1350
				
1371
				
1351
				// MISSING-DOC EXPR
1372
				// MISSING-DOC EXPR
(-)a/bundles/org.eclipse.orion.client.javascript/web/tern/plugin/doc_comment.js (-1 / +13 lines)
Lines 94-100 Link Here
94
        for (var i = 0; i < node.body.body.length; i++) {
94
        for (var i = 0; i < node.body.body.length; i++) {
95
          var method = node.body.body[i], name
95
          var method = node.body.body[i], name
96
          if (!method.commentsBefore) continue
96
          if (!method.commentsBefore) continue
97
          if (method.kind == "constructor")
97
          if (method.kind === "constructor")
98
            interpretComments(method, method.commentsBefore, scope, node.objType)
98
            interpretComments(method, method.commentsBefore, scope, node.objType)
99
          else if ((name = infer.propName(method)) != "<i>")
99
          else if ((name = infer.propName(method)) != "<i>")
100
            interpretComments(method, method.commentsBefore, scope, proto.getProp(name))
100
            interpretComments(method, method.commentsBefore, scope, proto.getProp(name))
Lines 108-113 Link Here
108
            if (prop) interpretComments(node, node.commentsBefore, scope, prop);
108
            if (prop) interpretComments(node, node.commentsBefore, scope, prop);
109
          }
109
          }
110
        }
110
        }
111
      },
112
      // ORION
113
      ExportNamedDeclaration: function(node, scope) {
114
        if (node.leadingComments && node.declaration && node.declaration.type === 'FunctionDeclaration') {
115
          var commentsBefore = [];
116
          node.leadingComments.forEach(function(comment) {
117
            commentsBefore.push(comment.value);
118
          });
119
          interpretComments(node, commentsBefore, scope,
120
                            scope.getProp(node.declaration.id.name),
121
                            node.declaration.scope.fnType);
122
        }
111
      }
123
      }
112
    }, infer.searchVisitor, scope);
124
    }, infer.searchVisitor, scope);
113
  }
125
  }

Return to bug 493276