Răsfoiți Sursa

JSCS and JSHint errors.

Szymon Cofalik 10 ani în urmă
părinte
comite
9ea00683c3

+ 4 - 4
packages/ckeditor5-utils/src/document/operation/changeoperation.js

@@ -146,8 +146,8 @@ CKEDITOR.define( [
 			}
 
 			// Check if they set different value or one of them removes the attribute.
-			return ( this.newAttr == null && otherOperation.newAttr != null ) ||
-				( this.newAttr != null && otherOperation.newAttr == null ) ||
+			return ( this.newAttr === null && otherOperation.newAttr !== null ) ||
+				( this.newAttr !== null && otherOperation.newAttr === null ) ||
 				( !this.newAttr.isEqual( otherOperation.newAttr ) );
 		}
 	}
@@ -224,7 +224,7 @@ CKEDITOR.define( [
 		}
 
 		// Common is a range of nodes that is affected by MoveOperation. So it got moved to other place.
-		if ( common != null ) {
+		if ( common !== null ) {
 			// We substitute original position by the combination of target position and original position.
 			// This reflects that those nodes were moved to another place by MoveOperation.
 			common.start = common.start.getCombined( move.sourcePosition, newTargetPosition );
@@ -264,7 +264,7 @@ CKEDITOR.define( [
 			// We get the range(s) which are only affected by this operation.
 			const ranges = this.range.getDifference( change.range );
 
-			if ( ranges.length == 0 ) {
+			if ( ranges.length === 0 ) {
 				// If there are no such ranges, this operation should not do anything (as it is less important).
 				return [ new NoOperation( this.baseVersion + 1 ) ];
 			} else {

+ 1 - 1
packages/ckeditor5-utils/src/document/operation/insertoperation.js

@@ -120,7 +120,7 @@ CKEDITOR.define( [
 		// MoveOperation removes nodes from their original position. We acknowledge this by proper transformation.
 		const newPosition = this.position.getTransformedByDeletion( move.sourcePosition, move.howMany );
 
-		if ( newPosition == null ) {
+		if ( newPosition === null ) {
 			// This operation's position was inside a node moved by MoveOperation. We substitute that position by
 			// the combination of move target position and insert position. This reflects changes done by MoveOperation.
 

+ 12 - 6
packages/ckeditor5-utils/src/document/operation/moveoperation.js

@@ -158,6 +158,8 @@ CKEDITOR.define( [
 	 * @private
 	 */
 	function getTransformedByInsertOperation( insert, isStrong ) {
+		/*jshint validthis:true */
+
 		// Get a target position from a state "after" nodes are inserted by InsertOperation.
 		const newTargetPosition = this.targetPosition.getTransformedByInsertion( insert.position, insert.nodeList.length, !isStrong );
 
@@ -172,7 +174,7 @@ CKEDITOR.define( [
 				newTargetPosition.clone(),
 				range.end.offset - range.start.offset,
 				this.baseVersion + i + 1
-			)
+			);
 		} );
 	}
 
@@ -187,6 +189,8 @@ CKEDITOR.define( [
 	 * @private
 	 */
 	function getTransformedByMoveOperation( move, isStrong ) {
+		/*jshint validthis:true */
+
 		// There is a special case when both move operations' target positions are inside nodes that are
 		// being moved by the other move operation. So in other words, we move ranges into inside of each other.
 		// This case can't be solved reasonably (on the other hand, it should not happen often).
@@ -241,7 +245,7 @@ CKEDITOR.define( [
 		if ( utils.compareArrays( move.sourcePosition.parentPath, this.sourcePosition.parentPath ) == utils.compareArrays.PREFIX || isStrong ) {
 			const common = thisRange.getCommon( moveRange );
 
-			if ( common != null ) {
+			if ( common !== null ) {
 				// We substitute original position by the combination of target position and original position.
 				// This reflects that those nodes were moved to another place by MoveOperation.
 				common.start = common.start.getCombined( move.sourcePosition, moveTargetPosition );
@@ -256,7 +260,7 @@ CKEDITOR.define( [
 		// First, transform target position by deletion of the other operation's range.
 		let newTargetPosition = this.targetPosition.getTransformedByDeletion( move.sourcePosition, move.howMany );
 
-		if ( newTargetPosition == null ) {
+		if ( newTargetPosition === null ) {
 			// This operation's target position was inside a node moved by the other MoveOperation.
 			// We substitute that position by the combination of the other move target position and this target position.
 			// This reflects changes done by the other MoveOperation.
@@ -271,7 +275,7 @@ CKEDITOR.define( [
 
 		// If we haven't got any ranges this far it means that both operations tried to move the same nodes and
 		// this operation is less important. We return NoOperation in this case.
-		if ( ranges.length == 0 ) {
+		if ( ranges.length === 0 ) {
 			return [ new NoOperation( this.baseVersion + 1 ) ];
 		}
 
@@ -292,9 +296,11 @@ CKEDITOR.define( [
 		} );
 	}
 
+	// Checks whether this MoveOperation targetPosition is inside a node from the source range of given MoveOperation.
 	function _targetsIntoMoveOperation( operation ) {
-		var testTarget = this.targetPosition.getTransformedByDeletion( operation.sourcePosition, operation.howMany );
-		return testTarget == null;
+		/*jshint validthis:true */
+
+		return this.targetPosition.getTransformedByDeletion( operation.sourcePosition, operation.howMany ) === null;
 	}
 
 	return MoveOperation;

+ 7 - 4
packages/ckeditor5-utils/src/document/position.js

@@ -6,10 +6,10 @@
 'use strict';
 
 CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootElement, utils, CKEditorError ) => {
-	const SAME = 0,
-		AFTER = 1,
-		BEFORE = -1,
-		DIFFERENT = -2;
+	const SAME = 0;
+	const AFTER = 1;
+	const BEFORE = -1;
+	const DIFFERENT = -2;
 
 	/**
 	 * Position in the tree. Position is always located before or after a node.
@@ -222,10 +222,13 @@ CKEDITOR.define( [ 'document/rootelement', 'utils', 'ckeditorerror' ], ( RootEle
 			switch ( result ) {
 				case utils.compareArrays.SAME:
 					return SAME;
+
 				case utils.compareArrays.PREFIX:
 					return BEFORE;
+
 				case utils.compareArrays.EXTENSION:
 					return AFTER;
+
 				default:
 					if ( this.path[ result ] < otherPosition.path[ result ] ) {
 						return BEFORE;

+ 10 - 9
packages/ckeditor5-utils/tests/document/operation/changeoperation.js

@@ -29,7 +29,8 @@ const modules = bender.amd.require(
 );
 
 describe( 'ChangeOperation', () => {
-	let Document, Node, ChangeOperation, InsertOperation, MoveOperation, NoOperation, Position, Range, Character, Attribute, NodeList, Text, CKEditorError;
+	let Document, Node, ChangeOperation, InsertOperation, MoveOperation, NoOperation, Position, Range,
+		Character, Attribute, NodeList, Text, CKEditorError;
 
 	before( () => {
 		Document = modules[ 'document/document' ];
@@ -881,7 +882,7 @@ describe( 'ChangeOperation', () => {
 					expectOperation( transOp[ 0 ], expected );
 				} );
 
-				it( 'should get split into two ranges and one of them have it\'s address merged if change range intersects on right-side with moved range', () => {
+				it( 'should get split into two ranges if change range intersects on right-side with moved range', () => {
 					let transformBy = new MoveOperation(
 						new Position( [ 0, 2, 2 ], root ),
 						new Position( [ 2, 4, 1 ], root ),
@@ -905,7 +906,7 @@ describe( 'ChangeOperation', () => {
 					expectOperation( transOp[ 1 ], expected );
 				} );
 
-				it( 'should get split into two ranges and one of them have it\'s address merged if change range intersects on left-side with moved range', () => {
+				it( 'should get split into two ranges if change range intersects on left-side with moved range', () => {
 					let transformBy = new MoveOperation(
 						new Position( [ 0, 2, 0 ], root ),
 						new Position( [ 2, 4, 1 ], root ),
@@ -930,7 +931,7 @@ describe( 'ChangeOperation', () => {
 					expectOperation( transOp[ 1 ], expected );
 				} );
 
-				it( 'should get split into two ranges and one of them have it\'s address merged if change range contains moved range', () => {
+				it( 'should get split into two ranges if change range contains moved range', () => {
 					let transformBy = new MoveOperation(
 						new Position( [ 0, 2, 2 ], root ),
 						new Position( [ 2, 4, 1 ], root ),
@@ -995,7 +996,7 @@ describe( 'ChangeOperation', () => {
 					expectOperation( transOp[ 1 ], expected );
 				} );
 
-				it( 'should get split into three ranges if moved range intersects change range and move-in destination is inside change range', () => {
+				it( 'should get split into three ranges if moved range intersects and move-in destination is inside change range', () => {
 					let transformBy = new MoveOperation(
 						new Position( [ 0, 2, 0 ], root ),
 						new Position( [ 0, 2, 3 ], root ),
@@ -1407,7 +1408,7 @@ describe( 'ChangeOperation', () => {
 					expectOperation( transOp[ 0 ], expected );
 				} );
 
-				it( 'should get split into two ranges and one of them have it\'s address merged if change range intersects on right-side with moved range', () => {
+				it( 'should get split into two ranges if change range intersects on right-side with moved range', () => {
 					let transformBy = new MoveOperation(
 						new Position( [ 2, 1 ], root ),
 						new Position( [ 4 ], root ),
@@ -1431,7 +1432,7 @@ describe( 'ChangeOperation', () => {
 					expectOperation( transOp[ 1 ], expected );
 				} );
 
-				it( 'should get split into two ranges and one of them have it\'s address merged if change range intersects on left-side with moved range', () => {
+				it( 'should get split into two ranges if change range intersects on left-side with moved range', () => {
 					let transformBy = new MoveOperation(
 						new Position( [ 1, 1 ], root ),
 						new Position( [ 0, 0 ], root ),
@@ -1455,7 +1456,7 @@ describe( 'ChangeOperation', () => {
 					expectOperation( transOp[ 1 ], expected );
 				} );
 
-				it( 'should get split into two ranges and one of them have it\'s address merged if change range contains moved range', () => {
+				it( 'should get split into two ranges if change range contains moved range', () => {
 					let transformBy = new MoveOperation(
 						new Position( [ 1, 4 ], root ),
 						new Position( [ 3, 2 ], root ),
@@ -1501,7 +1502,7 @@ describe( 'ChangeOperation', () => {
 					expectOperation( transOp[ 1 ], expected );
 				} );
 
-				it( 'should get split into three ranges if moved range intersects change range and move-in destination is inside change range', () => {
+				it( 'should get split into three ranges if moved range intersects and move-in destination is inside change range', () => {
 					let transformBy = new MoveOperation(
 						new Position( [ 1, 1 ], root ),
 						new Position( [ 2 ], root ),

+ 1 - 1
packages/ckeditor5-utils/tests/document/operation/insertoperation.js

@@ -215,7 +215,7 @@ describe( 'InsertOperation', () => {
 				type: InsertOperation,
 				position: position.clone(),
 				baseVersion: baseVersion + 1
-			}
+			};
 		} );
 
 		function expectOperation( op, params ) {

+ 1 - 1
packages/ckeditor5-utils/tests/document/position.js

@@ -73,7 +73,7 @@ describe( 'position', () => {
 
 	it( 'should throw error if given root is not a RootElement instance', () => {
 		expect( () => {
-			new Position( [ 0 ] )
+			new Position( [ 0 ] );
 		} ).to.throw( CKEditorError, /position-root-not-rootelement/ );
 
 		expect( () => {