Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 239881 Details for
Bug 428040
[eslint] Warn about unnecessary semicolon use
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
fix
unnecessary-semis.patch (text/plain), 8.64 KB, created by
Michael Rennie
on 2014-02-12 15:53:08 EST
(
hide
)
Description:
fix
Filename:
MIME Type:
Creator:
Michael Rennie
Created:
2014-02-12 15:53:08 EST
Size:
8.64 KB
patch
obsolete
>diff --git a/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/load-rules-async.js b/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/load-rules-async.js >index d269861..2816b21 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/load-rules-async.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/load-rules-async.js >@@ -20,8 +20,9 @@ > "eslint/rules/no-unused-vars", > "eslint/rules/no-use-before-define", > "eslint/rules/semi", >+ "eslint/rules/no-semi", > "eslint/rules/missing-doc" >-], function(eqeqeq, no_redeclare, no_undef, no_unused_vars, no_use_before_define, semi, missing_doc) { >+], function(eqeqeq, no_redeclare, no_undef, no_unused_vars, no_use_before_define, semi, no_semi, missing_doc) { > return function() { > return { > "eqeqeq": eqeqeq, >@@ -30,6 +31,7 @@ > "no-unused-vars": no_unused_vars, > "no-use-before-define": no_use_before_define, > "semi": semi, >+ "no-semi": no_semi, > "missing-func-decl-doc" : missing_doc, > "missing-func-expr-doc" : missing_doc > }; >diff --git a/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/rules/no-semi.js b/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/rules/no-semi.js >new file mode 100644 >index 0000000..2f85b57 >--- /dev/null >+++ b/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/rules/no-semi.js >@@ -0,0 +1,47 @@ >+/******************************************************************************* >+ * @license >+ * Copyright (c) 2014 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials are made >+ * available under the terms of the Eclipse Public License v1.0 >+ * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution >+ * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+/*global define module require exports */ >+(function(root, factory) { >+ if(typeof exports === 'object') { >+ module.exports = factory(require, exports, module); >+ } >+ else if(typeof define === 'function' && define.amd) { >+ define(['require', 'exports', 'module'], factory); >+ } >+ else { >+ var req = function(id) {return root[id];}, >+ exp = root, >+ mod = {exports: exp}; >+ root.rules.noundef = factory(req, exp, mod); >+ } >+}(this, function(require, exports, module) { >+ module.exports = function(context) { >+ "use strict"; >+ >+ /** >+ * @description Checks a set of tokens to see if we have an unnecessary semicolon >+ * @private >+ * @param {Object} node The AST node >+ */ >+ function report(node) { >+ var tokens = context.getTokens(node); >+ var t = tokens[tokens.length - 1]; >+ if (t && t.type === "Punctuator" && t.value === ";") { >+ context.report(node, "Unnecessary semicolon.", null, t /* expose the bad token */); >+ } >+ } >+ return { >+ "EmptyStatement": report >+ }; >+ }; >+ return module.exports; >+})); >diff --git a/bundles/org.eclipse.orion.client.javascript/web/eslint/tests/lib/rules/no-semi.js b/bundles/org.eclipse.orion.client.javascript/web/eslint/tests/lib/rules/no-semi.js >new file mode 100644 >index 0000000..4b360b3 >--- /dev/null >+++ b/bundles/org.eclipse.orion.client.javascript/web/eslint/tests/lib/rules/no-semi.js >@@ -0,0 +1,132 @@ >+/******************************************************************************* >+ * @license >+ * Copyright (c) 2014 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials are made >+ * available under the terms of the Eclipse Public License v1.0 >+ * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution >+ * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+/*global describe it module require*/ >+ >+//------------------------------------------------------------------------------ >+// Requirements >+//------------------------------------------------------------------------------ >+ >+var assert = require("assert"), >+ mocha = require("mocha"), >+ eslint = require("../../../lib/eslint"); >+ >+//------------------------------------------------------------------------------ >+// Constants >+//------------------------------------------------------------------------------ >+ >+var RULE_ID = "no-semi"; >+ >+//------------------------------------------------------------------------------ >+// Tests >+//------------------------------------------------------------------------------ >+describe(RULE_ID, function() { >+ /** >+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=428040 >+ */ >+ it("should flag statement multi", function() { >+ var topic = "var a=1;;"; >+ >+ var config = { rules: {} }; >+ config.rules[RULE_ID] = 1; >+ >+ var messages = eslint.verify(topic, config); >+ assert.equal(messages.length, 1); >+ assert.equal(messages[0].ruleId, RULE_ID); >+ assert.equal(messages[0].message, "Unnecessary semicolon."); >+ assert.equal(messages[0].node.type, "EmptyStatement"); >+ }); >+ /** >+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=428040 >+ */ >+ it("should flag function expresson statement multi", function() { >+ var topic = "var a = function() {};;"; >+ >+ var config = { rules: {} }; >+ config.rules[RULE_ID] = 1; >+ >+ var messages = eslint.verify(topic, config); >+ assert.equal(messages.length, 1); >+ assert.equal(messages[0].ruleId, RULE_ID); >+ assert.equal(messages[0].message, "Unnecessary semicolon."); >+ assert.equal(messages[0].node.type, "EmptyStatement"); >+ }); >+ /** >+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=428040 >+ */ >+ it("should flag function declaration", function() { >+ var topic = "function a() {};"; >+ >+ var config = { rules: {} }; >+ config.rules[RULE_ID] = 1; >+ >+ var messages = eslint.verify(topic, config); >+ assert.equal(messages.length, 1); >+ assert.equal(messages[0].ruleId, RULE_ID); >+ assert.equal(messages[0].message, "Unnecessary semicolon."); >+ assert.equal(messages[0].node.type, "EmptyStatement"); >+ }); >+ /** >+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=428040 >+ */ >+ it("should flag empty line", function() { >+ var topic = ";"; >+ >+ var config = { rules: {} }; >+ config.rules[RULE_ID] = 1; >+ >+ var messages = eslint.verify(topic, config); >+ assert.equal(messages.length, 1); >+ assert.equal(messages[0].ruleId, RULE_ID); >+ assert.equal(messages[0].message, "Unnecessary semicolon."); >+ assert.equal(messages[0].node.type, "EmptyStatement"); >+ }); >+ >+ //------------------------------------------------------------------------------ >+ // Should nots >+ //------------------------------------------------------------------------------ >+ /** >+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=428040 >+ */ >+ it("should not flag function expression", function() { >+ var topic = "var a = function() {};"; >+ >+ var config = { rules: {} }; >+ config.rules[RULE_ID] = 1; >+ >+ var messages = eslint.verify(topic, config); >+ assert.equal(messages.length, 0); >+ }); >+ /** >+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=428040 >+ */ >+ it("should not flag expression", function() { >+ var topic = "var a = 4;"; >+ >+ var config = { rules: {} }; >+ config.rules[RULE_ID] = 1; >+ >+ var messages = eslint.verify(topic, config); >+ assert.equal(messages.length, 0); >+ }); >+ /** >+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=428040 >+ */ >+ it("should not flag object expression", function() { >+ var topic = "var a = {};"; >+ >+ var config = { rules: {} }; >+ config.rules[RULE_ID] = 1; >+ >+ var messages = eslint.verify(topic, config); >+ assert.equal(messages.length, 0); >+ }); >+}); >diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/eslint/validator.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/eslint/validator.js >index e0c3c72..03eb7bb 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/eslint/validator.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/eslint/validator.js >@@ -26,6 +26,7 @@ > "no-unused-vars": 1, //$NON-NLS-0$ > "no-use-before-define": 1, //$NON-NLS-0$ > "semi": 1, //$NON-NLS-0$ >+ "no-semi": 1, //$NON-NLS-0$ > "missing-func-decl-doc": [0, 'decl'], //$NON-NLS-0$ //$NON-NLS-1$ > "missing-func-expr-doc": [0, 'expr'] //$NON-NLS-0$ //$NON-NLS-1$ > }, >@@ -207,6 +208,7 @@ > config.setOption("no-unused-vars", properties.validate_no_unused_vars); //$NON-NLS-0$ > config.setOption("no-use-before-define", properties.validate_use_before_define); //$NON-NLS-0$ > config.setOption("semi", properties.validate_missing_semi); //$NON-NLS-0$ >+ config.setOption("no-semi", properties.validate_unnecessary_semi); //$NON-NLS-0$ > } > }); >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 428040
:
239881
|
239882