Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiline function parameters #44

Open
meteora8888 opened this issue Aug 27, 2021 · 1 comment
Open

Multiline function parameters #44

meteora8888 opened this issue Aug 27, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@meteora8888
Copy link

I am was working on this autocorrect for long single line function headers so it automatically corrects them into multiple lines but since it was too complex i broke it into two separate autocorrects. First to break paramters into a singular line away from the func ( ) -> x surounding it and a second one that cycles over the match and break the last parameters onto a separate line every cycle. However eventhough it matches correctly as soon as I apply autocorrection to the second rule nothing ever changes. Please help me I am very confused because event if I switch out the replacement for litterally any matching group it ignored the autocorrect

`let longMultilineFunctionDefMatchingExample = "static func defaultAlert(verylongStringToPutToMultipleLineThatExceeds120charactersForSureSinceItIsSoVeryLongOhMyGod: Sting) {\n}"
let longMultilineFunctionDefNonMatchingExample1 = "\tstatic func defaultAlert(title: String, title: String, title: String, message: String) {\n}"
let longMultilineFunctionDefBeforeAutocorrect = "\tstatic func defaultAlert(verylongStringToPutToMultipleLineThatExceeds120charactersForSureSinceItIsSoVeryLongOhMyGod: String){\n}"
let longMultilineFunctionDefAfterAutocorrect = "\tstatic func defaultAlert(\n\t\tverylongStringToPutToMultipleLineThatExceeds120charactersForSureSinceItIsSoVeryLongOhMyGod: String\n\t){\n}"
try Lint.checkFileContents(
checkInfo: "Long multiparameter function: Parameters of functions above 120 character should be split into multiple lines",
regex: #"^(?=.{121,})(?[ \t])(?

[a-zA-Z@ ]func[a-zA-Z<> ]()(?.)(?).(?:->){0,1}.{)$"#,
matchingExamples: [longMultilineFunctionDefMatchingExample],
nonMatchingExamples: [longMultilineFunctionDefNonMatchingExample1],
includeFilters: [#".*.swift"#],
excludeFilters: excludeFilters,
autoCorrectReplacement: "$SPACING$HEADER\n$SPACING\t$PARAMETERS\n$SPACING$HEADEND",
autoCorrectExamples: [
["before": longMultilineFunctionDefBeforeAutocorrect,
"after": longMultilineFunctionDefAfterAutocorrect]
]
)

try Lint.checkFileContents(
    checkInfo: "Multiline function definition: Parameters of functions above 120 character should be split into multiple lines",
    regex: #"^(?<SPACING>[ \t]*)(?<HEADER>(?:[a-zA-Z@ ]*)func.*\()\n^[ \t]*(?<PARAMETERSTOKEEP>(?:.*\: .*,(?!\n))+) (?<PARAMETERSTOFORMAT>(?:\s*.*\: .*,{0,1}(?=\n))*)\n^(?<HEADEND>[ \t]*\).*(?:->){0,1}.*\{(?=\n))$"#,
    matchingExamples: ["func makePendingEventsSections(\nfor pendingEvents: [Event], photos: [RolePhoto], statusOverviews: [PresenceOverviewResponse]\n) -> [Section] {\n}"],
    nonMatchingExamples: ["\tstatic func defaultAlert(\ntitle: String) {"],
    includeFilters: [#".*\.swift"#],
    excludeFilters: excludeFilters,
    autoCorrectReplacement: "$SPACING$HEADER\n$SPACING\t$PARAMETERSTOKEEP\n$SPACING\t$PARAMETERSTOFORMAT\n$SPACING$HEADEND",
    autoCorrectExamples: [
        ["before": "static func defaultAlert(\n\ttitle: String, title: String, title: String, message: String, hi hi: no, in controller: (UIViewController\n) -> Void) {\n}",
         "after": "static func defaultAlert(\n\ttitle: String, title: String, title: String, message: String, hi hi: no,\n\tin controller: (UIViewController\n) -> Void) {\n}"]
    ],
    repeatIfAutoCorrected: true
)`

Expected Behavior

single line function parameters break into separate lines each

Actual Behavior

first rule works having all parameters on one line but second one is ignored (eventhough it matches)

Steps to Reproduce the Problem

  1. Run anylint with the stated autocorrect
  2. use this code as an example class func from( html: String?, font: (regular: UIFont, bold: UIFont), color: UIColor, documentAttributes: AutoreleasingUnsafeMutablePointer<NSDictionary?>? = nil ) -> NSAttributedString? { return from(html: html, font: font, size: font.regular.pointSize, color: color, documentAttributes: documentAttributes) }

Specifications

  • Version: flinesoft/anylint/anylint 0.8.2
  • Platform: iOS
  • IDE Version: Xcode 12.5.1
@meteora8888 meteora8888 added the bug Something isn't working label Aug 27, 2021
@Jeehut
Copy link
Member

Jeehut commented Apr 26, 2022

Hey @meteora8888, sorry for getting back to you this late, I didn't notice the email last year when you first wrote this and I'm just seeing it.

I've copied and tried out your check, the regex seems to trigger in the tests but not in real files, that's really weird. I don't see anything you're doing wrong, I will have to further investigate what's going on internally in AnyLint to know what the issue is, but looks like a bug in AnyLint, thanks for reporting. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants