diff options
author | dbeam@chromium.org <dbeam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-12 06:52:34 +0000 |
---|---|---|
committer | dbeam@chromium.org <dbeam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-12 06:52:34 +0000 |
commit | 8cd3da8c415045eaaf33bb672fce9c8533edcdee (patch) | |
tree | b6187115585eb74d17871aadda096be0a3bd6334 /chrome/browser | |
parent | 4ccb2303b07d557335a2ee79851d2f39e19df438 (diff) | |
download | chromium_src-8cd3da8c415045eaaf33bb672fce9c8533edcdee.zip chromium_src-8cd3da8c415045eaaf33bb672fce9c8533edcdee.tar.gz chromium_src-8cd3da8c415045eaaf33bb672fce9c8533edcdee.tar.bz2 |
Make a PRESUBMIT.py check for varNamesLikeThis.
BUG=181573
R=tbreisacher@chromium.org
TEST=c/b/resources/test_presubmit.py, no emails.
Review URL: https://chromiumcodereview.appspot.com/12755006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@187529 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
11 files changed, 75 insertions, 31 deletions
diff --git a/chrome/browser/resources/chromeos/login/screen_error_message.js b/chrome/browser/resources/chromeos/login/screen_error_message.js index d026626..80d7b15 100644 --- a/chrome/browser/resources/chromeos/login/screen_error_message.js +++ b/chrome/browser/resources/chromeos/login/screen_error_message.js @@ -124,7 +124,7 @@ cr.define('login', function() { /** * Sets current state of the error screen. - * @param {String} state New state of the error screen. + * @param {string} state New state of the error screen. * @private */ setState_: function(state) { diff --git a/chrome/browser/resources/chromeos/login/screen_locally_managed_user_creation.js b/chrome/browser/resources/chromeos/login/screen_locally_managed_user_creation.js index ec7bba3..40e55ab 100644 --- a/chrome/browser/resources/chromeos/login/screen_locally_managed_user_creation.js +++ b/chrome/browser/resources/chromeos/login/screen_locally_managed_user_creation.js @@ -34,7 +34,7 @@ cr.define('login', function() { /** * Screen controls. - * @type {array} Array of Buttons. + * @type {!Array} Array of Buttons. */ get buttons() { var buttons = []; @@ -90,8 +90,8 @@ cr.define('login', function() { /** * Show error message. - * @param {String} errorText Text to be displayed. - * @param {bool} recoverable Indicates if error was transiend and process + * @param {string} errorText Text to be displayed. + * @param {boolean} recoverable Indicates if error was transiend and process * can be retried. */ showErrorMessage: function(errorText, recoverable) { @@ -102,7 +102,7 @@ cr.define('login', function() { /** * Enables one particular subpage and hides the rest. - * @param {String} visiblePage - name of subpage (one of 'progress', + * @param {string} visiblePage - name of subpage (one of 'progress', * 'error', 'success') * @private */ diff --git a/chrome/browser/resources/downloads/downloads.js b/chrome/browser/resources/downloads/downloads.js index a1bfaf4..b4f67d6 100644 --- a/chrome/browser/resources/downloads/downloads.js +++ b/chrome/browser/resources/downloads/downloads.js @@ -661,11 +661,11 @@ var downloads, resultsTimeout; * on the download page. It is guaranteed that the updates in this array * are reflected to the download page in a FIFO order. */ -var fifo_results; +var fifoResults; function load() { chrome.send('onPageLoaded'); - fifo_results = new Array(); + fifoResults = []; downloads = new Downloads(); $('term').focus(); setSearch(''); @@ -694,13 +694,13 @@ function load() { } function setSearch(searchText) { - fifo_results.length = 0; + fifoResults.length = 0; downloads.setSearchText(searchText); chrome.send('getDownloads', [searchText.toString()]); } function clearAll() { - fifo_results.length = 0; + fifoResults.length = 0; downloads.clear(); downloads.setSearchText(''); chrome.send('clearAll'); @@ -717,7 +717,7 @@ function downloadsList(results) { if (downloads && downloads.isUpdateNeeded(results)) { if (resultsTimeout) clearTimeout(resultsTimeout); - fifo_results.length = 0; + fifoResults.length = 0; downloads.clear(); downloadUpdated(results); } @@ -733,7 +733,7 @@ function downloadUpdated(results) { if (!downloads) return; - fifo_results = fifo_results.concat(results); + fifoResults = fifoResults.concat(results); tryDownloadUpdatedPeriodically(); } @@ -743,8 +743,8 @@ function downloadUpdated(results) { */ function tryDownloadUpdatedPeriodically() { var start = Date.now(); - while (fifo_results.length) { - var result = fifo_results.shift(); + while (fifoResults.length) { + var result = fifoResults.shift(); downloads.updated(result); // Do as much as we can in 50ms. if (Date.now() - start > 50) { diff --git a/chrome/browser/resources/extension_resource/demo/library.js b/chrome/browser/resources/extension_resource/demo/library.js index 167786a..9e89995 100644 --- a/chrome/browser/resources/extension_resource/demo/library.js +++ b/chrome/browser/resources/extension_resource/demo/library.js @@ -2,4 +2,4 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -var _demo = {}; +var demo = {}; diff --git a/chrome/browser/resources/gesture_config.js b/chrome/browser/resources/gesture_config.js index 02ac671..43b4da1 100644 --- a/chrome/browser/resources/gesture_config.js +++ b/chrome/browser/resources/gesture_config.js @@ -456,12 +456,11 @@ function FlingConfig() { return new GeneralConfig(FLING_TITLE, FLING_PREFIX, FLING_FIELDS); } - /** * WebUI instance for configuring gesture.* and overscroll.* preference values * used by Chrome's gesture recognition system. */ -var gesture_config = { +window.gesture_config = { /** * Build and initialize the gesture configuration form. */ diff --git a/chrome/browser/resources/history/history.js b/chrome/browser/resources/history/history.js index 7656fc4..6bdbb88 100644 --- a/chrome/browser/resources/history/history.js +++ b/chrome/browser/resources/history/history.js @@ -97,7 +97,7 @@ function Visit(result, continued, model) { /** * Records the timestamp of another visit to the same URL as this visit. - * @param {Number} timestamp The timestamp to add. + * @param {number} timestamp The timestamp to add. */ Visit.prototype.addDuplicateTimestamp = function(timestamp) { this.duplicateTimestamps_.push(timestamp); diff --git a/chrome/browser/resources/net_internals/chromeos_view.js b/chrome/browser/resources/net_internals/chromeos_view.js index e370fdd..d49ea9b 100644 --- a/chrome/browser/resources/net_internals/chromeos_view.js +++ b/chrome/browser/resources/net_internals/chromeos_view.js @@ -70,15 +70,15 @@ var CrosView = (function() { function setFileContent_(result) { fileContent = result; // Parse the JSON to get at the top level "Type" property. - var json_object; + var jsonObject; // Ignore any parse errors: they'll get handled in the C++ import code. try { - json_object = JSON.parse(fileContent); + jsonObject = JSON.parse(fileContent); } catch (error) {} // Check if file is encrypted. - if (json_object && - json_object.hasOwnProperty('Type') && - json_object.Type == 'EncryptedConfiguration') { + if (jsonObject && + jsonObject.hasOwnProperty('Type') && + jsonObject.Type == 'EncryptedConfiguration') { promptForPasscode_(); } else { importONCFile_(); diff --git a/chrome/browser/resources/options/autofill_edit_creditcard_overlay.js b/chrome/browser/resources/options/autofill_edit_creditcard_overlay.js index 615f88c..8484969 100644 --- a/chrome/browser/resources/options/autofill_edit_creditcard_overlay.js +++ b/chrome/browser/resources/options/autofill_edit_creditcard_overlay.js @@ -5,9 +5,6 @@ cr.define('options', function() { /** @const */ var OptionsPage = options.OptionsPage; - // The GUID of the loaded credit card. - var guid_; - /** * AutofillEditCreditCardOverlay class * Encapsulated handling of the 'Add Page' overlay page. diff --git a/chrome/browser/resources/options/manage_profile_overlay.js b/chrome/browser/resources/options/manage_profile_overlay.js index 023f884..abf37df 100644 --- a/chrome/browser/resources/options/manage_profile_overlay.js +++ b/chrome/browser/resources/options/manage_profile_overlay.js @@ -95,7 +95,7 @@ cr.define('options', function() { /** * Registers event handlers that are common between create and manage modes. - * @param {String} mode A label that specifies the type of dialog + * @param {string} mode A label that specifies the type of dialog * box which is currently being viewed (i.e. 'create' or * 'manage'). * @param {function()} submitFunction The function that should be called diff --git a/chrome/browser/resources/test_presubmit.py b/chrome/browser/resources/test_presubmit.py index 10e4292d..0889c7b 100755 --- a/chrome/browser/resources/test_presubmit.py +++ b/chrome/browser/resources/test_presubmit.py @@ -245,6 +245,46 @@ class JsStyleGuideTest(SuperMoxTestBase): for line in lines: self.ShouldFailWrapperTypeCheck(line) + def ShouldFailVarNameCheck(self, line): + """Checks that var unix_hacker, $dollar are style errors.""" + error = self.checker.VarNameCheck(1, line) + self.assertNotEqual('', error, + msg='Should be flagged as style error: ' + line) + highlight = self.GetHighlight(line, error) + self.assertFalse('var ' in highlight); + + def ShouldPassVarNameCheck(self, line): + """Checks that variableNamesLikeThis aren't style errors.""" + self.assertEqual('', self.checker.VarNameCheck(1, line), + msg='Should not be flagged as style error: ' + line) + + def testVarNameFails(self): + lines = [ + "var private_;", + " var _super_private", + " var unix_hacker = someFunc();", + ] + for line in lines: + self.ShouldFailVarNameCheck(line) + + def testVarNamePasses(self): + lines = [ + " var namesLikeThis = [];", + " for (var i = 0; i < 10; ++i) { ", + "for (var i in obj) {", + " var one, two, three;", + " var magnumPI = {};", + " var g_browser = 'da browzer';", + "/** @const */ var Bla = options.Bla;", # goog.scope() replacement. + " var $ = function() {", # For legacy reasons. + " var StudlyCaps = cr.define('bla')", # Classes. + " var SCARE_SMALL_CHILDREN = [", # TODO(dbeam): add @const in + # front of all these vars like + "/** @const */ CONST_VAR = 1;", # this line has (<--). + ] + for line in lines: + self.ShouldPassVarNameCheck(line) + class CssStyleGuideTest(SuperMoxTestBase): def setUp(self): diff --git a/chrome/browser/resources/web_dev_style/js_checker.py b/chrome/browser/resources/web_dev_style/js_checker.py index d7f3a8e..cf87303 100644 --- a/chrome/browser/resources/web_dev_style/js_checker.py +++ b/chrome/browser/resources/web_dev_style/js_checker.py @@ -39,7 +39,7 @@ class JSChecker(object): def ChromeSendCheck(self, i, line): """Checks for a particular misuse of 'chrome.send'.""" return self.RegexCheck(i, line, r"chrome\.send\('[^']+'\s*(, \[\])\)", - 'Passing an empty array to chrome.send is unnecessary.') + 'Passing an empty array to chrome.send is unnecessary') def ConstCheck(self, i, line): """Check for use of the 'const' keyword.""" @@ -48,25 +48,31 @@ class JSChecker(object): return '' return self.RegexCheck(i, line, r'(?:^|\s|\()(const)\s', - 'Use var instead of const.') + 'Use /** @const */ var varName; instead of const varName;') def GetElementByIdCheck(self, i, line): """Checks for use of 'document.getElementById' instead of '$'.""" return self.RegexCheck(i, line, r"(document\.getElementById)\('", "Use $('id'), from chrome://resources/js/util.js, instead of " - "document.getElementById('id'))") + "document.getElementById('id')") def InheritDocCheck(self, i, line): """Checks for use of '@inheritDoc' instead of '@override'.""" return self.RegexCheck(i, line, r"\* (@inheritDoc)", - "@inheritDoc is deprecated, use @override instead.") + "@inheritDoc is deprecated, use @override instead") def WrapperTypeCheck(self, i, line): """Check for wrappers (new String()) instead of builtins (string).""" return self.RegexCheck(i, line, r"(?:/\*)?\*.*?@(?:param|return|type) ?" # /** @param/@return/@type r"{[^}]*\b(String|Boolean|Number)\b[^}]*}", # {(Boolean|Number|String)} - "Don't use wrapper types (i.e. new String() or @type {String}).") + "Don't use wrapper types (i.e. new String() or @type {String})") + + def VarNameCheck(self, i, line): + """See the style guide. http://goo.gl/uKir6""" + return self.RegexCheck(i, line, + r"var (?!g_\w+)([a-z]*[_$][\w_$]*)(?<! \$)", + "Please use var namesLikeThis <http://goo.gl/uKir6>") def error_highlight(self, start, length): """Takes a start position and a length, and produces a row of '^'s to @@ -196,6 +202,8 @@ class JSChecker(object): self.ConstCheck(i, line), self.GetElementByIdCheck(i, line), self.InheritDocCheck(i, line), + self.WrapperTypeCheck(i, line), + self.VarNameCheck(i, line), ]) # Use closure_linter to check for several different errors |