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 263603 Details for
Bug 499665
[eslint] update "semi" rule.
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]
Current patch
499665.patch (text/plain), 22.04 KB, created by
Olivier Thomann
on 2016-08-15 16:14:23 EDT
(
hide
)
Description:
Current patch
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2016-08-15 16:14:23 EDT
Size:
22.04 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 fb7ffa0..2269f8c 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 >@@ -2006,48 +2006,182 @@ define([ > }, > /** @callback */ > "semi": function(context) { >- /** >- * @description Check the given node for a trailing semicolon >- * @param {Object} node The AST node >- */ >- function checkForSemicolon(node) { >- var tokens = context.getTokens(node); >- var len = tokens.length; >- var t = tokens[len - 1]; >- if (t && t.type === "Punctuator" && (t.value === ";" || t.value === '.')) { >- return; >- } >- context.report(node, ProblemMessages['semi'], null, t /* expose the bad token */); >- } >- /** >- * @description Check the variable decl node for trailing semicolon >- * @param {Object} node The AST node >- */ >- function checkVariableDeclaration(node) { >- var ancestors = context.getAncestors(node), >- parent = ancestors[ancestors.length - 1], >- parentType = parent.type; >- if ((parentType === "ForStatement" && parent.init === node) || (parentType === "ForInStatement" && parent.left === node) >- || parentType === "ForOfStatement" && parent.left === node) { >- // One of these cases, no semicolon token is required after the VariableDeclaration: >- // for(var x;;) >- // for(var x in y) >- // for(var x of n) >- return; >- } >- checkForSemicolon(node); >- } > >- return { >- "VariableDeclaration": checkVariableDeclaration, >- "ExpressionStatement": checkForSemicolon, >- "ReturnStatement": checkForSemicolon, >- "ThrowStatement": checkForSemicolon, >- "BreakStatement": checkForSemicolon, >- "ContinueStatement": checkForSemicolon >- }; >- }, >- /** @callback */ >+ var OPT_OUT_PATTERN = /[\[\(\/\+\-]/; // One of [(/+- >+ var options = context.options[1]; >+ var never = context.options[0] === "never", >+ exceptOneLine = options && options.omitLastInOneLineBlock === true, >+ sourceCode = context.getSourceCode(); >+ >+ //-------------------------------------------------------------------------- >+ // Helpers >+ //-------------------------------------------------------------------------- >+ >+ /** >+ * Reports a semicolon error with appropriate location and message. >+ * @param {ASTNode} node The node with an extra or missing semicolon. >+ * @param {boolean} missing True if the semicolon is missing. >+ * @returns {void} >+ */ >+ function report(node, missing) { >+ /* >+ if (!missing) { >+ var tokens = context.getTokens(node); >+ var len = tokens.length; >+ var t = tokens[len - 1]; >+ if (t && t.type === "Punctuator" && (t.value === ";" || t.value === '.')) { >+ return; >+ } >+ context.report(node, ProblemMessages['semi'], null, t); >+ } else { >+ context.report(node, ProblemMessages['no-extra-semi']); >+ }*/ >+ var message, >+ lastToken = sourceCode.getLastToken(node), >+ ruleId = null; >+ >+ if (!missing) { >+ message = ProblemMessages["semi"]; >+ } else { >+ message = ProblemMessages["no-extra-semi"]; >+ ruleId = "no-extra-semi"; >+ } >+ >+ context.report({ >+ node: node, >+ loc: lastToken.loc, >+ message: message, >+ ruleId: ruleId, >+ data: lastToken >+ }); >+ } >+ >+ /** >+ * Checks whether a token is a semicolon punctuator. >+ * @param {Token} token The token. >+ * @returns {boolean} True if token is a semicolon punctuator. >+ */ >+ function isSemicolon(token) { >+ return token.type === "Punctuator" && token.value === ";"; >+ } >+ >+ /** >+ * Check if a semicolon is unnecessary, only true if: >+ * - next token is on a new line and is not one of the opt-out tokens >+ * - next token is a valid statement divider >+ * @param {Token} lastToken last token of current node. >+ * @returns {boolean} whether the semicolon is unnecessary. >+ */ >+ function isUnnecessarySemicolon(lastToken) { >+ var isDivider, isOptOutToken, lastTokenLine, nextToken, nextTokenLine; >+ >+ if (!isSemicolon(lastToken)) { >+ return false; >+ } >+ >+ nextToken = sourceCode.getTokenAfter(lastToken); >+ >+ if (!nextToken) { >+ return true; >+ } >+ >+ lastTokenLine = lastToken.loc.end.line; >+ nextTokenLine = nextToken.loc.start.line; >+ isOptOutToken = OPT_OUT_PATTERN.test(nextToken.value); >+ isDivider = nextToken.value === "}" || nextToken.value === ";"; >+ >+ return (lastTokenLine !== nextTokenLine && !isOptOutToken) || isDivider; >+ } >+ >+ /** >+ * Checks a node to see if it's in a one-liner block statement. >+ * @param {ASTNode} node The node to check. >+ * @returns {boolean} whether the node is in a one-liner block statement. >+ */ >+ function isOneLinerBlock(node) { >+ var nextToken = sourceCode.getTokenAfter(node); >+ >+ if (!nextToken || nextToken.value !== "}") { >+ return false; >+ } >+ >+ var parent = node.parent; >+ >+ return parent && parent.type === "BlockStatement" && >+ parent.loc.start.line === parent.loc.end.line; >+ } >+ >+ /** >+ * Checks a node to see if it's followed by a semicolon. >+ * @param {ASTNode} node The node to check. >+ * @returns {void} >+ */ >+ function checkForSemicolon(node) { >+ var lastToken = sourceCode.getLastToken(node); >+ >+ if (never) { >+ if (isUnnecessarySemicolon(lastToken)) { >+ report(node, true); >+ } >+ } else { >+ if (!isSemicolon(lastToken)) { >+ if (!exceptOneLine || !isOneLinerBlock(node)) { >+ report(node); >+ } >+ } else { >+ if (exceptOneLine && isOneLinerBlock(node)) { >+ report(node, true); >+ } >+ } >+ } >+ } >+ >+ /** >+ * Checks to see if there's a semicolon after a variable declaration. >+ * @param {ASTNode} node The node to check. >+ * @returns {void} >+ */ >+ function checkForSemicolonForVariableDeclaration(node) { >+ var ancestors = context.getAncestors(), >+ parentIndex = ancestors.length - 1, >+ parent = ancestors[parentIndex]; >+ >+ if ((parent.type !== "ForStatement" || parent.init !== node) && >+ (!/^For(?:In|Of)Statement/.test(parent.type) || parent.left !== node) >+ ) { >+ checkForSemicolon(node); >+ } >+ } >+ >+ //-------------------------------------------------------------------------- >+ // Public API >+ //-------------------------------------------------------------------------- >+ >+ return { >+ VariableDeclaration: checkForSemicolonForVariableDeclaration, >+ ExpressionStatement: checkForSemicolon, >+ ReturnStatement: checkForSemicolon, >+ ThrowStatement: checkForSemicolon, >+ DoWhileStatement: checkForSemicolon, >+ DebuggerStatement: checkForSemicolon, >+ BreakStatement: checkForSemicolon, >+ ContinueStatement: checkForSemicolon, >+ ImportDeclaration: checkForSemicolon, >+ ExportAllDeclaration: checkForSemicolon, >+ ExportNamedDeclaration: function(node) { >+ if (!node.declaration) { >+ checkForSemicolon(node); >+ } >+ }, >+ ExportDefaultDeclaration: function(node) { >+ if (!/(?:Class|Function)Declaration/.test(node.declaration.type)) { >+ checkForSemicolon(node); >+ } >+ } >+ }; >+ >+ }, >+ /** @callback */ > "unknown-require": function(context) { > var directive; > function checkDirective(node) { >diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/ruleData.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/ruleData.js >index 2528aa3..fb31e79 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/ruleData.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/ruleData.js >@@ -86,7 +86,7 @@ define([ > "no-with" : 1, > "quotes" : [1, "double", {avoidEscape: false, allowTemplateLiterals: false}], > "radix" : 1, >- "semi" : 1, >+ "semi" : [1, "always", {omitLastInOneLineBlock: false}], > "type-checked-consistent-return" : 0, > "unnecessary-nls" : 0, > "unknown-require": 1, >diff --git a/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/rule-context.js b/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/rule-context.js >index d419e29..e09586b 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/rule-context.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/eslint/lib/rule-context.js >@@ -137,10 +137,11 @@ function RuleContext(ruleId, eslint, severity, options, settings, ecmaFeatures, > fix = descriptor.fix(new RuleFixer()); > } > >+ var id = descriptor.ruleId ? descriptor.ruleId : ruleId; > eslint.report( >- ruleId, severity, descriptor.node, >+ id, severity, descriptor.node, > descriptor.loc || descriptor.node.loc.start, >- descriptor.message, descriptor.data, fix >+ descriptor.message, null, null, descriptor.data > ); > > return; >@@ -170,4 +171,3 @@ RuleContext.prototype = { > > return RuleContext; > }); >- >diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/nls/root/messages.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/nls/root/messages.js >index a40cf6d..2b70c4e 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/nls/root/messages.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/nls/root/messages.js >@@ -68,6 +68,8 @@ define({ > 'noNewWrappersFixName': 'Remove \'new\' keyword', > 'noMixedSpacesAndTabs' : 'Mixed spaces and tabs:', > 'missingSemi' : 'Missing semicolons:', >+ 'missingSemiFineGrained' : 'Kinds:', >+ 'missingSemiOmitLastInOneLineBlock' : 'Omit the last semicolon in a one-line block:', > 'unusedVars' : 'Unused variables:', > 'varRedecl' : 'Variable re-declarations:', > 'varShadow': 'Variable shadowing:', >@@ -183,6 +185,8 @@ define({ > 'backtickQuote' : 'backtick (`)', > 'quoteFixName' : 'Fix quotes', > 'yoda' : 'Require or disallow Yoda conditions:', >+ 'always' : 'Always', >+ 'never' : 'Never', > 'yodaKind' : 'Kinds:', > 'yodaExceptRange' : 'Except for range comparisons:', > 'yodaOnlyEquality' : 'Check only for \'==\' and \'===\' operators:', >diff --git a/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/validatorTests.js b/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/validatorTests.js >index 4181a48..f286433 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/validatorTests.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/validatorTests.js >@@ -10691,6 +10691,12 @@ define([ > id: RULE_ID, > severity: 'warning', > description: "Missing semicolon.", >+ nodeType: "VariableDeclaration" >+ }, >+ { >+ id: RULE_ID, >+ severity: 'warning', >+ description: "Missing semicolon.", > nodeType: "ExpressionStatement" > }]); > }, >@@ -11264,6 +11270,115 @@ define([ > worker.getTestState().callback(error); > }); > }); >+ it("should not flag missing semi when 'never' is used", function(callback) { >+ var topic = "var name = \"ESLint\""; >+ var config = { rules: {} }; >+ config.rules[RULE_ID] = [2, "never"]; >+ validate({buffer: topic, callback: callback, config: config}).then( >+ function (problems) { >+ assertProblems(problems, []); >+ }, >+ function (error) { >+ worker.getTestState().callback(error); >+ }); >+ }); >+ it("should not flag missing semi when 'never' is used with omitLastInOneLineBlock = true", function(callback) { >+ var topic = "if (foo) { bar() }"; >+ var config = { rules: {} }; >+ config.rules[RULE_ID] = [2, "always", {omitLastInOneLineBlock: true}]; >+ validate({buffer: topic, callback: callback, config: config}).then( >+ function (problems) { >+ assertProblems(problems, []); >+ }, >+ function (error) { >+ worker.getTestState().callback(error); >+ }); >+ }); >+ it("should not flag missing semi when 'never' is used with omitLastInOneLineBlock = true 2", function(callback) { >+ var topic = "if (foo) { bar(); baz() }"; >+ var config = { rules: {} }; >+ config.rules[RULE_ID] = [2, "always", {omitLastInOneLineBlock: true}]; >+ validate({buffer: topic, callback: callback, config: config}).then( >+ function (problems) { >+ assertProblems(problems, []); >+ }, >+ function (error) { >+ worker.getTestState().callback(error); >+ }); >+ }); >+ it("should flag missing semi when 'never' is used with omitLastInOneLineBlock = true", function(callback) { >+ var topic = >+ "if (foo) {\n" + >+ " bar()\n" + >+ "}"; >+ var config = { rules: {} }; >+ config.rules[RULE_ID] = [2, "always", {omitLastInOneLineBlock: true}]; >+ validate({buffer: topic, callback: callback, config: config}).then( >+ function (problems) { >+ assertProblems(problems, [ >+ { >+ id: RULE_ID, >+ severity: 'error', >+ start: 19, >+ end: 20 >+ }]); >+ }, >+ function (error) { >+ worker.getTestState().callback(error); >+ }); >+ }); >+ it("should flag missing semi when 'never' is used with omitLastInOneLineBlock = true 2", function(callback) { >+ var topic = >+ "if (foo) { bar(); }"; >+ var config = { rules: {} }; >+ config.rules[RULE_ID] = [2, "always", {omitLastInOneLineBlock: true}]; >+ validate({buffer: topic, callback: callback, config: config}).then( >+ function (problems) { >+ assertProblems(problems, [ >+ { >+ id: RULE_ID, >+ severity: 'error', >+ start: 16, >+ end: 17 >+ }]); >+ }, >+ function (error) { >+ worker.getTestState().callback(error); >+ }); >+ }); >+ it("should flag semi when 'never' is set", function(callback) { >+ var topic = "if (foo) { bar(); }"; >+ var config = { rules: {} }; >+ config.rules[RULE_ID] = [2, "never"]; >+ validate({buffer: topic, callback: callback, config: config}).then( >+ function (problems) { >+ assertProblems(problems, [ >+ { >+ id: RULE_ID, >+ severity: 'error', >+ start: 16, >+ end: 17 >+ }]); >+ }, >+ function (error) { >+ worker.getTestState().callback(error); >+ }); >+ }); >+ it("should not flag semi when 'never' is set", function(callback) { >+ var topic = >+ "var name = \"ESLint\"\n" + >+ ";(function() {\n" + >+ "})()"; >+ var config = { rules: {} }; >+ config.rules[RULE_ID] = [2, "never"]; >+ validate({buffer: topic, callback: callback, config: config}).then( >+ function (problems) { >+ assertProblems(problems, []); >+ }, >+ function (error) { >+ worker.getTestState().callback(error); >+ }); >+ }); > }); > > //USE-ISNAN -------------------------------------------------------- >@@ -13293,7 +13408,7 @@ define([ > it("flag invalid import/export", function(callback) { > var topic = "import * as test from \"./files/es_modules_dep1\""; > var config = { rules: {} }; >- config.rules[RULE_ID] = 2; >+ config.rules[RULE_ID] = [2, "never"]; > var features = Object.create(null); > features.modules = false; > config.ecmaFeatures = features; >diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js >index 6d78cfa..a2e45e7 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js >@@ -1465,25 +1465,25 @@ define([ > * ESLint settings > */ > var ignore = 0, warning = 1, error = 2, severities = [ >- {label: javascriptMessages.ignore, value: ignore}, >- {label: javascriptMessages.warning, value: warning}, >- {label: javascriptMessages.error, value: error} >+ {label: javascriptMessages['ignore'], value: ignore}, >+ {label: javascriptMessages['warning'], value: warning}, >+ {label: javascriptMessages['error'], value: error} > ]; > > var doubleQuote = 'double'; > var singleQuote = 'single'; > var backTick = 'backtick'; > var quotes = [ >- { label: javascriptMessages.singleQuote, value: singleQuote }, >- { label: javascriptMessages.doubleQuote, value: doubleQuote }, >- { label: javascriptMessages.backtickQuote, value: backTick } >+ { label: javascriptMessages['singleQuote'], value: singleQuote }, >+ { label: javascriptMessages['doubleQuote'], value: doubleQuote }, >+ { label: javascriptMessages['backtickQuote'], value: backTick } > ]; > > var Never = 'never'; > var Always = 'always'; >- var yodaKinds = [ >- { label: javascriptMessages.yodayAlways, value: Always }, >- { label: javascriptMessages.yodaNever, value: Never }, >+ var kinds = [ >+ { label: javascriptMessages['always'], value: Always }, >+ { label: javascriptMessages['never'], value: Never }, > ]; > provider.registerService("orion.core.setting", //$NON-NLS-1$ > {}, >@@ -1959,7 +1959,7 @@ define([ > name: javascriptMessages["yodaKind"], > type: "string", //$NON-NLS-1$ > defaultValue: Never, >- options: yodaKinds >+ options: kinds > }, > { > id: "yoda:exceptRange", //$NON-NLS-1$ >@@ -2057,6 +2057,19 @@ define([ > defaultValue: warning, > options: severities > }, >+ { id: "semi!1", //$NON-NLS-1$ >+ dependsOn: "semi", >+ name: javascriptMessages["missingSemiFineGrained"], >+ type: "string", //$NON-NLS-1$ >+ defaultValue: Always, >+ options: kinds >+ }, >+ { id: "semi:omitLastInOneLineBlock", //$NON-NLS-1$ >+ dependsOn: "semi", >+ name: javascriptMessages["missingSemiOmitLastInOneLineBlock"], >+ type: "boolean", //$NON-NLS-1$ >+ defaultValue: false >+ }, > { id: "no-mixed-spaces-and-tabs", //$NON-NLS-1$ > name: javascriptMessages["noMixedSpacesAndTabs"], > type: "number", //$NON-NLS-1$ >@@ -2126,25 +2139,25 @@ define([ > var mac = "\r"; > var windows = "\n\r"; > var eof_characters = [ >- {label: javascriptMessages.indentation_unix, value: unix}, >- {label: javascriptMessages.indentation_mac, value: mac}, >- {label: javascriptMessages.indentation_windows, value: windows} >+ {label: javascriptMessages['indentation_unix'], value: unix}, >+ {label: javascriptMessages['indentation_mac'], value: mac}, >+ {label: javascriptMessages['indentation_windows'], value: windows} > ]; > > var space = ' '; > var tab= '\t'; > var indentation_characters = [ >- {label: javascriptMessages.indentation_space, value: space}, >- {label: javascriptMessages.indentation_tab, value: tab}, >+ {label: javascriptMessages['indentation_space'], value: space}, >+ {label: javascriptMessages['indentation_tab'], value: tab}, > ]; > > var before_newline = 'before-newline'; > var after_newline = 'after-newline'; > var preserve_newline = 'preserve-newline'; > var operator_positions = [ >- { label: javascriptMessages.before_newline, value: before_newline}, >- { label: javascriptMessages.after_newline, value: after_newline}, >- { label: javascriptMessages.preserve_newline, value: preserve_newline}, >+ { label: javascriptMessages['before_newline'], value: before_newline}, >+ { label: javascriptMessages['after_newline'], value: after_newline}, >+ { label: javascriptMessages['preserve_newline'], value: preserve_newline}, > ]; > > var collapse_preserve_inline = 'collapse-preserve-inline'; >@@ -2153,11 +2166,11 @@ define([ > var end_expand = 'end-expand'; > var none = 'none'; > var brace_styles = [ >- { label: javascriptMessages.collapse_preserve_inline , value: collapse_preserve_inline}, >- { label: javascriptMessages.collapse , value: collapse}, >- { label: javascriptMessages.expand , value: expand}, >- { label: javascriptMessages.end_expand , value: end_expand}, >- { label: javascriptMessages.none , value: none}, >+ { label: javascriptMessages['collapse_preserve_inline'], value: collapse_preserve_inline}, >+ { label: javascriptMessages['collapse'], value: collapse}, >+ { label: javascriptMessages['expand'], value: expand}, >+ { label: javascriptMessages['end_expand'], value: end_expand}, >+ { label: javascriptMessages['none'], value: none}, > ]; > provider.registerServiceProvider("orion.core.setting", {}, { > settings: [
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 499665
:
263603
|
263617