[MediaWiki-commits] [Gerrit] Added type checks to wikibase.api.RepoApi functions - change (mediawiki...WikibaseJavaScriptApi)

2014-12-19 Thread WMDE
Thiemo Mättig (WMDE) has submitted this change and it was merged.

Change subject: Added type checks to wikibase.api.RepoApi functions
..


Added type checks to wikibase.api.RepoApi functions

Actually reflecting parameter documentation in the code instead of relying on 
the back-end handling.
This resolves some wrong documentation as well.
Added tests testing the minimum of parameters required by each function.

Change-Id: I4d043f5cc43852970a489014bc5c106592ccfdc3
---
M .jshintrc
M README.md
M src/RepoApi.js
A tests/.jshintrc
M tests/RepoApi.tests.js
5 files changed, 557 insertions(+), 149 deletions(-)

Approvals:
  Thiemo Mättig (WMDE): Verified; Looks good to me, approved



diff --git a/.jshintrc b/.jshintrc
index 09f9407..239b121 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -1,52 +1,52 @@
 {
-   bitwise : true, // Prohibit bitwise operators (, |, ^, etc.).
+   bitwise: true, // Prohibit bitwise operators (, |, ^, etc.).
camelcase: true, // Force variable names to be camelcase
-   curly : true, // Require {} for every new block or scope.
-   eqeqeq : true, // Require triple equals i.e. `===`.
+   curly: true, // Require {} for every new block or scope.
+   eqeqeq: true, // Require triple equals i.e. `===`.
es3: true, // Prohibit trailing comma in object literals (breaks 
older versions of IE)
-   forin : false, // Don't expect `for in` loops to call 
`hasOwnPrototype`.
+   forin: false, // Don't expect `for in` loops to call 
`hasOwnPrototype`.
freeze: true, // Prohibit overwriting prototypes of native objects 
such as Array, Date and so on.
-   immed : true, // Require immediate invocations to be wrapped in 
parens e.g. `( function(){}() );`
-   latedef : true, // Prohibit variable use before definition.
-   newcap : true, // Require capitalization of all constructor functions 
e.g. `new F()`.
-   noarg : true, // Prohibit use of `arguments.caller` and 
`arguments.callee`.
-   noempty : true, // Prohibit use of empty blocks.
+   immed: true, // Require immediate invocations to be wrapped in parens 
e.g. `( function(){}() );`
+   latedef: true, // Prohibit variable use before definition.
+   newcap: true, // Require capitalization of all constructor functions 
e.g. `new F()`.
+   noarg: true, // Prohibit use of `arguments.caller` and 
`arguments.callee`.
+   noempty: true, // Prohibit use of empty blocks.
nonbsp: true, // Prohibit nbsp
-   nonew : true, // Prohibit use of constructors for side-effects.
-   plusplus : false, // Allow use of `++`  `--`.
-   regexp : true, // Prohibit `.` and `[^...]` in regular expressions.
-   undef : true, // Require all non-global variables be declared before 
they are used.
-   unused : false, // Don't warn about unused variables
-   strict : true, // Require `use strict` pragma in every file.
-   trailing : true, // Prohibit trailing whitespaces.
+   nonew: true, // Prohibit use of constructors for side-effects.
+   plusplus: false, // Allow use of `++`  `--`.
+   regexp: true, // Prohibit `.` and `[^...]` in regular expressions.
+   undef: true, // Require all non-global variables be declared before 
they are used.
+   unused: false, // Don't warn about unused variables
+   strict: true, // Require `use strict` pragma in every file.
+   trailing: true, // Prohibit trailing whitespaces.
 
-   asi : false, // Don't tolerate Automatic Semicolon Insertion (no 
semicolons).
-   boss : false, // Don't tolerate assignments inside if, for  while. 
Usually conditions  loops are for comparison, not assignments.
-   debug : false, // Don't allow debugger statements e.g. browser 
breakpoints.
-   eqnull : false, // Don't tolerate use of `== null`.
-   es5 : false, // Don't allow EcmaScript 5 syntax.
-   esnext : false, // Don't allow ES.next specific features such as 
`const` and `let`.
-   evil : false, // Don't tolerate use of `eval`.
-   expr : false, // Don't tolerate `ExpressionStatement` as Programs.
-   funcscope : false, // Don't tolerate declarations of variables inside 
of control structures while accessing them later from the outside.
-   globalstrict : false, // Don't allow global use strict (also 
enables 'strict').
-   iterator : false, // Don't allow usage of __iterator__ property.
-   lastsemic : false, // Don't tolerat missing semicolons when the it is 
omitted for the last statement in a one-line block.
-   laxbreak : true, // Tolerate unsafe line breaks e.g. `return [\n] x` 
without semicolons.
-   laxcomma : false, // Don't suppress warnings about comma-first coding 
style.
-   loopfunc : false, // Don't allow functions to be defined within loops.
-   multistr : false, // Don't tolerate multi-line strings.
-   onecase : false, // Don't tolerate switches with just one 

