瀏覽代碼

Code style: Switched to ESLint.

Kamil Piechaczek 8 年之前
父節點
當前提交
39a558d9ae

+ 13 - 13
packages/ckeditor5-list/src/converters.js

@@ -282,7 +282,7 @@ export function modelViewSplitOnInsert( evt, data, consumable, conversionApi ) {
 
 				// Don't merge first list! We want a split in that place (this is why this converter is introduced).
 				if ( i > 0 ) {
-					let mergePos = mergeViewLists( previousList, previousList.nextSibling );
+					const mergePos = mergeViewLists( previousList, previousList.nextSibling );
 
 					// If `mergePos` is in `previousList` it means that the lists got merged.
 					// In this case, we need to fix insert position.
@@ -366,13 +366,13 @@ export function viewModelConverter( evt, data, consumable, conversionApi ) {
 		data.indent++;
 
 		// `listItem`s will be kept in flat structure.
-		let items = new ModelDocumentFragment();
+		const items = new ModelDocumentFragment();
 		items.appendChildren( listItem );
 
 		// Check all children of the converted `<li>`.
 		// At this point we assume there are no "whitespace" view text nodes in view list, between view list items.
 		// This should be handled by `<ul>` and `<ol>` converters.
-		for ( let child of data.input.getChildren() ) {
+		for ( const child of data.input.getChildren() ) {
 			// Let's convert the child.
 			const converted = conversionApi.convertItem( child, consumable, data );
 
@@ -409,7 +409,7 @@ export function cleanList( evt, data, consumable ) {
 		// Caching children because when we start removing them iterating fails.
 		const children = Array.from( data.input.getChildren() );
 
-		for ( let child of children ) {
+		for ( const child of children ) {
 			if ( !child.is( 'li' ) ) {
 				child.remove();
 			}
@@ -436,7 +436,7 @@ export function cleanListItem( evt, data, consumable ) {
 		let foundList = false;
 		let firstNode = true;
 
-		for ( let child of children ) {
+		for ( const child of children ) {
 			if ( foundList && !child.is( 'ul' ) && !child.is( 'ol' ) ) {
 				child.remove();
 			}
@@ -475,12 +475,12 @@ export function modelToViewPosition( evt, data ) {
 
 	if ( modelItem && modelItem.is( 'listItem' ) ) {
 		const viewItem = data.mapper.toViewElement( modelItem );
-		const topmostViewList = viewItem.getAncestors().find( ( element ) => element.is( 'ul' ) || element.is( 'ol' ) );
+		const topmostViewList = viewItem.getAncestors().find( element => element.is( 'ul' ) || element.is( 'ol' ) );
 		const walker = new ViewTreeWalker( {
 			startPosition: ViewPosition.createAt( viewItem, 0 )
 		} );
 
-		for ( let value of walker ) {
+		for ( const value of walker ) {
 			if ( value.type == 'elementStart' && value.item.is( 'li' ) ) {
 				data.viewPosition = value.previousPosition;
 
@@ -652,7 +652,7 @@ function _fixItemsIndent( changePosition, document, batch ) {
 
 			if ( items.length > 0 ) {
 				// Since we are outdenting list items, it is safer to start from the last one (it will maintain correct model state).
-				for ( let item of items.reverse() ) {
+				for ( const item of items.reverse() ) {
 					batch.setAttribute( item.item, 'indent', item.indent );
 				}
 			}
@@ -794,7 +794,7 @@ function getSiblingListItem( modelItemOrPosition, options ) {
 	let item = modelItemOrPosition instanceof ModelElement ? modelItemOrPosition[ direction ] : modelItemOrPosition[ posDirection ];
 
 	while ( item && item.name == 'listItem' ) {
-		let itemIndent = item.getAttribute( 'indent' );
+		const itemIndent = item.getAttribute( 'indent' );
 
 		if (
 			( sameIndent && indent == itemIndent ) ||
@@ -848,7 +848,7 @@ function injectViewList( modelItem, injectedItem, mapper, removePosition ) {
 	if ( prevItem && prevItem.getAttribute( 'indent' ) == modelItem.getAttribute( 'indent' ) ) {
 		// There is a list item with same indent - we found same-level sibling.
 		// Break the list after it. Inserted view item will be inserted in the broken space.
-		let viewItem = mapper.toViewElement( prevItem );
+		const viewItem = mapper.toViewElement( prevItem );
 		insertPosition = viewWriter.breakContainer( ViewPosition.createAfter( viewItem ) );
 	} else {
 		// There is no list item with same indent. Check previous model item.
@@ -889,11 +889,11 @@ function injectViewList( modelItem, injectedItem, mapper, removePosition ) {
 	// if multiple items in model were inserted/moved at once.
 	const nextItem = getSiblingListItem(
 		modelItem,
-		{ biggerIndent: true, getNext: true, isMapped: true, mapper: mapper }
+		{ biggerIndent: true, getNext: true, isMapped: true, mapper }
 	);
 
 	if ( nextItem ) {
-		let viewItem = mapper.toViewElement( nextItem );
+		const viewItem = mapper.toViewElement( nextItem );
 
 		// Break the list between found view item and its preceding `<li>`s.
 		viewWriter.breakContainer( ViewPosition.createBefore( viewItem ) );
@@ -997,7 +997,7 @@ function hoistNestedLists( nextIndent, modelRemoveStartPosition, viewRemoveStart
 
 	// Handle multiple lists. This happens if list item has nested numbered and bulleted lists. Following lists
 	// are inserted after the first list (no need to recalculate insertion position for them).
-	for ( let child of [ ...viewRemovedItem.getChildren() ] ) {
+	for ( const child of [ ...viewRemovedItem.getChildren() ] ) {
 		if ( child.is( 'ul' ) || child.is( 'ol' ) ) {
 			insertPosition = viewWriter.move( ViewRange.createOn( child ), insertPosition ).end;
 

+ 2 - 2
packages/ckeditor5-list/src/indentcommand.js

@@ -69,7 +69,7 @@ export default class IndentCommand extends Command {
 				itemsToChange = itemsToChange.reverse();
 			}
 
-			for ( let item of itemsToChange ) {
+			for ( const item of itemsToChange ) {
 				const indent = item.getAttribute( 'indent' ) + this._indentBy;
 
 				// If indent is lower than 0, it means that the item got outdented when it was not indented.
@@ -92,7 +92,7 @@ export default class IndentCommand extends Command {
 				itemsToChange = itemsToChange.reverse();
 			}
 
-			for ( let item of itemsToChange ) {
+			for ( const item of itemsToChange ) {
 				_fixType( item, batch );
 			}
 		} );

+ 3 - 3
packages/ckeditor5-list/src/list.js

@@ -99,12 +99,12 @@ export default class List extends Plugin {
 		const editor = this.editor;
 		const command = editor.commands.get( commandName );
 
-		editor.ui.componentFactory.add( commandName, ( locale ) => {
+		editor.ui.componentFactory.add( commandName, locale => {
 			const buttonView = new ButtonView( locale );
 
 			buttonView.set( {
-				label: label,
-				icon: icon,
+				label,
+				icon,
 				tooltip: true
 			} );
 

+ 3 - 3
packages/ckeditor5-list/src/listcommand.js

@@ -160,7 +160,7 @@ export default class ListCommand extends Command {
 
 				changes = changes.reverse();
 
-				for ( let item of changes ) {
+				for ( const item of changes ) {
 					batch.setAttribute( item.element, 'indent', item.indent );
 				}
 			}
@@ -187,7 +187,7 @@ export default class ListCommand extends Command {
 				// top-most list affected by the command.
 				let lowestIndent = Number.POSITIVE_INFINITY;
 
-				for ( let item of blocks ) {
+				for ( const item of blocks ) {
 					if ( item.is( 'listItem' ) && item.getAttribute( 'indent' ) < lowestIndent ) {
 						lowestIndent = item.getAttribute( 'indent' );
 					}
@@ -207,7 +207,7 @@ export default class ListCommand extends Command {
 			// For each block element that was in the selection, we will either: turn it to list item,
 			// turn it to paragraph, or change it's type. Or leave it as it is.
 			// Do it in reverse as there might be multiple blocks (same as with changing indents).
-			for ( let element of blocks.reverse() ) {
+			for ( const element of blocks.reverse() ) {
 				if ( turnOff && element.name == 'listItem' ) {
 					// We are turning off and the element is a `listItem` - it should be converted to `paragraph`.
 					// List item specific attributes are removed by post fixer.

+ 3 - 3
packages/ckeditor5-list/src/listengine.js

@@ -72,7 +72,7 @@ export default class ListEngine extends Plugin {
 		// TODO: fix this when changes are converted on `changesDone`.
 		this.editor.document.on( 'change', ( evt, type, changes ) => {
 			if ( type == 'move' ) {
-				for ( let item of changes.range.getItems() ) {
+				for ( const item of changes.range.getItems() ) {
 					if ( item.is( 'listItem' ) ) {
 						editing.mapper.unbindModelElement( item );
 					}
@@ -126,9 +126,9 @@ export default class ListEngine extends Plugin {
 function getViewListItemLength( element ) {
 	let length = 1;
 
-	for ( let child of element.getChildren() ) {
+	for ( const child of element.getChildren() ) {
 		if ( child.name == 'ul' || child.name == 'ol' ) {
-			for ( let item of child.getChildren() ) {
+			for ( const item of child.getChildren() ) {
 				length += getViewListItemLength( item );
 			}
 		}

+ 0 - 1
packages/ckeditor5-list/src/viewlistitemelement.js

@@ -38,7 +38,6 @@ export default class ViewListItemElement extends ViewContainerElement {
 //
 // @returns {Number|null} Block filler offset or `null` if block filler is not needed.
 function getFillerOffset() {
-	/*jshint validthis:true */
 	const hasOnlyLists = !this.isEmpty && ( this.getChild( 0 ).name == 'ul' || this.getChild( 0 ).name == 'ol' );
 
 	return this.isEmpty || hasOnlyLists ? 0 : null;

+ 2 - 5
packages/ckeditor5-list/tests/list.js

@@ -15,18 +15,15 @@ import { getCode } from '@ckeditor/ckeditor5-utils/src/keyboard';
 import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 describe( 'List', () => {
-	let editor, doc, bulletedListButton, numberedListButton, schema;
+	let editor, doc, bulletedListButton, numberedListButton;
 
 	beforeEach( () => {
 		const editorElement = document.createElement( 'div' );
 		document.body.appendChild( editorElement );
 
-		return ClassicTestEditor.create( editorElement, {
-			plugins: [ Paragraph, List ]
-		} )
+		return ClassicTestEditor.create( editorElement, { plugins: [ Paragraph, List ] } )
 			.then( newEditor => {
 				editor = newEditor;
-				schema = editor.document.schema;
 				doc = editor.document;
 
 				bulletedListButton = editor.ui.componentFactory.create( 'bulletedList' );

+ 2 - 0
packages/ckeditor5-list/tests/listcommand.js

@@ -154,6 +154,7 @@ describe( 'ListCommand', () => {
 				} );
 
 				it( 'should handle outdenting sub-items when list item is turned off', () => {
+					/* eslint-disable max-len */
 					// Taken from docs.
 					//
 					// 1  * --------
@@ -189,6 +190,7 @@ describe( 'ListCommand', () => {
 					// 12 * --------
 					// 13    * --------
 					// 14       * --------
+					/* eslint-enable max-len */
 
 					setData(
 						doc,

+ 5 - 2
packages/ckeditor5-list/tests/listengine.js

@@ -90,7 +90,10 @@ describe( 'ListEngine', () => {
 			test( 'numbered list', '<ol><li>a</li><li>b</li></ol>' );
 			test( 'mixed list and content #1', '<p>xxx</p><ul><li>a</li><li>b</li></ul><ol><li>c</li><li>d</li></ol><p>yyy</p>' );
 			test( 'mixed list and content #2', '<ol><li>a</li></ol><p>xxx</p><ul><li>b</li><li>c</li></ul><p>yyy</p><ul><li>d</li></ul>' );
-			test( 'clears incorrect elements', '<ul>x<li>a</li><li>b</li><p>xxx</p>x</ul><p>c</p>', '<ul><li>a</li><li>b</li></ul><p>c</p>' );
+			test(
+				'clears incorrect elements',
+				'<ul>x<li>a</li><li>b</li><p>xxx</p>x</ul><p>c</p>', '<ul><li>a</li><li>b</li></ul><p>c</p>'
+			);
 			test(
 				'clears whitespaces',
 				'<p>foo</p>' +
@@ -3228,7 +3231,7 @@ describe( 'ListEngine', () => {
 	}
 
 	function getViewPath( position ) {
-		let path = [ position.offset ];
+		const path = [ position.offset ];
 		let parent = position.parent;
 
 		while ( parent.parent ) {

+ 5 - 5
packages/ckeditor5-list/tests/viewlistitemelement.js

@@ -9,26 +9,26 @@ import ViewText from '@ckeditor/ckeditor5-engine/src/view/text';
 
 describe( 'ViewListItemElement', () => {
 	it( 'should extend ViewContainerElement', () => {
-		let item = new ViewListItemElement();
+		const item = new ViewListItemElement();
 
 		expect( item ).to.be.instanceof( ViewContainerElement );
 	} );
 
 	it( 'should have li name', () => {
-		let item = new ViewListItemElement();
+		const item = new ViewListItemElement();
 
 		expect( item.name ).to.equal( 'li' );
 	} );
 
 	describe( 'getFillerOffset', () => {
 		it( 'should return 0 if item is empty', () => {
-			let item = new ViewListItemElement();
+			const item = new ViewListItemElement();
 
 			expect( item.getFillerOffset() ).to.equal( 0 );
 		} );
 
 		it( 'should return 0 if item has only lists as children', () => {
-			let item = new ViewListItemElement( null, [
+			const item = new ViewListItemElement( null, [
 				new ViewContainerElement( 'ul', null, [
 					new ViewListItemElement( null, new ViewText( 'foo' ) ),
 					new ViewListItemElement( null, new ViewText( 'bar' ) )
@@ -39,7 +39,7 @@ describe( 'ViewListItemElement', () => {
 		} );
 
 		it( 'should return null if item has non-list contents', () => {
-			let item = new ViewListItemElement( null, new ViewText( 'foo' ) );
+			const item = new ViewListItemElement( null, new ViewText( 'foo' ) );
 
 			expect( item.getFillerOffset() ).to.be.null;
 		} );