BartyCrouch icon indicating copy to clipboard operation
BartyCrouch copied to clipboard

Unable to run BartyCrouch when project includes other eval such as LineEnding of the CSVImporter library

Open yannisps opened this issue 4 years ago • 1 comments

Expected Behaviour

BartyCrouch update command fails to update the sources and add into translated strings.

caseToLangCode to evaluate to: ["italian": "it", "chineseSimplified": "zh-Hans", "portuguese": "pt-BR", "malay": "ms", "korean": "ko", "chineseTraditional": "zh-Hant", "turkish": "tr", "german": "de", "arabic": "ar", "japanese": "ja", "french": "fr", "english": "en", "spanish": "es", "hindi": "hi", "russian": "ru"] i.e. the contents of the enum SupportedLanguage

Actual Behavior

caseToLangCode evaluates to: ["carriageReturnLineFeed": "\\r\\n", "unknown": "", "newLine": "\\n", "carriageReturn": "\\r"] which is the enum found in the CSVImporter.swift /// An enum to represent the possible line endings of CSV files. public enum LineEnding: String { case newLine = "\n" case carriageReturn = "\r" case carriageReturnLineFeed = "\r\n" case unknown = "" }

As a result no languages are found and consequently no updates take place.

Steps to Reproduce the Problem

  1. Include the Flinesoft CSVImporter or any enum in the Demo project. Following a detailed investigation I discovered the following by adding this line in the Su[pportedLanguagesReader.swift: print("Visiting SupportedLanguagesReader (enumDeclaration.parent?.as(CodeBlockItemSyntax.self) != nil), (enumDeclaration.identifier.text)" , level: .info)

The first test is aways TRUE and the || if enumDeclaration.parent?.as(CodeBlockItemSyntax.self) != nil && enumDeclaration.identifier.text == "SupportedLanguage" always evaluates our TRUE so the code adds any enum it finds in the code as Language Settings. Furthermore, the second test never evaluated to TRUE as the SupportedLanguage is en eval inside BartyCrouch recommended syntax.

My workaround is to make the SupportedLanguage an independent eval from the BartyCrouch eval and change the || of the SupportedLanguagesReader.swift to &&. i.e. from:

enum BartyCrouch {
    enum SupportedLanguage: String {
        case arabic = "ar"
...

to:

enum SupportedLanguage: String {
       // TODO: remove unsupported languages from the following cases list & add any missing languages
        case arabic = "ar"
...
}
enum BartyCrouch {
...

Specifications

  • Version: 4.2.0

yannisps avatar Apr 27 '20 02:04 yannisps

@yannisps Thank you for reporting this bug. It seems to me like you already investigated the code, so I guess you are closer to a solution then I would be when I started to understand the problem. So would you mind taking the next step and fixing this yourself? I'd happily review and merge your PR. In the best case, you would first write a test that fails at the moment, then implement your fix.

Jeehut avatar Apr 28 '20 14:04 Jeehut