Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Removed usage of logger. #1760

Merged
merged 8 commits into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/conversion/downcasthelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

/**
* Contains downcast (model-to-view) converters for {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher}.
*
* @module engine/conversion/downcasthelpers
*/

/* globals console */

scofalik marked this conversation as resolved.
Show resolved Hide resolved
import ModelRange from '../model/range';
import ModelSelection from '../model/selection';
import ModelElement from '../model/element';
Expand All @@ -11,14 +19,8 @@ import ViewAttributeElement from '../view/attributeelement';
import DocumentSelection from '../model/documentselection';
import ConversionHelpers from './conversionhelpers';

import log from '@ckeditor/ckeditor5-utils/src/log';
import { cloneDeep } from 'lodash-es';

/**
* Contains downcast (model-to-view) converters for {@link module:engine/conversion/downcastdispatcher~DowncastDispatcher}.
*
* @module engine/conversion/downcasthelpers
*/
import { attachLinkToDocumentation } from '@ckeditor/ckeditor5-utils/src/ckeditorerror';

/**
* Downcast conversion helper functions.
Expand Down Expand Up @@ -824,8 +826,10 @@ function changeAttribute( attributeCreator ) {
*
* @error conversion-attribute-to-attribute-on-text
*/
log.warn( 'conversion-attribute-to-attribute-on-text: ' +
'Trying to convert text node\'s attribute with attribute-to-attribute converter.' );
console.warn( attachLinkToDocumentation(
pjasiun marked this conversation as resolved.
Show resolved Hide resolved
'conversion-attribute-to-attribute-on-text: ' +
'Trying to convert text node\'s attribute with attribute-to-attribute converter.'
) );

return;
}
Expand Down
8 changes: 1 addition & 7 deletions src/model/documentselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import TextProxy from './textproxy';
import toMap from '@ckeditor/ckeditor5-utils/src/tomap';
import Collection from '@ckeditor/ckeditor5-utils/src/collection';
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
import log from '@ckeditor/ckeditor5-utils/src/log';
import uid from '@ckeditor/ckeditor5-utils/src/uid';

const storePrefix = 'selection:';
Expand Down Expand Up @@ -804,12 +803,7 @@ class LiveSelection extends Selection {
this._checkRange( range );

if ( range.root == this._document.graveyard ) {
/**
* Trying to add a Range that is in the graveyard root. Range rejected.
*
* @warning model-selection-range-in-graveyard
*/
log.warn( 'model-selection-range-in-graveyard: Trying to add a Range that is in the graveyard root. Range rejected.' );
// @if CK_DEBUG // console.warn( 'Trying to add a Range that is in the graveyard root. Range rejected.' );

return;
}
Expand Down
17 changes: 8 additions & 9 deletions src/model/operation/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Range from '../range';
import Position from '../position';

import compareArrays from '@ckeditor/ckeditor5-utils/src/comparearrays';
import log from '@ckeditor/ckeditor5-utils/src/log';

const transformations = new Map();

Expand Down Expand Up @@ -102,14 +101,14 @@ export function transform( a, b, context = {} ) {

return transformationFunction( a, b, context );
} catch ( e ) {
log.error( 'Error during operation transformation!', e.message );
log.error( 'Transformed operation', a );
log.error( 'Operation transformed by', b );
log.error( 'context.aIsStrong', context.aIsStrong );
log.error( 'context.aWasUndone', context.aWasUndone );
log.error( 'context.bWasUndone', context.bWasUndone );
log.error( 'context.abRelation', context.abRelation );
log.error( 'context.baRelation', context.baRelation );
// @if CK_DEBUG // console.error( 'Error during operation transformation!', e.message );
// @if CK_DEBUG // console.error( 'Transformed operation', a );
// @if CK_DEBUG // console.error( 'Operation transformed by', b );
// @if CK_DEBUG // console.error( 'context.aIsStrong', context.aIsStrong );
// @if CK_DEBUG // console.error( 'context.aWasUndone', context.aWasUndone );
// @if CK_DEBUG // console.error( 'context.bWasUndone', context.bWasUndone );
// @if CK_DEBUG // console.error( 'context.abRelation', context.abRelation );
// @if CK_DEBUG // console.error( 'context.baRelation', context.baRelation );

throw e;
}
Expand Down
18 changes: 7 additions & 11 deletions src/model/utils/insertcontent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
* @module engine/model/utils/insertcontent
*/

/* globals console */

import Position from '../position';
import LivePosition from '../liveposition';
import Element from '../element';
import Range from '../range';
import log from '@ckeditor/ckeditor5-utils/src/log';
import DocumentSelection from '../documentselection';
import Selection from '../selection';
import { attachLinkToDocumentation } from '@ckeditor/ckeditor5-utils/src/ckeditorerror';

/**
* Inserts content into the editor (specified selection) as one would expect the paste
Expand Down Expand Up @@ -85,13 +87,7 @@ export default function insertContent( model, content, selectable, placeOrOffset
} else {
// We are not testing else because it's a safe check for unpredictable edge cases:
// an insertion without proper range to select.

/**
* Cannot determine a proper selection range after insertion.
*
* @warning insertcontent-no-range
*/
log.warn( 'insertcontent-no-range: Cannot determine a proper selection range after insertion.' );
// @if CK_DEBUG // console.warn( 'insertcontent-no-range: Cannot determine a proper selection range after insertion.' );
}

