File view.js
has 457 lines of code (exceeds 250 allowed). Consider refactoring. Open
/**
* @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
Function _getPositions
has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring. Open
_getPositions( node ) {
if ( node.is( 'documentFragment' ) || node.is( 'element' ) ) {
// Copy elements into the array, when nodes will be removed from parent node this array will still have all the
// items needed for iteration.
const children = [ ...node.getChildren() ];
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _getPositions
has 68 lines of code (exceeds 25 allowed). Consider refactoring. Open
_getPositions( node ) {
if ( node.is( 'documentFragment' ) || node.is( 'element' ) ) {
// Copy elements into the array, when nodes will be removed from parent node this array will still have all the
// items needed for iteration.
const children = [ ...node.getChildren() ];
Function _walkView
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
_walkView( root, callback ) {
const ignore = this.ignoreRoot && this.root === root;
if ( root.is( 'element' ) || root.is( 'documentFragment' ) ) {
if ( root.is( 'element' ) && !ignore ) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _convertViewElements
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
function _convertViewElements( rootNode ) {
if ( rootNode.is( 'element' ) || rootNode.is( 'documentFragment' ) ) {
// Convert element or leave document fragment.
const convertedElement = rootNode.is( 'documentFragment' ) ?
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _createRanges
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
_createRanges() {
const ranges = [];
let range = null;
for ( const item of this._positions ) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _stringifyTextRanges
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
_stringifyTextRanges( node ) {
const length = node.data.length;
let result = node.data.split( '' );
let rangeStartToken, rangeEndToken;
Function parse
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
export function parse( data, options = {} ) {
const viewDocument = new ViewDocument( new StylesProcessor() );
options.order = options.order || [];
const rangeParser = new RangeParser( {
Function _stringifyTextRanges
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
_stringifyTextRanges( node ) {
const length = node.data.length;
let result = node.data.split( '' );
let rangeStartToken, rangeEndToken;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _stringifyElementRanges
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
_stringifyElementRanges( element, offset ) {
let start = '';
let end = '';
let collapsed = '';
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
if ( !this.sameSelectionCharacters && item.textOffset !== 0 && item.textOffset !== text.length ) {
throw new Error( `Parse error - range delimiter '${ item.bracket }' is placed inside text node.` );
}
Function _convertElement
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
function _convertElement( viewDocument, viewElement ) {
const info = _convertElementNameAndInfo( viewElement );
const ElementConstructor = allowedTypes[ info.type ];
const newElement = ElementConstructor ? new ElementConstructor( viewDocument, info.name ) : new ViewElement( viewDocument, info.name );
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _stringifyElementType
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
_stringifyElementType( element ) {
if ( this.showType ) {
for ( const type in allowedTypes ) {
if ( element instanceof allowedTypes[ type ] ) {
return type;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"