Failure to parse a keypath with a subscript

I’ve already reported this on github, but got no response, so trying here.

The following code fails to parse:

paths.sorted(by: \.[0].item)

where paths is of type [[IndexPath]]. This is valid Swift code.

SonarSwift version: 4.2.2
Docker: sonarsource/sonar-scanner-cli:4.3

Hi @sjavora,

you linked a github repo which is not a SonarSource one.

What swift plugin do you have installed?

Could you share the sonar-scanner output log?

Hi, thanks for responding!

Oops. I suppose it was the first one I found that sort of looked like what we were using.

According to the SonarQube admin panel, we are using SonarSwift 4.2.2 (build 77).

Here is the log:

sonar-scanner -Dsonar.projectKey="${CI_PROJECT_PATH//\//:}" -Dsonar.sources=$SONARQUBE_TARGET $SONARQUBE_EXTRA_ARGSe
INFO: Scanner configuration file: /opt/sonar-scanner/conf/
INFO: Project root configuration file: NONE
INFO: SonarScanner
INFO: Java 11.0.3 AdoptOpenJDK (64-bit)
INFO: Linux 5.3.0-1032-gcp amd64
INFO: User cache: /home/scanner-cli/.sonar/cache
INFO: Scanner configuration file: /opt/sonar-scanner/conf/
INFO: Project root configuration file: NONE
INFO: Analyzing on SonarQube server 8.2.0
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Load global settings
INFO: Load global settings (done) | time=128ms
INFO: Server id: D2EFCA25-AVuAwefdOjxzg72yKwki
INFO: User cache: /home/scanner-cli/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=51ms
INFO: Load/download plugins (done) | time=2347ms
INFO: Loaded core extensions: developer-scanner
INFO: Process project properties
INFO: Process project properties (done) | time=8ms
INFO: Execute project builders
INFO: Execute project builders (done) | time=2ms
INFO: Project key: mobile:ios
INFO: Base dir: /builds/mobile/ios
INFO: Working dir: /builds/mobile/ios/.scannerwork
INFO: Load project settings for component key: 'mobile:ios'
INFO: Load project settings for component key: 'mobile:ios' (done) | time=35ms
INFO: Load project branches
INFO: Load project branches (done) | time=36ms
INFO: Load project pull requests
INFO: Load project pull requests (done) | time=26ms
INFO: Load branch configuration
INFO: Load branch configuration (done) | time=2ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=60ms
INFO: Detected Gitlab CI
INFO: Load active rules
INFO: Load active rules (done) | time=991ms
INFO: Branch name: task/MOBILE-18654-i-prepare-screen-for-selecting-passengers
INFO: Indexing files...
INFO: Project configuration:
INFO:   Included sources: **/*.swift
INFO:   Excluded sources: Pods/**, **/Build/**, **/*.framework/**, **/*.playground/**, **/*Test*/**, **/*.h, **/*.m, **/*.json, **/*.png, **/Logs/**, **/*.dylib, **/*.plist, **/*Test*/**
INFO:   Included tests: **/*Test*/**
INFO:   Excluded sources for coverage: test/**, __generated__/*
INFO: 3337 files indexed
INFO: 0 files ignored because of inclusion/exclusion patterns
INFO: 0 files ignored because of scm ignore settings
INFO: Quality profile for swift: Swift - Mobile
INFO: ------------- Run sensors on module mobile:ios
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=31ms
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by net.sf.cglib.core.ReflectUtils$1 (file:/home/scanner-cli/.sonar/cache/a89f1943fc75b65becd9fb4ecab8d913/sonar-tsql-plugin.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,
WARNING: Please consider reporting this to the maintainers of net.sf.cglib.core.ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
INFO: Sensor Import external issues report
INFO: Load project repositories
INFO: Load project repositories (done) | time=129ms
INFO: Imported 86 issues in 45 files
INFO: External issues ignored for 1 unknown files, including: projectname/ViewPlayground.playground/Contents.swift
INFO: Sensor Import external issues report (done) | time=377ms
INFO: Sensor SonarCSS Rules [cssfamily]
INFO: No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
INFO: Sensor SonarCSS Rules [cssfamily] (done) | time=5ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=13ms
INFO: Sensor JavaXmlSensor [java]
INFO: Sensor JavaXmlSensor [java] (done) | time=36ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=10ms
INFO: Sensor SonarSwift [swift]
INFO: 2579 source files to be analyzed
WARN: locking FileBasedConfig[/home/scanner-cli/.config/jgit/config] failed after 5 retries
ERROR: String is not parsed (file projectname/SharedUI/SharedUI/Simple Picker/SimplePickerDataSource.swift, line 17)
7: //
9: import UIKit
10: import Orbit
12: open class SimplePickerDataSource<ItemInformation: Equatable>:
13:              CollectionDataSource<SimplePickerDataSource.DataSourceItem> {
15:     public enum DataSourceItem: Equatable {
16:         case header(title: String, titleColor: UIColor, textAlignment: NSTextAlignment)
17:         case actionItem(SuggestedItem<ItemInformation>, SuggestedItemConfiguration? = nil)
18:         case suggestedItem(SuggestedItem<ItemInformation>, SuggestedItemConfiguration? = nil)
19:         case separator(insets: UIEdgeInsets)
20:     }
22:     public var suggesterHandler: SuggesterHandling
24:     public let separatorInsets = UIEdgeInsets(
25:         top: 0,
26:         left: Spacing.pickerSeparatorPadding.rawValue,
27:         bottom: 0,
INFO: 263/2579 files analyzed, current file: projectname/projectname/LocationPicker/LocationPickerSuggester.swift
INFO: 606/2579 files analyzed, current file: projectname/Networking/Networking/APIDataTransformations.swift
INFO: 924/2579 files analyzed, current file: projectname/projectname/classes/ShareDestinationBehavior.swift
ERROR: String is not parsed (file projectname/SharedUI/SharedUI/View/Collection view layouts/ColumnCollectionLayout/ColumnCollectionLayout.swift, line 487)
477:             let preferredAttributes = self.preferredAttributesCache[identifier] {
478:                 cachedAttributes.size.height = preferredAttributes.size.height
479:                 self.preferredAttributesCache[identifier] = nil
480:             }
481:         }
482:     }
484:     private func maxSizesPerLine(in section: Int, itemsPerLine: Int) -> [CGSize] {
486:         let indexPathsGroupedByLine = itemIndexPaths(in: section).grouped(by: { $0.item / itemsPerLine })
487:         let sortedGroups = indexPathsGroupedByLine.sorted(by: \.[0].item)
489:         return sortedGroups.compactMap { $ { $0.height }) }
490:     }
492:     private func sizeForItem(at indexPath: IndexPath) -> CGSize {
494:         let sectionLayout = sectionLayouts[indexPath.section]
495:         let itemInsets = sectionLayout.insets
496:         let usableWidth = collectionViewWidth - itemInsets.horizontalSize
497:         let width: CGFloat
INFO: 1340/2579 files analyzed, current file: projectname/ManageMyBooking/ManageMyBooking/Shared/Models/CoreData/Entities/OvernightService.swift
INFO: 1823/2579 files analyzed, current file: projectname/Search/Search/Travel Search Results Screen/Result list data sources/TravelSearchResultsDataSource.swift
INFO: 2159/2579 files analyzed, current file: projectname/ManageMyBooking/ManageMyBooking/Shared/Dependencies/BookingDescriptionToFlightDetailTransformer.swift
ERROR: String is not parsed (file projectname/Booking/Booking/Payment/PaymentSteps/BookingPaymentFlowError.swift, line 14)
4: //
5: //  Created by Radim Langer on 05/12/2018.
6: //  Copyright ? 2018 projectname. All rights reserved.
7: //
9: enum BookingPaymentFlowError: Error, Equatable {
10:     case priceChanged
11:     case flightInvalid
12:     case isDuplicateBooking
13:     case confirmationFailedBecauseOfMissingCvvCode
14:     case failed(reason: String, status: SaveBookingStatus, reasons: PaymentFlowErrorReasons? = nil)
15: }
17: enum PaymentErrorCondition: Equatable {
18:     case responseIsNotValid(step: PaymentStep)
19:     case strongSelfDoesNotExist(step: PaymentStep)
20:     case webViewClosedOn3DS2
21:     case cannotInitializeWebViewOn3DS2
22:     case payUPublicKey
23:     case errorInResponseOnConfirmPayment
24:     case unknown
INFO: 2531/2579 files analyzed, current file: projectname/Search/Search/Miscellaneous Views/TextOnlySegmentedControl.swift
INFO: 2579/2579 source files have been analyzed
INFO: Sensor SonarSwift [swift] (done) | time=71241ms
INFO: ------------- Run sensors on project
INFO: Sensor Generic Coverage Report
INFO: Parsing /builds/mobile/ios/artifacts/sonarqube-generic-coverage.xml
INFO: Imported coverage data for 2225 files
INFO: Coverage data ignored for 150 unknown files, including:
INFO: Sensor Generic Coverage Report (done) | time=471ms
INFO: Sensor Dependency-Check [dependencycheck]
INFO: Process Dependency-Check report
INFO: Using JSON-Reportparser
INFO: Dependency-Check JSON report does not exists. Please check property sonar.dependencyCheck.jsonReportPath:/builds/mobile/ios/${WORKSPACE}/dependency-check-report.json
INFO: JSON-Analysis skipped/aborted due to missing report file
INFO: Using XML-Reportparser
INFO: Dependency-Check XML report does not exists. Please check property sonar.dependencyCheck.xmlReportPath:/builds/mobile/ios/${WORKSPACE}/dependency-check-report.xml
INFO: XML-Analysis skipped/aborted due to missing report file
INFO: Dependency-Check HTML report does not exists. Please check property sonar.dependencyCheck.htmlReportPath:/builds/mobile/ios/${WORKSPACE}/dependency-check-report.html
INFO: HTML-Dependency-Check report does not exist.
INFO: Process Dependency-Check report (done) | time=3ms
INFO: Sensor Dependency-Check [dependencycheck] (done) | time=4ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=33ms
INFO: SCM Publisher SCM provider for this project is: git
INFO: SCM Publisher 40 source files to be analyzed
INFO: SCM Publisher 40/40 source files have been analyzed (done) | time=6039ms
INFO: CPD Executor 357 files had no CPD blocks
INFO: CPD Executor Calculating CPD for 2219 files
INFO: CPD Executor CPD calculation finished (done) | time=604ms
INFO: Analysis report generated in 434ms, dir size=17 MB
INFO: Analysis report compressed in 4422ms, zip size=8 MB
INFO: Analysis report uploaded in 749ms
INFO: ------------- Check Quality Gate status
INFO: Waiting for the analysis report to be processed (max 300s)
INFO: Analysis total time: 3:23.898 s
INFO: ------------------------------------------------------------------------
INFO: ------------------------------------------------------------------------
INFO: Total time: 3:27.875s
INFO: Final Memory: 155M/524M
INFO: ------------------------------------------------------------------------

Hi @sjavora,

I created these 2 tickets:

They are going to be fixed in next version.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.