r99735 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99734‎ | r99735 | r99736 >
Date:21:32, 13 October 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Fixed some things that jshint was complaining about
Modified paths:
  • /trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js (modified) (history)
  • /trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/tests/hype/es.DocumentModel.test.js
@@ -22,7 +22,7 @@
2323 var obj = {
2424 'type': 'document',
2525 'children': [
26 - {
 26+ {
2727 'type': 'paragraph',
2828 'content': {
2929 'text': 'abc',
@@ -49,51 +49,51 @@
5050 {
5151 'type': 'tableCell',
5252 'children': [
53 - {
54 - 'type': 'paragraph',
55 - 'content': {
56 - 'text': 'a'
57 - }
58 - },
59 - {
60 - 'type': 'list',
61 - 'children': [
62 - {
63 - 'type': 'listItem',
64 - 'attributes': {
65 - 'styles': ['bullet']
66 - },
67 - 'content': {
68 - 'text': 'a'
69 - }
70 - },
71 - {
72 - 'type': 'listItem',
73 - 'attributes': {
74 - 'styles': ['bullet', 'bullet']
75 - },
76 - 'content': {
77 - 'text': 'b'
78 - }
79 - },
80 - {
81 - 'type': 'listItem',
82 - 'attributes': {
83 - 'styles': ['number']
84 - },
85 - 'content': {
86 - 'text': 'c'
87 - }
88 - }
89 - ]
90 - }
91 - ]
 53+ {
 54+ 'type': 'paragraph',
 55+ 'content': {
 56+ 'text': 'a'
 57+ }
 58+ },
 59+ {
 60+ 'type': 'list',
 61+ 'children': [
 62+ {
 63+ 'type': 'listItem',
 64+ 'attributes': {
 65+ 'styles': ['bullet']
 66+ },
 67+ 'content': {
 68+ 'text': 'a'
 69+ }
 70+ },
 71+ {
 72+ 'type': 'listItem',
 73+ 'attributes': {
 74+ 'styles': ['bullet', 'bullet']
 75+ },
 76+ 'content': {
 77+ 'text': 'b'
 78+ }
 79+ },
 80+ {
 81+ 'type': 'listItem',
 82+ 'attributes': {
 83+ 'styles': ['number']
 84+ },
 85+ 'content': {
 86+ 'text': 'c'
 87+ }
 88+ }
 89+ ]
 90+ }
 91+ ]
9292 }
9393 ]
9494 }
9595 ]
9696 },
97 - {
 97+ {
9898 'type': 'paragraph',
9999 'content': {
100100 'text': 'a'
@@ -120,8 +120,8 @@
121121 * [attributes]: {Object} List of symbolic attribute name and literal value pairs
122122 */
123123 var data = [
124 - // 0 - Beginning of paragraph
125 - { 'type': 'paragraph' },
 124+ // 0 - Beginning of paragraph
 125+ { 'type': 'paragraph' },
126126 // 1 - Plain content
127127 'a',
128128 // 2 - Annotated content
@@ -130,39 +130,39 @@
131131 ['c', { 'type': 'italic', 'hash': '#italic' }],
132132 // 4 - End of paragraph
133133 { 'type': '/paragraph' },
134 - // 5 - Beginning of table
 134+ // 5 - Beginning of table
135135 { 'type': 'table' },
136 - // 6 - Beginning of row
 136+ // 6 - Beginning of row
137137 { 'type': 'tableRow' },
138 - // 7 - Beginning of cell
 138+ // 7 - Beginning of cell
139139 { 'type': 'tableCell' },
140 - // 8 - Beginning of paragraph
 140+ // 8 - Beginning of paragraph
141141 { 'type': 'paragraph' },
142142 // 9 - Plain content
143143 'a',
144 - // 10 - End of paragraph
 144+ // 10 - End of paragraph
145145 { 'type': '/paragraph' },
146 - // 11 - Beginning of list
 146+ // 11 - Beginning of list
147147 { 'type': 'list' },
148 - // 12 - Beginning of bullet list item
 148+ // 12 - Beginning of bullet list item
149149 { 'type': 'listItem', 'attributes': { 'styles': ['bullet'] } },
150150 // 13 - Plain content
151151 'a',
152 - // 14 - End of item
 152+ // 14 - End of item
153153 { 'type': '/listItem' },
154 - // 15 - Beginning of nested bullet list item
 154+ // 15 - Beginning of nested bullet list item
155155 { 'type': 'listItem', 'attributes': { 'styles': ['bullet', 'bullet'] } },
156156 // 16 - Plain content
157157 'b',
158 - // 17 - End of item
 158+ // 17 - End of item
159159 { 'type': '/listItem' },
160 - // 18 - Beginning of numbered list item
 160+ // 18 - Beginning of numbered list item
161161 { 'type': 'listItem', 'attributes': { 'styles': ['number'] } },
162162 // 19 - Plain content
163163 'c',
164 - // 20 - End of item
 164+ // 20 - End of item
165165 { 'type': '/listItem' },
166 - // 21 - End of list
 166+ // 21 - End of list
167167 { 'type': '/list' },
168168 // 22 - End of cell
169169 { 'type': '/tableCell' },
@@ -170,11 +170,11 @@
171171 { 'type': '/tableRow' },
172172 // 24 - End of table
173173 { 'type': '/table' },
174 - // 25 - Beginning of paragraph
 174+ // 25 - Beginning of paragraph
175175 { 'type': 'paragraph' },
176176 // 26 - Plain content
177177 'a',
178 - // 27 - End of paragraph
 178+ // 27 - End of paragraph
179179 { 'type': '/paragraph' }
180180 ];
181181
@@ -231,13 +231,13 @@
232232
233233 try {
234234 documentModel[0].getContent( new es.Range( -1, 3 ) );
235 - } catch ( err ) {
 235+ } catch ( negativeIndexError ) {
236236 ok( true, 'getContent throws exceptions when given a range with start < 0' );
237237 }
238238
239239 try {
240240 documentModel[0].getContent( new es.Range( 0, 4 ) );
241 - } catch ( err ) {
 241+ } catch ( outOfRangeError ) {
242242 ok( true, 'getContent throws exceptions when given a range with end > length' );
243243 }
244244
@@ -286,8 +286,8 @@
287287 );
288288
289289 try {
290 - documentModel.prepareElementAttributeChange( 1, 'set', 'test', 1234 )
291 - } catch ( err ) {
 290+ documentModel.prepareElementAttributeChange( 1, 'set', 'test', 1234 );
 291+ } catch ( invalidOffsetError ) {
292292 ok(
293293 true,
294294 'prepareElementAttributeChange throws an exception when offset is not an element'
@@ -295,8 +295,8 @@
296296 }
297297
298298 try {
299 - documentModel.prepareElementAttributeChange( 4, 'set', 'test', 1234 )
300 - } catch ( err ) {
 299+ documentModel.prepareElementAttributeChange( 4, 'set', 'test', 1234 );
 300+ } catch ( closingElementError ) {
301301 ok(
302302 true,
303303 'prepareElementAttributeChange throws an exception when offset is a closing element'
Index: trunk/parsers/wikidom/lib/hype/models/es.DocumentModel.js
@@ -114,7 +114,7 @@
115115 }
116116 // Automatically clean up attributes object
117117 var empty = true;
118 - for ( key in element.attributes ) {
 118+ for ( var key in element.attributes ) {
119119 empty = false;
120120 break;
121121 }
@@ -127,11 +127,15 @@
128128 }
129129
130130 function annotate( to ) {
 131+ var i,
 132+ j,
 133+ length,
 134+ annotation;
131135 // Handle annotations
132136 if ( this.set.length ) {
133 - for ( var i = 0, length = this.set.length; i < length; i++ ) {
134 - var annotation = this.set[i];
135 - for ( var j = this.cursor; j < to; j++ ) {
 137+ for ( i = 0, length = this.set.length; i < length; i++ ) {
 138+ annotation = this.set[i];
 139+ for ( j = this.cursor; j < to; j++ ) {
136140 if ( $.isArray( this.data[j] ) ) {
137141 this.data[j].push( annotation );
138142 } else {
@@ -143,9 +147,9 @@
144148 }
145149 }
146150 if ( this.clear.length ) {
147 - for ( var i = 0, length = this.clear.length; i < length; i++ ) {
148 - var annotation = this.clear[i];
149 - for ( var j = this.cursor; j < to; j++ ) {
 151+ for ( i = 0, length = this.clear.length; i < length; i++ ) {
 152+ annotation = this.clear[i];
 153+ for ( j = this.cursor; j < to; j++ ) {
150154 var index = es.DocumentModel.getIndexOfAnnotation( this.data[j], annotation );
151155 if ( index !== -1 ) {
152156 this.data[j].splice( index, 1 );
@@ -261,7 +265,7 @@
262266
263267 es.DocumentModel.getIndexOfAnnotation = function( character, annotation ) {
264268 if ( annotation === undefined || annotation.type === undefined ) {
265 - throw 'Invalid annotation error. Can not find non-annotation data in character.'
 269+ throw 'Invalid annotation error. Can not find non-annotation data in character.';
266270 }
267271 if ( $.isArray( character ) ) {
268272 // Find the index of a comparable annotation (checking for same value, not reference)
@@ -333,7 +337,9 @@
334338 }
335339 for ( var j = src.start; j < src.end; j++ ) {
336340 // Auto-convert to array
337 - typeof data[j] === 'string' && ( data[j] = [data[j]] );
 341+ if ( typeof data[j] === 'string' ) {
 342+ data[j] = [data[j]];
 343+ }
338344 // Append
339345 data[j].push( dst );
340346 }
@@ -424,7 +430,7 @@
425431 */
426432 es.DocumentModel.prototype.getData = function( range, deep ) {
427433 var start = 0,
428 - end = undefined;
 434+ end;
429435 if ( range !== undefined ) {
430436 range.normalize();
431437 start = Math.max( 0, Math.min( this.data.length, range.start ) );
@@ -481,8 +487,8 @@
482488 for ( var i = 0, length = this.length; i < length; i++ ) {
483489 nodeLength = this[i].getElementLength();
484490 if ( offset >= nodeOffset && offset < nodeOffset + nodeLength ) {
485 - return this[i].length
486 - ? es.DocumentModel.prototype.getNode.call( this[i], offset - nodeOffset ) : this[i];
 491+ return this[i].length ?
 492+ es.DocumentModel.prototype.getNode.call( this[i], offset - nodeOffset ) : this[i];
487493 }
488494 nodeOffset += nodeLength;
489495 }
@@ -525,7 +531,7 @@
526532 range = {
527533 'start': 0,
528534 'end': length
529 - }
 535+ };
530536 }
531537 var offset = this.getOffsetFromNode( node );
532538 if ( offset !== -1 ) {
@@ -583,7 +589,6 @@
584590 * }
585591 * }
586592 */
587 - return tx;
588593 };
589594
590595 /**
@@ -718,10 +723,10 @@
719724 tx.pushRetain( offset );
720725 }
721726 if ( this.data[offset].type === undefined ) {
722 - throw 'Invalid element offset error. Can not set attributes to non-element data.'
 727+ throw 'Invalid element offset error. Can not set attributes to non-element data.';
723728 }
724729 if ( this.data[offset].type[0] === '/' ) {
725 - throw 'Invalid element offset error. Can not set attributes on closing element.'
 730+ throw 'Invalid element offset error. Can not set attributes on closing element.';
726731 }
727732 tx.pushChangeElementAttribute( method, key, value );
728733 if ( offset < this.data.length ) {

Status & tagging log