[MediaWiki-commits] [Gerrit] Added type checks to wikibase.api.RepoApi functions - change (mediawiki...WikibaseJavaScriptApi)

2014-12-04 Thread Henning Snater (Code Review)
Henning Snater has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/177517

Change subject: Added type checks to wikibase.api.RepoApi functions
..

Added type checks to wikibase.api.RepoApi functions

Actually reflecting parameter documentation in the code instead of relying on 
the back-end handling.
This resolves some wrong documentation as well.
Added tests testing the minimum of parameters required by each function.

Change-Id: I4d043f5cc43852970a489014bc5c106592ccfdc3
---
A .jshintignore
M README.md
M src/RepoApi.js
M tests/RepoApi.tests.js
4 files changed, 445 insertions(+), 94 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseJavaScriptApi 
refs/changes/17/177517/1

diff --git a/.jshintignore b/.jshintignore
new file mode 100644
index 000..711939d
--- /dev/null
+++ b/.jshintignore
@@ -0,0 +1 @@
+./tests
\ No newline at end of file
diff --git a/README.md b/README.md
index f2f54c4..0069924 100644
--- a/README.md
+++ b/README.md
@@ -8,10 +8,11 @@
 * Updated code documentation to be able to generate documentation using JSDuck.
 * `wikibase.api.RepoApi` QUnit tests have been rewritten to not execute actual 
API requests anymore.
 * Added `wikibase.api.RepoApi` QUnit tests for functions not yet tested.
+* Added type checks to `wikibase.api.RepoApi` functions to actually reflect 
parameter documentation in the code instead of relying on the back-end handling.
 
 ### Bugfixes
 * An empty `Entity` may be created by omitting the `data` parameter on 
`wikibase.api.RepoApi.createEntity()` again.
-* `wikibase.api.RepoApi` always submits `normalize` parameter if it is 
specified explicitly (before, `false` resolved to `undefined`).
+* `wikibase.api.RepoApi` functions explicitly submit default parameters if not 
set otherwise.
 
 ### 1.0.1 (2014-11-28)
 
diff --git a/src/RepoApi.js b/src/RepoApi.js
index 6306dce..7d1f97b 100644
--- a/src/RepoApi.js
+++ b/src/RepoApi.js
@@ -53,8 +53,14 @@
 * @return {Function} return.fail
 * @return {string} return.fail.code
 * @return {*} return.fail.error
+*
+* @throws {Error} if a parameter is not specified properly.
 */
createEntity: function( type, data ) {
+   if( typeof type !== 'string' || data  typeof data !== 
'object' ) {
+   throw new Error( 'Parameter not specified properly' );
+   }
+
var params = {
action: 'wbeditentity',
'new': type,
@@ -67,10 +73,10 @@
 * Edits an `Entity`.
 * @see wikibase.api.RepoApi._post
 *
-* @param {String} id `Entity` id.
-* @param {Number} baseRevId Revision id the edit shall be performed on.
-* @param {Object} data The `Entity`'s structure.
-* @param {Boolean} [clear=false] Whether to clear whole entity before 
editing.
+* @param {string} id `Entity` id.
+* @param {number} baseRevId Revision id the edit shall be performed on.
+* @param {Object} [data] The `Entity`'s structure.
+* @param {boolean} [clear] Whether to clear whole entity before 
editing.
 * @return {Object} jQuery.Promise
 * @return {Function} return.done
 * @return {*} return.done.result
@@ -78,17 +84,28 @@
 * @return {Function} return.fail
 * @return {string} return.fail.code
 * @return {*} return.fail.error
+*
+* @throws {Error} if a parameter is not specified properly.
 */
editEntity: function( id, baseRevId, data, clear ) {
+   if(
+   typeof id !== 'string'
+   || typeof baseRevId !== 'number'
+   || typeof data !== 'object'
+   || data  typeof data !== 'object'
+   ) {
+   throw new Error( 'Parameter not specified properly' );
+   }
+
var params = {
action: 'wbeditentity',
id: id,
baserevid: baseRevId,
-   data: JSON.stringify( data )
+   data: JSON.stringify( data || {} )
};
 
-   if ( clear ) {
-   params.clear = true;
+   if( typeof clear === 'boolean' ) {
+   params.clear = clear;
}
 
return this._post( params );
@@ -109,8 +126,19 @@
 * @return {Function} return.fail
 * @return {string} return.fail.code
 * @return {*} return.fail.error
+*
+* @throws {Error} if a parameter is not specified properly.
 */
formatValue: function( dataValue, options, dataType, outputFormat ) {
+   if(
+   typeof dataValue !== 'object'
+   || options  typeof