Sfoglia il codice sorgente

Merge branch 'master' into t/26

Szymon Kupś 8 anni fa
parent
commit
ce5dbe6ba4

+ 12 - 0
packages/ckeditor5-autoformat/.eslintrc.js

@@ -0,0 +1,12 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* eslint-env node */
+
+'use strict';
+
+module.exports = {
+	extends: 'ckeditor5'
+};

+ 0 - 92
packages/ckeditor5-autoformat/.jscsrc

@@ -1,92 +0,0 @@
-{
-  "requireCurlyBraces": [
-    "if",
-    "else",
-    "for",
-    "while",
-    "do",
-    "switch",
-    "try",
-    "catch"
-  ],
-  "requireSpaceBeforeKeywords": true,
-  "requireSpaceAfterKeywords": [
-    "do",
-    "for",
-    "if",
-    "else",
-    "switch",
-    "case",
-    "try",
-    "catch",
-    "void",
-    "while",
-    "with",
-    "return",
-    "typeof"
-  ],
-  "requireSpaceBeforeBlockStatements": true,
-  "requireParenthesesAroundIIFE": true,
-  "requireSpacesInConditionalExpression": {
-    "afterTest": true,
-    "beforeConsequent": true,
-    "afterConsequent": true,
-    "beforeAlternate": true
-  },
-  "requireSpacesInFunction": {
-    "beforeOpeningCurlyBrace": true
-  },
-  "disallowSpacesInFunction": {
-    "beforeOpeningRoundBrace": true
-  },
-  "disallowSpacesInCallExpression": true,
-  "disallowMultipleVarDecl": "exceptUndefined",
-  "requireBlocksOnNewline": true,
-  "disallowPaddingNewlinesInBlocks": true,
-  "requirePaddingNewlinesBeforeKeywords": [
-    "do",
-    "for",
-    "if",
-    "switch",
-    "case",
-    "try",
-    "while",
-    "with",
-    "return"
-  ],
-  "requireSpacesInsideObjectBrackets": "all",
-  "requireSpacesInsideArrayBrackets": "all",
-  "requireSpacesInsideParentheses": "all",
-  "disallowSpaceAfterObjectKeys": true,
-  "requireSpaceBeforeObjectValues": true,
-  "requireCommaBeforeLineBreak": true,
-  "requireOperatorBeforeLineBreak": true,
-  "disallowSpaceAfterPrefixUnaryOperators": true,
-  "disallowSpaceBeforePostfixUnaryOperators": true,
-  "requireSpaceBeforeBinaryOperators": true,
-  "disallowImplicitTypeConversion": [
-    "numeric",
-    "binary",
-    "string"
-  ],
-  "requireCamelCaseOrUpperCaseIdentifiers": true,
-  "requireSpaceAfterBinaryOperators": true,
-  "disallowKeywords": [
-    "with"
-  ],
-  "disallowMultipleLineStrings": true,
-  "disallowMultipleLineBreaks": true,
-  "disallowMixedSpacesAndTabs": true,
-  "disallowTrailingWhitespace": true,
-  "maximumLineLength": 140,
-  "requireCapitalizedConstructors": true,
-  "requireDotNotation": true,
-  "disallowYodaConditions": true,
-  "disallowNewlineBeforeBlockStatements": true,
-  "validateLineBreaks": "LF",
-  "validateQuoteMarks": "'",
-  "validateIndentation": "\t",
-  "safeContextKeyword": [
-    "that"
-  ]
-}

+ 0 - 11
packages/ckeditor5-autoformat/.jshintrc

@@ -1,11 +0,0 @@
-{
-  "esnext": true,
-  "immed": true,
-  "loopfunc": true,
-  "noarg": true,
-  "nonbsp": true,
-  "undef": true,
-  "unused": true,
-  "strict": "implied",
-  "varstmt": true
-}

+ 6 - 5
packages/ckeditor5-autoformat/gulpfile.js

