wikimedia/mediawiki-extensions-Translate

View on GitHub

Showing 1,238 of 1,238 total issues

Identical blocks of code found in 4 locations. Consider refactoring.
Open

            api.postWithToken( 'csrf', params )
                .done( successFunction )
                .fail( function ( code, data ) {
                    // eslint-disable-next-line no-alert
                    alert( data.error && data.error.info );
Severity: Major
Found in resources/js/ext.translate.special.aggregategroups.js and 3 other locations - About 1 hr to fix
resources/js/ext.translate.special.aggregategroups.js on lines 24..29
resources/js/ext.translate.special.aggregategroups.js on lines 75..80
resources/js/ext.translate.special.aggregategroups.js on lines 397..402

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 60.

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

Further Reading

Function getDefinitions has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    public function getDefinitions() {
        $groups = MessageGroups::getAllGroups();
        $keys = [];

        /** @var $g MessageGroup */
Severity: Minor
Found in messagegroups/WorkflowStatesMessageGroup.php - About 1 hr to fix

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 6 locations. Consider refactoring.
Open

    saturate: function (ratio) {
        var hsl = this.values.hsl;
        hsl[1] += hsl[1] * ratio;
        this.setValues('hsl', hsl);
        return this;
Severity: Major
Found in resources/lib/Chart.js/Chart.js and 5 other locations - About 1 hr to fix
resources/lib/Chart.js/Chart.js on lines 1851..1856
resources/lib/Chart.js/Chart.js on lines 1858..1863
resources/lib/Chart.js/Chart.js on lines 1872..1877
resources/lib/Chart.js/Chart.js on lines 1879..1884
resources/lib/Chart.js/Chart.js on lines 1886..1891

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 60.

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

Further Reading

Function exports has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = function ( grunt ) {
    const conf = grunt.file.readJSON( 'extension.json' );

    grunt.loadNpmTasks( 'grunt-eslint' );
    grunt.loadNpmTasks( 'grunt-banana-checker' );
Severity: Minor
Found in Gruntfile.js - About 1 hr to fix

    Function showShortcuts has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            showShortcuts: function () {
                // Any better way?
                var rtl = $( document.body ).is( '.rtl' );
    
                var editorOffset = this.$editor.offset();
    Severity: Minor
    Found in resources/js/ext.translate.editor.shortcuts.js - About 1 hr to fix

      Function saveDocumentation has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              saveDocumentation: function () {
                  var translateEditor = this,
                      api = new mw.Api(),
                      newDocumentation = translateEditor.$editor.find( '.tux-textarea-documentation' ).val();
      
      
      Severity: Minor
      Found in resources/js/ext.translate.editor.helpers.js - About 1 hr to fix

        Function calculatePointY has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            calculatePointY: function(value, index, datasetIndex) {
                var me = this;
                var chart = me.chart;
                var yScale = me._yScale;
                var sumPos = 0;
        Severity: Minor
        Found in resources/lib/Chart.js/Chart.js - About 1 hr to fix

          Function hsl has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          convert.rgb.hsl = function (rgb) {
              var r = rgb[0] / 255;
              var g = rgb[1] / 255;
              var b = rgb[2] / 255;
              var min = Math.min(r, g, b);
          Severity: Minor
          Found in resources/lib/Chart.js/Chart.js - About 1 hr to fix

            Function proofread has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    proofread: function () {
                        var message = this.message,
                            $message = this.$message,
                            api = new mw.Api();
            
            
            Severity: Minor
            Found in resources/js/ext.translate.proofread.js - About 1 hr to fix

              Function listen has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                      listen: function () {
                          var statsbar = this;
                          statsbar.$statsBar.on( 'change', function ( event, to, from ) {
                              // This updates the value in mw.translate.languagestats as a reference to
                              // the object is returned here.
              Severity: Minor
              Found in resources/js/ext.translate.statsbar.js - About 1 hr to fix

                Function rgb has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                convert.hcg.rgb = function (hcg) {
                    var h = hcg[0] / 360;
                    var c = hcg[1] / 100;
                    var g = hcg[2] / 100;
                
                
                Severity: Minor
                Found in resources/lib/Chart.js/Chart.js - About 1 hr to fix

                  Function handleEvent has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      handleEvent: function(e) {
                          var me = this;
                          var opts = me.options;
                          var type = e.type === 'mouseup' ? 'click' : e.type;
                          var hoveredItem;
                  Severity: Minor
                  Found in resources/lib/Chart.js/Chart.js - About 1 hr to fix

                    Method getArrayDiff has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function getArrayDiff( array $old, array $new ): array {
                            $values = [];
                            $record = static function ( $groups ) use ( &$values ) {
                                foreach ( $groups as $group ) {
                                    $values[$group] = true;
                    Severity: Minor
                    Found in src/MessageLoading/MessageIndex.php - About 1 hr to fix

                      Method execute has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public function execute() {
                              $this->contentLanguage = MediaWikiServices::getInstance()->getContentLanguage();
                      
                              $threads = (int)$this->getOption( 'threads', 1 );
                              $outputDir = $this->getOption( 'output-directory' );
                      Severity: Minor
                      Found in src/TtmServer/ExportTtmServerDumpMaintenanceScript.php - About 1 hr to fix

                        Method createQueryBuilder has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            public function createQueryBuilder( IReadableDatabase $database, string $caller ): SelectQueryBuilder {
                                global $wgTranslateMessageNamespaces;
                        
                                $fields = [ 'log_timestamp' ];
                        
                        
                        Severity: Minor
                        Found in src/Statistics/ReviewPerLanguageStats.php - About 1 hr to fix

                          Method normalize has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              public function normalize( array $validCounts ): void {
                                  $this->formOptions->validateIntBounds( 'days', 1, 10000 );
                                  $this->formOptions->validateIntBounds( 'width', 200, 1000 );
                                  $this->formOptions->validateIntBounds( 'height', 200, 1000 );
                          
                          
                          Severity: Minor
                          Found in src/Statistics/TranslationStatsGraphOptions.php - About 1 hr to fix

                            Method onArticleViewHeader has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                public function onArticleViewHeader( $article, &$outputDone, &$pcache ) {
                                    if ( !$this->enableIntegration ) {
                                        return;
                                    }
                            
                            
                            Severity: Minor
                            Found in src/MessageBundleTranslation/Hooks.php - About 1 hr to fix

                              Method levenshtein has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  public function levenshtein( string $str1, string $str2, int $length1, int $length2 ): int {
                                      if ( $length1 === 0 ) {
                                          return $length2;
                                      }
                              
                              
                              Severity: Minor
                              Found in src/Utilities/StringComparators/EditDistanceStringComparator.php - About 1 hr to fix

                                Method getLatestRevisionsForTags has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                    public function getLatestRevisionsForTags( PageIdentity $identity, string ...$tags ): ?array {
                                        if ( !$identity->exists() ) {
                                            return null;
                                        }
                                
                                
                                Severity: Minor
                                Found in src/MessageGroupProcessing/RevTagStore.php - About 1 hr to fix

                                  Method addValidator has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                      public function addValidator( array $validatorConfig ): void {
                                          $validatorId = $validatorConfig['id'] ?? null;
                                          $className = $validatorConfig['class'] ?? null;
                                  
                                          if ( $validatorId !== null ) {
                                  Severity: Minor
                                  Found in src/Validation/ValidationRunner.php - About 1 hr to fix
                                    Severity
                                    Category
                                    Status
                                    Source
                                    Language