File ve.init.mw.DesktopArticleTarget.js
has 901 lines of code (exceeds 250 allowed). Consider refactoring. Open
/*!
* VisualEditor MediaWiki Initialization DesktopArticleTarget class.
*
* @copyright See AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
Function restorePage
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
ve.init.mw.DesktopArticleTarget.prototype.restorePage = function () {
// Restore any previous redirectMsg/redirectsub
this.setRealRedirectInterface();
if ( this.$originalCategories ) {
$( '#catlinks' ).replaceWith( this.$originalCategories );
- 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 teardown
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
ve.init.mw.DesktopArticleTarget.prototype.teardown = function ( trackMechanism ) {
// Event tracking
let abortType, abortedMode;
if ( trackMechanism ) {
if ( this.activating ) {
Function restorePage
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
ve.init.mw.DesktopArticleTarget.prototype.restorePage = function () {
// Restore any previous redirectMsg/redirectsub
this.setRealRedirectInterface();
if ( this.$originalCategories ) {
$( '#catlinks' ).replaceWith( this.$originalCategories );
Function VeInitMwDesktopArticleTarget
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
ve.init.mw.DesktopArticleTarget = function VeInitMwDesktopArticleTarget( config ) {
// Parent constructor
ve.init.mw.DesktopArticleTarget.super.call( this, config );
// Parent constructor bound key event handlers, but we don't want them bound until
Function switchToFallbackWikitextEditor
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
ve.init.mw.DesktopArticleTarget.prototype.switchToFallbackWikitextEditor = function ( modified ) {
const oldId = mw.config.get( 'wgRevisionId' ) || $( 'input[name=parentRevId]' ).val();
const prefPromise = mw.libs.ve.setEditorPreference( 'wikitext' );
if ( !modified ) {
Function onWindowPopState
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
ve.init.mw.DesktopArticleTarget.prototype.onWindowPopState = function ( e ) {
if ( !this.verifyPopState( e.state ) ) {
// Ignore popstate events fired for states not created by us
// This also filters out the initial fire in Chrome (T59901).
return;
- 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 onWindowPopState
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
ve.init.mw.DesktopArticleTarget.prototype.onWindowPopState = function ( e ) {
if ( !this.verifyPopState( e.state ) ) {
// Ignore popstate events fired for states not created by us
// This also filters out the initial fire in Chrome (T59901).
return;
Function teardown
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
ve.init.mw.DesktopArticleTarget.prototype.teardown = function ( trackMechanism ) {
// Event tracking
let abortType, abortedMode;
if ( trackMechanism ) {
if ( this.activating ) {
- 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 loadFail
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
ve.init.mw.DesktopArticleTarget.prototype.loadFail = function ( code, errorDetails ) {
// Parent method
ve.init.mw.DesktopArticleTarget.super.prototype.loadFail.apply( this, arguments );
if ( this.wikitextFallbackLoading ) {
Function setupNewSection
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
ve.init.mw.DesktopArticleTarget.prototype.setupNewSection = function ( surface ) {
if ( surface.getMode() === 'source' && this.section === 'new' ) {
if ( !this.sectionTitle ) {
this.sectionTitle = new OO.ui.TextInputWidget( {
$element: $( '<h2>' ),
- 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 updateHistoryState
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
ve.init.mw.DesktopArticleTarget.prototype.updateHistoryState = function () {
const veaction = this.getDefaultMode() === 'visual' ? 'edit' : 'editsource',
section = this.section;
// Push veaction=edit(source) url in history (if not already present).
- 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 updateHistoryState
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
ve.init.mw.DesktopArticleTarget.prototype.updateHistoryState = function () {
const veaction = this.getDefaultMode() === 'visual' ? 'edit' : 'editsource',
section = this.section;
// Push veaction=edit(source) url in history (if not already present).
Function surfaceReady
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
ve.init.mw.DesktopArticleTarget.prototype.surfaceReady = function () {
if ( !this.activating ) {
// Activation was aborted before we got here. Do nothing
// TODO are there things we need to clean up?
return;
Function setupToolbar
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
ve.init.mw.DesktopArticleTarget.prototype.setupToolbar = function ( surface ) {
const mode = surface.getMode(),
wasSetup = !!this.toolbar;
ve.track( 'trace.setupToolbar.enter', { mode: mode } );
Function maybeShowWelcomeDialog
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
ve.init.mw.DesktopArticleTarget.prototype.maybeShowWelcomeDialog = function () {
const editorMode = this.getDefaultMode(),
windowManager = this.getSurface().dialogs;
this.welcomeDialogPromise = ve.createDeferred();
Function maybeShowMetaDialog
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
ve.init.mw.DesktopArticleTarget.prototype.maybeShowMetaDialog = function () {
if ( this.welcomeDialogPromise ) {
// Pop out the notices when the welcome dialog is closed
this.welcomeDialogPromise
.always( () => {
- 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 afterActivate
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
ve.init.mw.DesktopArticleTarget.prototype.afterActivate = function () {
$( 'html' ).removeClass( 've-activating' ).addClass( 've-active' );
// Disable TemplateStyles in the original content
// (We do this here because toggling 've-active' class above hides it)
- 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 setupSkinTabs
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
ve.init.mw.DesktopArticleTarget.prototype.setupSkinTabs = function () {
if ( this.isViewPage ) {
const namespaceNumber = mw.config.get( 'wgNamespaceNumber' );
const namespaceName = mw.config.get( 'wgCanonicalNamespace' );
const isTalkNamespace = mw.Title.isTalkNamespace( namespaceNumber );
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
ve.init.mw.DesktopArticleTarget.prototype.switchToWikitextEditor = function () {
// Parent method
ve.init.mw.DesktopArticleTarget.super.prototype.switchToWikitextEditor.apply( this, arguments );
if ( this.isModeAvailable( 'source' ) ) {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 107.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
ve.init.mw.DesktopArticleTarget.prototype.switchToVisualEditor = function () {
// Parent method
ve.init.mw.DesktopArticleTarget.super.prototype.switchToVisualEditor.apply( this, arguments );
if ( this.isModeAvailable( 'visual' ) ) {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 107.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
ve.init.mw.DesktopArticleTarget.prototype.unbindHandlers = function () {
ve.init.mw.DesktopArticleTarget.super.prototype.unbindHandlers.call( this );
if ( this.onWatchToggleHandler ) {
mw.hook( 'wikipage.watchlistChange' ).remove( this.onWatchToggleHandler );
}
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 105.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
ve.init.mw.DesktopArticleTarget.prototype.bindHandlers = function () {
ve.init.mw.DesktopArticleTarget.super.prototype.bindHandlers.call( this );
if ( this.onWatchToggleHandler ) {
mw.hook( 'wikipage.watchlistChange' ).add( this.onWatchToggleHandler );
}
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 105.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
ve.init.mw.DesktopArticleTarget.prototype.setupToolbarSaveButton = function () {
this.toolbarSaveButton = this.toolbar.getToolGroupByName( 'save' ).items[ 0 ];
};
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 67.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
case 'mwCategory': {
const metaList = this.getSurface().getModel().getDocument().getMetaList();
this.rebuildCategories( metaList.getItemsInGroup( 'mwCategory' ) );
break;
}
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 62.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
case 'mwCategory': {
const metaList = this.getSurface().getModel().getDocument().getMetaList();
this.rebuildCategories( metaList.getItemsInGroup( 'mwCategory' ) );
break;
}
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 62.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76