@@ -3,19 +3,20 @@
  * For licensing, see LICENSE.md.
  */
 
-/* jshint browser: false, node: true, strict: true */
+/* eslint-env node */
 
 'use strict';
 
 const gulp = require( 'gulp' );
-const ckeditor5Lint = require( '@ckeditor/ckeditor5-dev-lint' )( {
+const ckeditor5Lint = require( '@ckeditor/ckeditor5-dev-lint' );
+const options = {
 	// Files ignored by `gulp lint` task.
 	// Files from .gitignore will be added automatically during task execution.
 	ignoredFiles: [
 		'src/lib/**'
 	]
-} );
+};
 
-gulp.task( 'lint', ckeditor5Lint.lint );
-gulp.task( 'lint-staged', ckeditor5Lint.lintStaged );
+gulp.task( 'lint', () => ckeditor5Lint.lint( options ) );
+gulp.task( 'lint-staged', () => ckeditor5Lint.lintStaged( options ) );
 gulp.task( 'pre-commit', [ 'lint-staged' ] );

+ 3 - 1
packages/ckeditor5-autoformat/package.json

@@ -9,6 +9,7 @@
   },
   "devDependencies": {
     "@ckeditor/ckeditor5-basic-styles": "^0.8.1",
+    "@ckeditor/ckeditor5-dev-lint": "^3.0.0",
     "@ckeditor/ckeditor5-block-quote": "^0.1.1",
     "@ckeditor/ckeditor5-dev-lint": "^2.0.2",
     "@ckeditor/ckeditor5-editor-classic": "^0.7.3",
@@ -18,7 +19,8 @@
     "@ckeditor/ckeditor5-paragraph": "^0.8.0",
     "@ckeditor/ckeditor5-typing": "^0.9.1",
     "@ckeditor/ckeditor5-undo": "^0.8.1",
-    "gulp": "^3.9.0",
+    "eslint-config-ckeditor5": "^1.0.0",
+    "gulp": "^3.9.1",
     "guppy-pre-commit": "^0.4.0"
   },
   "engines": {

+ 26 - 15
packages/ckeditor5-autoformat/src/autoformat.js

@@ -43,9 +43,9 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
  * * `**foo bar**` or `__foo bar__` – will bold the text,
  * * `*foo bar*` or `_foo bar_` – will italicize the text,
  *
- * NOTE: Remember to add proper features to editor configuration. Autoformatting will be enabled only for those
- * commands that are included in current configuration. For example: `bold` autoformatting will not work if there is no
- * `bold` command registered in editor.
+ * NOTE: Remember to add proper features to the editor configuration. Autoformatting will be enabled only for those
+ * commands that are included in the actual configuration. For example: `bold` autoformatting will not work if there is no
+ * `bold` command registered in the editor.
  *
  * @extends module:core/plugin~Plugin
  */
@@ -68,11 +68,11 @@ export default class Autoformat extends Plugin {
 	}
 
 	/**
-	 * Adds autoformatting related to `bulletedList` and `numberedList` commands.
+	 * Adds autoformatting related to the {@link module:list/list~List}.
 	 *
 	 * When typed:
-	 * - `* ` or `- ` - paragraph will be changed to a bulleted list,
-	 * - `1. ` or `1) ` - paragraph will be changed to a numbered list (1 can be any digit or list of digits).
+	 * - `* ` or `- ` - a paragraph will be changed to a bulleted list,
+	 * - `1. ` or `1) ` - a paragraph will be changed to a numbered list ("1" can be any digit or list of digits).
 	 *
 	 * @private
 	 */
@@ -80,16 +80,19 @@ export default class Autoformat extends Plugin {
 		const commands = this.editor.commands;
 
 		if ( commands.has( 'bulletedList' ) ) {
-			new BlockAutoformatEngine( this.editor, /^[\*\-]\s$/, 'bulletedList' );
+			// eslint-disable-next-line no-new
+			new BlockAutoformatEngine( this.editor, /^[*-]\s$/, 'bulletedList' );
 		}
 
 		if ( commands.has( 'numberedList' ) ) {
-			new BlockAutoformatEngine( this.editor, /^\d+[\.|)]?\s$/, 'numberedList' );
+			// eslint-disable-next-line no-new
+			new BlockAutoformatEngine( this.editor, /^\d+[.|)]?\s$/, 'numberedList' );
 		}
 	}
 
 	/**
-	 *Adds autoformatting related to `bold` and `italic` commands.
+	 * Adds autoformatting related to the {@link module:basic-styles/bold~Bold} and
+	 * {@link module:basic-styles/italic~Italic}.
 	 *
 	 * When typed:
 	 * - `**foobar**`: `**` characters are removed, and `foobar` is set to bold,
@@ -103,21 +106,27 @@ export default class Autoformat extends Plugin {
 		const commands = this.editor.commands;
 
 		if ( commands.has( 'bold' ) ) {
-			new InlineAutoformatEngine( this.editor, /(\*\*)([^\*]+)(\*\*)$/g, 'bold' );
+			/* eslint-disable no-new */
+			new InlineAutoformatEngine( this.editor, /(\*\*)([^*]+)(\*\*)$/g, 'bold' );
 			new InlineAutoformatEngine( this.editor, /(__)([^_]+)(__)$/g, 'bold' );
