8
0
فهرست منبع

Aligned the code style.

Piotrek Koszuliński 8 سال پیش
والد
کامیت
e290178914

+ 8 - 5
packages/ckeditor5-autoformat/src/autoformat.js

@@ -83,8 +83,8 @@ export default class Autoformat extends Plugin {
 	 * @private
 	 * @private
 	 */
 	 */
 	_addListAutoformats() {
 	_addListAutoformats() {
-		new BlockAutoformatEngine( this.editor, /^[\*\-]\s$/, 'bulletedList' );
-		new BlockAutoformatEngine( this.editor, /^\d+[\.|)]?\s$/, 'numberedList' );
+		new BlockAutoformatEngine( this.editor, /^[*-]\s$/, 'bulletedList' ); // eslint-disable-line no-new
+		new BlockAutoformatEngine( this.editor, /^\d+[.|)]?\s$/, 'numberedList' ); // eslint-disable-line no-new
 	}
 	}
 
 
 	/**
 	/**
@@ -94,7 +94,8 @@ export default class Autoformat extends Plugin {
 	 * @private
 	 * @private
 	 */
 	 */
 	_addHeadingAutoformats() {
 	_addHeadingAutoformats() {
-		new BlockAutoformatEngine( this.editor, /^(#{1,3})\s$/, ( context ) => {
+		// eslint-disable-next-line no-new
+		new BlockAutoformatEngine( this.editor, /^(#{1,3})\s$/, context => {
 			const { batch, match } = context;
 			const { batch, match } = context;
 			const headingLevel = match[ 1 ].length;
 			const headingLevel = match[ 1 ].length;
 
 
@@ -114,12 +115,14 @@ export default class Autoformat extends Plugin {
 	 * @private
 	 * @private
 	 */
 	 */
 	_addInlineAutoformats() {
 	_addInlineAutoformats() {
-		new InlineAutoformatEngine( this.editor, /(\*\*)([^\*]+)(\*\*)$/g, 'bold' );
+		/* eslint-disable no-new */
+		new InlineAutoformatEngine( this.editor, /(\*\*)([^*]+)(\*\*)$/g, 'bold' );
 		new InlineAutoformatEngine( this.editor, /(__)([^_]+)(__)$/g, 'bold' );
 		new InlineAutoformatEngine( this.editor, /(__)([^_]+)(__)$/g, 'bold' );
 
 
 		// The italic autoformatter cannot be triggered by the bold markers, so we need to check the
 		// The italic autoformatter cannot be triggered by the bold markers, so we need to check the
 		// text before the pattern (e.g. `(?:^|[^\*])`).
 		// text before the pattern (e.g. `(?:^|[^\*])`).
-		new InlineAutoformatEngine( this.editor, /(?:^|[^\*])(\*)([^\*_]+)(\*)$/g, 'italic' );
+		new InlineAutoformatEngine( this.editor, /(?:^|[^*])(\*)([^*_]+)(\*)$/g, 'italic' );
 		new InlineAutoformatEngine( this.editor, /(?:^|[^_])(_)([^_]+)(_)$/g, 'italic' );
 		new InlineAutoformatEngine( this.editor, /(?:^|[^_])(_)([^_]+)(_)$/g, 'italic' );
+		/* eslint-enable no-new */
 	}
 	}
 }
 }

+ 1 - 1
packages/ckeditor5-autoformat/src/blockautoformatengine.js

@@ -61,7 +61,7 @@ export default class BlockAutoformatEngine {
 			// We assume that the actual command name was provided.
 			// We assume that the actual command name was provided.
 			const command = callbackOrCommand;
 			const command = callbackOrCommand;
 
 
-			callback = ( context ) => {
+			callback = context => {
 				const { batch } = context;
 				const { batch } = context;
 
 
 				// Create new batch for removal and command execution.
 				// Create new batch for removal and command execution.

+ 7 - 7
packages/ckeditor5-autoformat/src/inlineautoformatengine.js

@@ -88,10 +88,10 @@ export default class InlineAutoformatEngine {
 		}
 		}
 
 
 		// A test callback run on changed text.
 		// A test callback run on changed text.
-		testCallback = testCallback || ( ( text ) => {
+		testCallback = testCallback || ( text => {
 			let result;
 			let result;
-			let remove = [];
-			let format = [];
+			const remove = [];
+			const format = [];
 
 
 			while ( ( result = regExp.exec( text ) ) !== null ) {
 			while ( ( result = regExp.exec( text ) ) !== null ) {
 				// There should be full match and 3 capture groups.
 				// There should be full match and 3 capture groups.
@@ -134,7 +134,7 @@ export default class InlineAutoformatEngine {
 
 
 		// A format callback run on matched text.
 		// A format callback run on matched text.
 		formatCallback = formatCallback || ( ( batch, validRanges ) => {
 		formatCallback = formatCallback || ( ( batch, validRanges ) => {
-			for ( let range of validRanges ) {
+			for ( const range of validRanges ) {
 				batch.setAttribute( range, command, true );
 				batch.setAttribute( range, command, true );
 			}
 			}
 		} );
 		} );
@@ -156,7 +156,7 @@ export default class InlineAutoformatEngine {
 			const rangesToFormat = [];
 			const rangesToFormat = [];
 
 
 			// Apply format before deleting text.
 			// Apply format before deleting text.
-			ranges.format.forEach( ( range ) => {
+			ranges.format.forEach( range => {
 				if ( range[ 0 ] === undefined || range[ 1 ] === undefined ) {
 				if ( range[ 0 ] === undefined || range[ 1 ] === undefined ) {
 					return;
 					return;
 				}
 				}
@@ -170,7 +170,7 @@ export default class InlineAutoformatEngine {
 			const rangesToRemove = [];
 			const rangesToRemove = [];
 
 
 			// Reverse order to not mix the offsets while removing.
 			// Reverse order to not mix the offsets while removing.
-			ranges.remove.slice().reverse().forEach( ( range ) => {
+			ranges.remove.slice().reverse().forEach( range => {
 				if ( range[ 0 ] === undefined || range[ 1 ] === undefined ) {
 				if ( range[ 0 ] === undefined || range[ 1 ] === undefined ) {
 					return;
 					return;
 				}
 				}
@@ -194,7 +194,7 @@ export default class InlineAutoformatEngine {
 				formatCallback( batch, validRanges );
 				formatCallback( batch, validRanges );
 
 
 				// Remove delimiters.
 				// Remove delimiters.
-				for ( let range of rangesToRemove ) {
+				for ( const range of rangesToRemove ) {
 					batch.remove( range );
 					batch.remove( range );
 				}
 				}
 			} );
 			} );

+ 5 - 5
packages/ckeditor5-autoformat/tests/blockautoformatengine.js

@@ -31,7 +31,7 @@ describe( 'BlockAutoformatEngine', () => {
 		it( 'should run a command when the pattern is matched', () => {
 		it( 'should run a command when the pattern is matched', () => {
 			const spy = testUtils.sinon.spy();
 			const spy = testUtils.sinon.spy();
 			editor.commands.set( 'testCommand', new TestCommand( editor, spy ) );
 			editor.commands.set( 'testCommand', new TestCommand( editor, spy ) );
-			new BlockAutoformatEngine( editor, /^[\*]\s$/, 'testCommand' );
+			new BlockAutoformatEngine( editor, /^[*]\s$/, 'testCommand' ); // eslint-disable-line no-new
 
 
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			doc.enqueueChanges( () => {
 			doc.enqueueChanges( () => {
@@ -44,7 +44,7 @@ describe( 'BlockAutoformatEngine', () => {
 		it( 'should remove found pattern', () => {
 		it( 'should remove found pattern', () => {
 			const spy = testUtils.sinon.spy();
 			const spy = testUtils.sinon.spy();
 			editor.commands.set( 'testCommand', new TestCommand( editor, spy ) );
 			editor.commands.set( 'testCommand', new TestCommand( editor, spy ) );
-			new BlockAutoformatEngine( editor, /^[\*]\s$/, 'testCommand' );
+			new BlockAutoformatEngine( editor, /^[*]\s$/, 'testCommand' ); // eslint-disable-line no-new
 
 
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			doc.enqueueChanges( () => {
 			doc.enqueueChanges( () => {
@@ -59,7 +59,7 @@ describe( 'BlockAutoformatEngine', () => {
 	describe( 'Callback', () => {
 	describe( 'Callback', () => {
 		it( 'should run callback when the pattern is matched', () => {
 		it( 'should run callback when the pattern is matched', () => {
 			const spy = testUtils.sinon.spy();
 			const spy = testUtils.sinon.spy();
-			new BlockAutoformatEngine( editor, /^[\*]\s$/, spy );
+			new BlockAutoformatEngine( editor, /^[*]\s$/, spy ); // eslint-disable-line no-new
 
 
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			doc.enqueueChanges( () => {
 			doc.enqueueChanges( () => {
@@ -71,7 +71,7 @@ describe( 'BlockAutoformatEngine', () => {
 
 
 		it( 'should ignore other delta operations', () => {
 		it( 'should ignore other delta operations', () => {
 			const spy = testUtils.sinon.spy();
 			const spy = testUtils.sinon.spy();
-			new BlockAutoformatEngine( editor, /^[\*]\s/, spy );
+			new BlockAutoformatEngine( editor, /^[*]\s/, spy ); // eslint-disable-line no-new
 
 
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			doc.enqueueChanges( () => {
 			doc.enqueueChanges( () => {
@@ -83,7 +83,7 @@ describe( 'BlockAutoformatEngine', () => {
 
 
 		it( 'should stop if there is no text to run matching on', () => {
 		it( 'should stop if there is no text to run matching on', () => {
 			const spy = testUtils.sinon.spy();
 			const spy = testUtils.sinon.spy();
-			new BlockAutoformatEngine( editor, /^[\*]\s/, spy );
+			new BlockAutoformatEngine( editor, /^[*]\s/, spy ); // eslint-disable-line no-new
 
 
 			setData( doc, '<paragraph>[]</paragraph>' );
 			setData( doc, '<paragraph>[]</paragraph>' );
 			doc.enqueueChanges( () => {
 			doc.enqueueChanges( () => {

+ 6 - 6
packages/ckeditor5-autoformat/tests/inlineautoformatengine.js

@@ -29,7 +29,7 @@ describe( 'InlineAutoformatEngine', () => {
 
 
 	describe( 'attribute', () => {
 	describe( 'attribute', () => {
 		it( 'should stop early if there are less than 3 capture groups', () => {
 		it( 'should stop early if there are less than 3 capture groups', () => {
-			new InlineAutoformatEngine( editor, /(\*)(.+?)\*/g, 'testAttribute' );
+			new InlineAutoformatEngine( editor, /(\*)(.+?)\*/g, 'testAttribute' ); // eslint-disable-line no-new
 
 
 			setData( doc, '<paragraph>*foobar[]</paragraph>' );
 			setData( doc, '<paragraph>*foobar[]</paragraph>' );
 			doc.enqueueChanges( () => {
 			doc.enqueueChanges( () => {
@@ -40,7 +40,7 @@ describe( 'InlineAutoformatEngine', () => {
 		} );
 		} );
 
 
 		it( 'should apply an attribute when the pattern is matched', () => {
 		it( 'should apply an attribute when the pattern is matched', () => {
-			new InlineAutoformatEngine( editor, /(\*)(.+?)(\*)/g, 'testAttribute' );
+			new InlineAutoformatEngine( editor, /(\*)(.+?)(\*)/g, 'testAttribute' ); // eslint-disable-line no-new
 
 
 			setData( doc, '<paragraph>*foobar[]</paragraph>' );
 			setData( doc, '<paragraph>*foobar[]</paragraph>' );
 			doc.enqueueChanges( () => {
 			doc.enqueueChanges( () => {
@@ -51,7 +51,7 @@ describe( 'InlineAutoformatEngine', () => {
 		} );
 		} );
 
 
 		it( 'should stop early if selection is not collapsed', () => {
 		it( 'should stop early if selection is not collapsed', () => {
-			new InlineAutoformatEngine( editor, /(\*)(.+?)\*/g, 'testAttribute' );
+			new InlineAutoformatEngine( editor, /(\*)(.+?)\*/g, 'testAttribute' ); // eslint-disable-line no-new
 
 
 			setData( doc, '<paragraph>*foob[ar]</paragraph>' );
 			setData( doc, '<paragraph>*foob[ar]</paragraph>' );
 			doc.enqueueChanges( () => {
 			doc.enqueueChanges( () => {
@@ -70,7 +70,7 @@ describe( 'InlineAutoformatEngine', () => {
 				remove: []
 				remove: []
 			} );
 			} );
 
 
-			new InlineAutoformatEngine( editor, testStub, formatSpy );
+			new InlineAutoformatEngine( editor, testStub, formatSpy ); // eslint-disable-line no-new
 
 
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			doc.enqueueChanges( () => {
 			doc.enqueueChanges( () => {
@@ -87,7 +87,7 @@ describe( 'InlineAutoformatEngine', () => {
 				remove: [ [] ]
 				remove: [ [] ]
 			} );
 			} );
 
 
-			new InlineAutoformatEngine( editor, testStub, formatSpy );
+			new InlineAutoformatEngine( editor, testStub, formatSpy ); // eslint-disable-line no-new
 
 
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			doc.enqueueChanges( () => {
 			doc.enqueueChanges( () => {
@@ -104,7 +104,7 @@ describe( 'InlineAutoformatEngine', () => {
 				remove: [ [] ]
 				remove: [ [] ]
 			} );
 			} );
 
 
-			new InlineAutoformatEngine( editor, testStub, formatSpy );
+			new InlineAutoformatEngine( editor, testStub, formatSpy ); // eslint-disable-line no-new
 
 
 			setData( doc, '<paragraph>[]</paragraph>' );
 			setData( doc, '<paragraph>[]</paragraph>' );
 			doc.enqueueChanges( () => {
 			doc.enqueueChanges( () => {