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 428040 | Differences between
and this patch

Collapse All | Expand All

(-)a/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/load-rules-async.js (-1 / +3 lines)
Lines 20-27 Link Here
20
	"eslint/rules/no-unused-vars",
20
	"eslint/rules/no-unused-vars",
21
	"eslint/rules/no-use-before-define",
21
	"eslint/rules/no-use-before-define",
22
	"eslint/rules/semi",
22
	"eslint/rules/semi",
23
	"eslint/rules/no-semi",
23
	"eslint/rules/missing-doc"
24
	"eslint/rules/missing-doc"
24
], function(eqeqeq, no_redeclare, no_undef, no_unused_vars, no_use_before_define, semi, missing_doc) {
25
], function(eqeqeq, no_redeclare, no_undef, no_unused_vars, no_use_before_define, semi, no_semi, missing_doc) {
25
	return function() {
26
	return function() {
26
		return {
27
		return {
27
			"eqeqeq": eqeqeq,
28
			"eqeqeq": eqeqeq,
Lines 30-35 Link Here
30
			"no-unused-vars": no_unused_vars,
31
			"no-unused-vars": no_unused_vars,
31
			"no-use-before-define": no_use_before_define,
32
			"no-use-before-define": no_use_before_define,
32
			"semi": semi,
33
			"semi": semi,
34
			"no-semi": no_semi,
33
			"missing-func-decl-doc" : missing_doc,
35
			"missing-func-decl-doc" : missing_doc,
34
			"missing-func-expr-doc" : missing_doc
36
			"missing-func-expr-doc" : missing_doc
35
		};
37
		};
(-)a/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/rules/no-semi.js (+47 lines)
Added Link Here
1
/*******************************************************************************
2
 * @license
3
 * Copyright (c) 2014 IBM Corporation and others.
4
 * All rights reserved. This program and the accompanying materials are made 
5
 * available under the terms of the Eclipse Public License v1.0 
6
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
7
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
8
 *
9
 * Contributors:
10
 *	 IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
/*global define module require exports */
13
(function(root, factory) {
14
	if(typeof exports === 'object') {
15
		module.exports = factory(require, exports, module);
16
	}
17
	else if(typeof define === 'function' && define.amd) {
18
		define(['require', 'exports', 'module'], factory);
19
	}
20
	else {
21
		var req = function(id) {return root[id];},
22
			exp = root,
23
			mod = {exports: exp};
24
		root.rules.noundef = factory(req, exp, mod);
25
	}
26
}(this, function(require, exports, module) {
27
	module.exports = function(context) {
28
		"use strict";
29
		
30
		/**
31
		 * @description Checks a set of tokens to see if we have an unnecessary semicolon
32
		 * @private
33
		 * @param {Object} node The AST node
34
		 */
35
		function report(node) {
36
			var tokens = context.getTokens(node);
37
			var t = tokens[tokens.length - 1];
38
			if (t && t.type === "Punctuator" && t.value === ";") {
39
				context.report(node, "Unnecessary semicolon.", null, t /* expose the bad token */);
40
			}
41
		}
42
		return {
43
			"EmptyStatement": report
44
		};
45
	};
46
	return module.exports;
47
}));
(-)a/bundles/org.eclipse.orion.client.javascript/web/eslint/tests/lib/rules/no-semi.js (+132 lines)
Added Link Here
1
/*******************************************************************************
2
 * @license
3
 * Copyright (c) 2014 IBM Corporation and others.
4
 * All rights reserved. This program and the accompanying materials are made 
5
 * available under the terms of the Eclipse Public License v1.0 
6
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
7
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
8
 *
9
 * Contributors:
10
 *     IBM Corporation - initial API and implementation
11
 *******************************************************************************/
12
/*global describe it module require*/
13
14
//------------------------------------------------------------------------------
15
// Requirements
16
//------------------------------------------------------------------------------
17
18
var assert = require("assert"),
19
	mocha = require("mocha"),
20
	eslint = require("../../../lib/eslint");
21
22
//------------------------------------------------------------------------------
23
// Constants
24
//------------------------------------------------------------------------------
25
26
var RULE_ID = "no-semi";
27
28
//------------------------------------------------------------------------------
29
// Tests
30
//------------------------------------------------------------------------------
31
describe(RULE_ID, function() {
32
	/**
33
	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=428040
34
	 */
35
	it("should flag statement multi", function() {
36
		var topic = "var a=1;;";
37
38
		var config = { rules: {} };
39
		config.rules[RULE_ID] = 1;
40
41
		var messages = eslint.verify(topic, config);
42
		assert.equal(messages.length, 1);
43
		assert.equal(messages[0].ruleId, RULE_ID);
44
		assert.equal(messages[0].message, "Unnecessary semicolon.");
45
		assert.equal(messages[0].node.type, "EmptyStatement");
46
	});
47
	/**
48
	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=428040
49
	 */
50
	it("should flag function expresson statement multi", function() {
51
		var topic = "var a = function() {};;";
52
53
		var config = { rules: {} };
54
		config.rules[RULE_ID] = 1;
55
56
		var messages = eslint.verify(topic, config);
57
		assert.equal(messages.length, 1);
58
		assert.equal(messages[0].ruleId, RULE_ID);
59
		assert.equal(messages[0].message, "Unnecessary semicolon.");
60
		assert.equal(messages[0].node.type, "EmptyStatement");
61
	});
62
	/**
63
	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=428040
64
	 */
65
	it("should flag function declaration", function() {
66
		var topic = "function a() {};";
67
68
		var config = { rules: {} };
69
		config.rules[RULE_ID] = 1;
70
71
		var messages = eslint.verify(topic, config);
72
		assert.equal(messages.length, 1);
73
		assert.equal(messages[0].ruleId, RULE_ID);
74
		assert.equal(messages[0].message, "Unnecessary semicolon.");
75
		assert.equal(messages[0].node.type, "EmptyStatement");
76
	});
77
	/**
78
	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=428040
79
	 */
80
	it("should flag empty line", function() {
81
		var topic = ";";
82
83
		var config = { rules: {} };
84
		config.rules[RULE_ID] = 1;
85
86
		var messages = eslint.verify(topic, config);
87
		assert.equal(messages.length, 1);
88
		assert.equal(messages[0].ruleId, RULE_ID);
89
		assert.equal(messages[0].message, "Unnecessary semicolon.");
90
		assert.equal(messages[0].node.type, "EmptyStatement");
91
	});
92
	
93
	//------------------------------------------------------------------------------
94
	// Should nots
95
	//------------------------------------------------------------------------------
96
	/**
97
	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=428040
98
	 */
99
	it("should not flag function expression", function() {
100
		var topic = "var a = function() {};";
101
102
		var config = { rules: {} };
103
		config.rules[RULE_ID] = 1;
104
105
		var messages = eslint.verify(topic, config);
106
		assert.equal(messages.length, 0);
107
	});
108
	/**
109
	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=428040
110
	 */
111
	it("should not flag expression", function() {
112
		var topic = "var a = 4;";
113
114
		var config = { rules: {} };
115
		config.rules[RULE_ID] = 1;
116
117
		var messages = eslint.verify(topic, config);
118
		assert.equal(messages.length, 0);
119
	});
120
	/**
121
	 * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=428040
122
	 */
123
	it("should not flag object expression", function() {
124
		var topic = "var a = {};";
125
126
		var config = { rules: {} };
127
		config.rules[RULE_ID] = 1;
128
129
		var messages = eslint.verify(topic, config);
130
		assert.equal(messages.length, 0);
131
	});
132
});
(-)a/bundles/org.eclipse.orion.client.javascript/web/javascript/eslint/validator.js (+2 lines)
Lines 26-31 Link Here
26
			"no-unused-vars": 1, //$NON-NLS-0$
26
			"no-unused-vars": 1, //$NON-NLS-0$
27
			"no-use-before-define": 1, //$NON-NLS-0$
27
			"no-use-before-define": 1, //$NON-NLS-0$
28
			"semi": 1, //$NON-NLS-0$
28
			"semi": 1, //$NON-NLS-0$
29
			"no-semi": 1, //$NON-NLS-0$
29
			"missing-func-decl-doc": [0, 'decl'], //$NON-NLS-0$ //$NON-NLS-1$
30
			"missing-func-decl-doc": [0, 'decl'], //$NON-NLS-0$ //$NON-NLS-1$
30
			"missing-func-expr-doc": [0, 'expr'] //$NON-NLS-0$ //$NON-NLS-1$
31
			"missing-func-expr-doc": [0, 'expr'] //$NON-NLS-0$ //$NON-NLS-1$
31
		},
32
		},
Lines 207-212 Link Here
207
			config.setOption("no-unused-vars", properties.validate_no_unused_vars); //$NON-NLS-0$
208
			config.setOption("no-unused-vars", properties.validate_no_unused_vars); //$NON-NLS-0$
208
			config.setOption("no-use-before-define", properties.validate_use_before_define); //$NON-NLS-0$
209
			config.setOption("no-use-before-define", properties.validate_use_before_define); //$NON-NLS-0$
209
			config.setOption("semi", properties.validate_missing_semi); //$NON-NLS-0$
210
			config.setOption("semi", properties.validate_missing_semi); //$NON-NLS-0$
211
			config.setOption("no-semi", properties.validate_unnecessary_semi); //$NON-NLS-0$
210
		}
212
		}
211
	});
213
	});
212
214

Return to bug 428040