const affectedRange = insertion.getAffectedRange() || model.createRange( insertionPosition );
Expand Down Expand Up @@ -322,8 +318,8 @@ class Insertion {
if ( !this.schema.checkChild( this.position, node ) ) {
// Algorithm's correctness check. We should never end up here but it's good to know that we did.
// Note that it would often be a silent issue if we insert node in a place where it's not allowed.
log.error(
'insertcontent-wrong-position: The node cannot be inserted on the given position.',
console.error(
attachLinkToDocumentation( 'insertcontent-wrong-position: The node cannot be inserted on the given position.' ),
pjasiun marked this conversation as resolved.
Show resolved Hide resolved
{ node, position: this.position }
);

Expand Down Expand Up @@ -442,7 +438,7 @@ class Insertion {
// Algorithm's correctness check. We should never end up here but it's good to know that we did.
// At this point the insertion position should be after the node we'll merge. If it isn't,
// it should need to be secured as in the left merge case.
log.error( 'insertcontent-wrong-position-on-merge: The insertion position should equal the merge position' );
// @if CK_DEBUG // console.error( 'The insertion position should equal the merge position' );
pjasiun marked this conversation as resolved.
Show resolved Hide resolved
}

// Move the position to the previous node, so it isn't moved to the graveyard on merge.
Expand Down
15 changes: 5 additions & 10 deletions src/view/observer/selectionobserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import Observer from './observer';
import MutationObserver from './mutationobserver';
import log from '@ckeditor/ckeditor5-utils/src/log';
import { debounce } from 'lodash-es';

/**
Expand Down Expand Up @@ -150,15 +149,11 @@ export default class SelectionObserver extends Observer {
// This counter is reset each second. 60 selection changes in 1 second is enough high number
// to be very difficult (impossible) to achieve using just keyboard keys (during normal editor use).
if ( ++this._loopbackCounter > 60 ) {
/**
* Selection change observer detected an infinite rendering loop.
* Most probably you try to put the selection in the position which is not allowed
* by the browser and browser fixes it automatically what causes `selectionchange` event on
* which a loopback through a model tries to re-render the wrong selection and again.
*
* @error selectionchange-infinite-loop
*/
log.warn( 'selectionchange-infinite-loop: Selection change observer detected an infinite rendering loop.' );
// Selection change observer detected an infinite rendering loop.
// Most probably you try to put the selection in the position which is not allowed
// by the browser and browser fixes it automatically what causes `selectionchange` event on
// which a loopback through a model tries to re-render the wrong selection and again.
// @if CK_DEBUG // console.warn( 'Selection change observer detected an infinite rendering loop.' );

return;
}
Expand Down
9 changes: 6 additions & 3 deletions src/view/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* @module engine/view/view
*/

/* globals console */

import Document from './document';
import DowncastWriter from './downcastwriter';
import Renderer from './renderer';
Expand All @@ -24,12 +26,11 @@ import CompositionObserver from './observer/compositionobserver';
import InputObserver from './observer/inputobserver';

import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin';
import log from '@ckeditor/ckeditor5-utils/src/log';
import mix from '@ckeditor/ckeditor5-utils/src/mix';
import { scrollViewportToShowTarget } from '@ckeditor/ckeditor5-utils/src/dom/scroll';
import { injectUiElementHandling } from './uielement';
import { injectQuirksHandling } from './filler';
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
import CKEditorError, { attachLinkToDocumentation } from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
import env from '@ckeditor/ckeditor5-utils/src/env';

/**
Expand Down Expand Up @@ -405,7 +406,9 @@ export default class View {
*
* @error view-focus-no-selection
*/
log.warn( 'view-focus-no-selection: There is no selection in any editable to focus.' );
console.warn( attachLinkToDocumentation(
pjasiun marked this conversation as resolved.
Show resolved Hide resolved
'view-focus-no-selection: There is no selection in any editable to focus.'
) );
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/conversion/conversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe( 'Conversion', () => {

it( 'should be chainable', () => {
const helpers = conversion.for( 'upcast' );
const addResult = helpers.add( () => { } );
const addResult = helpers.add( () => {} );

expect( addResult ).to.equal( helpers );
} );
Expand Down
4 changes: 2 additions & 2 deletions tests/conversion/downcastdispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ describe( 'DowncastDispatcher', () => {
const viewFigure = new ViewContainerElement( 'figure', null, viewCaption );

// Create custom highlight handler mock.
viewFigure._setCustomProperty( 'addHighlight', () => { } );
viewFigure._setCustomProperty( 'removeHighlight', () => { } );
viewFigure._setCustomProperty( 'addHighlight', () => {} );
viewFigure._setCustomProperty( 'removeHighlight', () => {} );

// Create mapper mock.
dispatcher.conversionApi.mapper = {
Expand Down
13 changes: 7 additions & 6 deletions tests/conversion/downcasthelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/

/* globals console */

import EditingController from '../../src/controller/editingcontroller';

import Model from '../../src/model/model';
Expand All @@ -15,7 +17,6 @@ import ViewContainerElement from '../../src/view/containerelement';
import ViewUIElement from '../../src/view/uielement';
import ViewText from '../../src/view/text';

import log from '@ckeditor/ckeditor5-utils/src/log';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';

import DowncastHelpers, {
Expand Down Expand Up @@ -614,7 +615,7 @@ describe( 'DowncastHelpers', () => {

// #1587
it( 'config.view and config.model as strings in generic conversion (elements only)', () => {
const logStub = testUtils.sinon.stub( log, 'warn' );
const consoleWarnStub = testUtils.sinon.stub( console, 'warn' );

downcastHelpers.elementToElement( { model: 'paragraph', view: 'p' } );

Expand All @@ -626,7 +627,7 @@ describe( 'DowncastHelpers', () => {
} );

expectResult( '<p test="1"></p><p test="2"></p>' );
expect( logStub.callCount ).to.equal( 0 );
expect( consoleWarnStub.callCount ).to.equal( 0 );

model.change( writer => {
writer.removeAttribute( 'test', modelRoot.getChild( 1 ) );
Expand All @@ -637,7 +638,7 @@ describe( 'DowncastHelpers', () => {

// #1587
it( 'config.view and config.model as strings in generic conversion (elements + text)', () => {
const logStub = testUtils.sinon.stub( log, 'warn' );
const consoleWarnStub = testUtils.sinon.stub( console, 'warn' );

downcastHelpers.elementToElement( { model: 'paragraph', view: 'p' } );

Expand All @@ -652,8 +653,8 @@ describe( 'DowncastHelpers', () => {
} );

expectResult( '<p>Foo</p><p test="1">Bar</p>' );
expect( logStub.callCount ).to.equal( 2 );
expect( logStub.alwaysCalledWithMatch( 'conversion-attribute-to-attribute-on-text' ) ).to.true;
expect( consoleWarnStub.callCount ).to.equal( 2 );
expect( consoleWarnStub.alwaysCalledWithMatch( 'conversion-attribute-to-attribute-on-text' ) ).to.true;

model.change( writer => {
writer.removeAttribute( 'test', modelRoot.getChild( 1 ) );
Expand Down
4 changes: 2 additions & 2 deletions tests/model/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe( 'Document', () => {
baseVersion: 0,
isDocumentOperation: true,
_execute: sinon.stub().returns( data ),
_validate: () => { }
_validate: () => {}
};

batch = new Batch();
Expand Down Expand Up @@ -82,7 +82,7 @@ describe( 'Document', () => {
const operation = {
baseVersion: 1,
isDocumentOperation: true,
_execute: () => { }
_execute: () => {}
};

expectToThrowCKEditorError( () => {
Expand Down
32 changes: 8 additions & 24 deletions tests/model/documentselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ import AttributeOperation from '../../src/model/operation/attributeoperation';
import SplitOperation from '../../src/model/operation/splitoperation';
import Collection from '@ckeditor/ckeditor5-utils/src/collection';
import count from '@ckeditor/ckeditor5-utils/src/count';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
import { setData, getData } from '../../src/dev-utils/model';
import { expectToThrowCKEditorError } from '@ckeditor/ckeditor5-utils/tests/_utils/utils';

describe( 'DocumentSelection', () => {
let model, doc, root, selection, liveRange, range;

testUtils.createSinonSandbox();

const fooStoreAttrKey = DocumentSelection._getStoreAttributeKey( 'foo' );
const abcStoreAttrKey = DocumentSelection._getStoreAttributeKey( 'abc' );

Expand Down Expand Up @@ -54,6 +51,7 @@ describe( 'DocumentSelection', () => {
} );

afterEach( () => {
sinon.restore();
model.destroy();
liveRange.detach();
} );
Expand Down Expand Up @@ -457,9 +455,6 @@ describe( 'DocumentSelection', () => {

expect( ranges[ 0 ].detach.called ).to.be.true;
expect( ranges[ 1 ].detach.called ).to.be.true;

ranges[ 0 ].detach.restore();
ranges[ 1 ].detach.restore();
} );
} );

Expand Down Expand Up @@ -512,7 +507,7 @@ describe( 'DocumentSelection', () => {
it( 'detaches all existing ranges', () => {
selection._setTo( [ range, liveRange ] );

const spy = testUtils.sinon.spy( LiveRange.prototype, 'detach' );
const spy = sinon.spy( LiveRange.prototype, 'detach' );
selection._setTo( root, 0 );

expect( spy.calledTwice ).to.be.true;
Expand All @@ -534,7 +529,7 @@ describe( 'DocumentSelection', () => {
const startPos = Position._createAt( root, 1 );
const endPos = Position._createAt( root, 2 );
const newEndPos = Position._createAt( root, 4 );
const spy = testUtils.sinon.spy( LiveRange.prototype, 'detach' );
const spy = sinon.spy( LiveRange.prototype, 'detach' );

selection._setTo( new Range( startPos, endPos ) );

Expand Down Expand Up @@ -569,11 +564,6 @@ describe( 'DocumentSelection', () => {
selection._setTo( null );
} );

afterEach( () => {
ranges[ 0 ].detach.restore();
ranges[ 1 ].detach.restore();
} );

it( 'should remove all stored ranges (and reset to default range)', () => {
expect( Array.from( selection.getRanges() ).length ).to.equal( 1 );
expect( selection.anchor.isEqual( new Position( root, [ 0, 0 ] ) ) ).to.be.true;
Expand Down Expand Up @@ -601,19 +591,13 @@ describe( 'DocumentSelection', () => {
}, /model-selection-set-ranges-not-range/, model );
} );

it( 'should log a warning when trying to set selection to the graveyard', () => {
// eslint-disable-next-line no-undef
const warnStub = sinon.stub( console, 'warn' );

const range = new Range( new Position( model.document.graveyard, [ 0 ] ) );
selection._setTo( range );

expect( warnStub.calledOnce ).to.equal( true );
expect( warnStub.getCall( 0 ).args[ 0 ] ).to.match( /model-selection-range-in-graveyard/ );
it( 'should not do nothing when trying to set selection to the graveyard', () => {
expect( () => {
const range = new Range( new Position( model.document.graveyard, [ 0 ] ) );
selection._setTo( range );
} ).to.not.throw();

expect( selection._ranges ).to.deep.equal( [] );

warnStub.restore();
} );

it( 'should detach removed ranges', () => {
Expand Down
Loading