+			/* eslint-enable no-new */
 		}
 
 		if ( commands.has( 'italic' ) ) {
 			// The italic autoformatter cannot be triggered by the bold markers, so we need to check the
 			// text before the pattern (e.g. `(?:^|[^\*])`).
-			new InlineAutoformatEngine( this.editor, /(?:^|[^\*])(\*)([^\*_]+)(\*)$/g, 'italic' );
+
+			/* eslint-disable no-new */
+			new InlineAutoformatEngine( this.editor, /(?:^|[^*])(\*)([^*_]+)(\*)$/g, 'italic' );
 			new InlineAutoformatEngine( this.editor, /(?:^|[^_])(_)([^_]+)(_)$/g, 'italic' );
+			/* eslint-enable no-new */
 		}
 	}
 
 	/**
-	 * Adds autoformatting related to heading commands.
-	 * It is using number at the end of the command name to associate it with proper trigger:
+	 * Adds autoformatting related to {@link module:heading/heading~Heading}.
+	 *
+	 * It is using a number at the end of the command name to associate it with the proper trigger:
 	 * * `heading1` will be executed when typing `#`,
 	 * * `heading2` will be executed when typing `##`,
 	 * * `heading3` will be executed when typing `###`.
@@ -129,7 +138,7 @@ export default class Autoformat extends Plugin {
 		const options = this.editor.config.get( 'heading.options' );
 
 		if ( options ) {
-			for ( let option of options ) {
+			for ( const option of options ) {
 				const commandName = option.modelElement;
 				let match;
 
@@ -137,7 +146,8 @@ export default class Autoformat extends Plugin {
 					const level = match[ 0 ];
 					const regExp = new RegExp( `^(#{${ level }})\\s$` );
 
-					new BlockAutoformatEngine( this.editor, regExp, ( context ) => {
+					// eslint-disable-next-line no-new
+					new BlockAutoformatEngine( this.editor, regExp, context => {
 						const { batch } = context;
 
 						this.editor.execute( commandName, { batch } );
@@ -149,6 +159,7 @@ export default class Autoformat extends Plugin {
 
 	_addBlockQuoteAutoformats() {
 		if ( this.editor.commands.has( 'blockQuote' ) ) {
+			// eslint-disable-next-line no-new
 			new BlockAutoformatEngine( this.editor, /^>\s$/, 'blockQuote' );
 		}
 	}

+ 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.
 			const command = callbackOrCommand;
 
-			callback = ( context ) => {
+			callback = context => {
 				const { batch } = context;
 
 				// 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.
-		testCallback = testCallback || ( ( text ) => {
+		testCallback = testCallback || ( text => {
 			let result;
-			let remove = [];
-			let format = [];
+			const remove = [];
+			const format = [];
 
 			while ( ( result = regExp.exec( text ) ) !== null ) {
 				// There should be full match and 3 capture groups.
@@ -134,7 +134,7 @@ export default class InlineAutoformatEngine {
 
 		// A format callback run on matched text.
 		formatCallback = formatCallback || ( ( batch, validRanges ) => {
-			for ( let range of validRanges ) {
+			for ( const range of validRanges ) {
 				batch.setAttribute( range, command, true );
 			}
 		} );
@@ -156,7 +156,7 @@ export default class InlineAutoformatEngine {
 			const rangesToFormat = [];
 
 			// Apply format before deleting text.
-			ranges.format.forEach( ( range ) => {
+			ranges.format.forEach( range => {
 				if ( range[ 0 ] === undefined || range[ 1 ] === undefined ) {
 					return;
 				}
@@ -170,7 +170,7 @@ export default class InlineAutoformatEngine {
 			const rangesToRemove = [];
 
 			// 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 ) {
 					return;
 				}
@@ -194,7 +194,7 @@ export default class InlineAutoformatEngine {
 				formatCallback( batch, validRanges );
 
 				// Remove delimiters.
-				for ( let range of rangesToRemove ) {
+				for ( const range of rangesToRemove ) {
 					batch.remove( range );
 				}
 			} );

+ 0 - 22
packages/ckeditor5-autoformat/tests/.jshintrc

@@ -1,22 +0,0 @@
-{
-  "esnext": true,
-  "expr": true,
-  "immed": true,
-  "loopfunc": true,
-  "noarg": true,
-  "nonbsp": true,
-  "strict": "implied",
-  "undef": true,
-  "unused": true,
-  "varstmt": true,
-  "globals": {
-    "after": false,
-    "afterEach": false,
-    "before": false,
-    "beforeEach": false,
-    "describe": false,
-    "expect": false,
-    "it": false,
-    "sinon": false
-  }
-}

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

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

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

@@ -29,7 +29,7 @@ describe( 'InlineAutoformatEngine', () => {
 
 	describe( 'attribute', () => {
 		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>' );
 			doc.enqueueChanges( () => {
@@ -40,7 +40,7 @@ describe( 'InlineAutoformatEngine', () => {
 		} );
 
 		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>' );
 			doc.enqueueChanges( () => {
@@ -51,7 +51,7 @@ describe( 'InlineAutoformatEngine', () => {
 		} );
 
 		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>' );
 			doc.enqueueChanges( () => {
@@ -70,7 +70,7 @@ describe( 'InlineAutoformatEngine', () => {
 				remove: []
 			} );
 
-			new InlineAutoformatEngine( editor, testStub, formatSpy );
+			new InlineAutoformatEngine( editor, testStub, formatSpy ); // eslint-disable-line no-new
 
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			doc.enqueueChanges( () => {
@@ -87,7 +87,7 @@ describe( 'InlineAutoformatEngine', () => {
 				remove: [ [] ]
 			} );
 
-			new InlineAutoformatEngine( editor, testStub, formatSpy );
+			new InlineAutoformatEngine( editor, testStub, formatSpy ); // eslint-disable-line no-new
 
 			setData( doc, '<paragraph>*[]</paragraph>' );
 			doc.enqueueChanges( () => {
@@ -104,7 +104,7 @@ describe( 'InlineAutoformatEngine', () => {
 				remove: [ [] ]
 			} );
 
-			new InlineAutoformatEngine( editor, testStub, formatSpy );
+			new InlineAutoformatEngine( editor, testStub, formatSpy ); // eslint-disable-line no-new
 
 			setData( doc, '<paragraph>[]</paragraph>' );
 			doc.enqueueChanges( () => {