Skip to content

Remove init requirement & syntax sugar from Withable#50

Merged
Jeehut merged 6 commits intomainfrom
wip/cg_withable
Jun 20, 2020
Merged

Remove init requirement & syntax sugar from Withable#50
Jeehut merged 6 commits intomainfrom
wip/cg_withable

Conversation

@Jeehut
Copy link
Copy Markdown
Member

@Jeehut Jeehut commented Jun 20, 2020

Fixes #49.

Proposed Changes

  • Remove the init() requirement from Withable.
  • Remove the init syntax sugar method that allowed Foo { $0.bar = 5} in favor of Foo().with { $0.bar = 5}.
  • Adds support for Foo(bar: 5).with { $0.otherProperty = true } without requiring init() on Foo type.

Copy link
Copy Markdown
Member Author

Jeehut commented Jun 20, 2020

Codacy Here is an overview of what got changed by this pull request:

Issues
======
- Added 50
           

See the complete overview on Codacy

Comment thread lint.swift
excludeFilters: [testFiles],
autoCorrectReplacement: #"{ $1 in"#,
autoCorrectExamples: [
["before": "run { (a) in", "after": "run { a in"],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lint.swift
autoCorrectExamples: [
["before": "run { (a) in", "after": "run { a in"],
["before": "run { (a, b) in", "after": "run { a, b in"],
["before": "run { (a, b, c) in", "after": "run { a, b, c in"]
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lint.swift
excludeFilters: [testFiles],
autoCorrectReplacement: "$callPart1!.$callPart2!.$callPart3",
autoCorrectExamples: [
["before": "let x = (viewModel?.profile?.imagePath)!\n", "after": "let x = viewModel!.profile!.imagePath\n"]
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lint.swift
excludeFilters: [testFiles],
autoCorrectReplacement: "$callPart1!.$callPart2!.$callPart3!.$callPart4",
autoCorrectExamples: [
["before": "let x = (viewModel?.user?.profile?.imagePath)!\n", "after": "let x = viewModel!.user!.profile!.imagePath\n"]
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lint.swift
// MARK: EmptyTodo
try Lint.checkFileContents(
checkInfo: "EmptyTodo: `// TODO:` comments should not be empty.",
regex: #"// TODO: ?(\[[\d\-_a-z]+\])? *\n"#,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lint.swift
try Lint.checkFileContents(
checkInfo: "SingleLineGuard: Use a single line guard for simple checks.",
regex: #"guard\s*([^\{]{2,80})\s+else\s*\{\s*\n\s*(return[^\n]{0,40}|continue|fatalError\([^\n;]+\))\s*\}"#,
matchingExamples: ["guard x else {\n return\n}", "guard x else {\n return 2 * x.squared(x: {15})\n}", #"guard x else {\#n fatalError("some message: \(x)")\#n}"#],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lint.swift
"callPart3": #"[^\s\?\.]+"#,
"separator3": #"\?\."#,
"callPart4": #"[^\s\?\.]+"#,
"closingBraceUnwrap": #"\)!"#
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lint.swift
["before": "init(\n x: Int,\n y: Int\n) {\n \n}", "after": "init(\n x: Int,\n y: Int\n) {}"],
["before": "func foo2bar() { }", "after": "func foo2bar() {}"],
["before": "func foo2bar(x: Int, y: Int) { }", "after": "func foo2bar(x: Int, y: Int) {}"],
["before": "func foo2bar()\n{\n \n}", "after": "func foo2bar() {}"],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lint.swift
try Lint.checkFileContents(
checkInfo: "EmptyTodo: `// TODO:` comments should not be empty.",
regex: #"// TODO: ?(\[[\d\-_a-z]+\])? *\n"#,
matchingExamples: ["// TODO:\n", "// TODO: [2020-03-19]\n", "// TODO: [cg_2020-03-19] \n"],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jeehut Jeehut merged commit eddbe17 into main Jun 20, 2020
Comment thread lint.swift
{
dataExporterHelper.exportData(
"""
]
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lint.swift
@@ -0,0 +1,547 @@
#!/usr/local/bin/swift-sh
import AnyLint // @Flinesoft ~> 0.8.2
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jeehut Jeehut deleted the wip/cg_withable branch June 20, 2020 14:16
Comment thread lint.swift
checkInfo: "SingleLineGuard: Use a single line guard for simple checks.",
regex: #"guard\s*([^\{]{2,80})\s+else\s*\{\s*\n\s*(return[^\n]{0,40}|continue|fatalError\([^\n;]+\))\s*\}"#,
matchingExamples: ["guard x else {\n return\n}", "guard x else {\n return 2 * x.squared(x: {15})\n}", #"guard x else {\#n fatalError("some message: \(x)")\#n}"#],
nonMatchingExamples: ["guard x else { return }", "guard x else { return 2 * x.squared(x: {15}) }", #"guard x else { fatalError("some message: \(x)") }"#],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lint.swift

// MARK: IfAsGuard
try Lint.checkFileContents(
checkInfo: "IfAsGuard: Don't use an if statement to just return – use guard for such cases instead.",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lint.swift
excludeFilters: [testFiles],
autoCorrectReplacement: "$callPart1!.$callPart2",
autoCorrectExamples: [
["before": "call(x: (viewModel?.username)!)", "after": "call(x: viewModel!.username)"]
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lint.swift
}
""",
"""
guard let collection = viewModel.myCollection(),
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lint.swift
try Lint.checkFileContents(
checkInfo: "NavigationControllerVariableNaming: Always name your navigation controller variables with the suffix `NavCtrl` or just `navCtrl`.",
regex: #"(var|let) +(nc|navigationcontroller|navc|ncontroller|navcontroller)[ :][^\n=]*=\i"#,
matchingExamples: ["let nc =", "var navigationController =", "let navc =", "let ncontroller =", "var nc: MyNavigationController =", "let navController: MyNavigationController<T> = "],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lint.swift
try Lint.checkFileContents(
checkInfo: "ClosureParamsParantheses: Don't use parantheses around non-typed parameters in a closure.",
regex: #"\{\s*\(((?!self)[^):]+)\)\s*in"#,
matchingExamples: ["run { (a) in", "run { (a, b) in", "run { (a, b, c) in"],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lint.swift
regex: #"guard\s*([^\n]*,\n)+([^\n]*\S *)else\s*\{"#,
matchingExamples: [
"""
guard
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lint.swift
excludeFilters: [testFiles],
autoCorrectReplacement: "$callPart1!.$callPart2",
autoCorrectExamples: [
["before": "call(x: (viewModel?.username)!)", "after": "call(x: viewModel!.username)"]
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lint.swift
"callPart3": #"[^\s\?\.]+"#,
"closingBraceUnwrap": #"\)!"#
],
matchingExamples: ["call(x: (viewModel?.profile?.username)!)"],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lint.swift
"closingBraceUnwrap": #"\)!"#
],
matchingExamples: ["call(x: (viewModel?.username)!)"],
nonMatchingExamples: ["call(x: (viewModel?.profile?.username)!)", "call(x: viewModel!.username)"],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lint.swift
["before": "init()\n{\n \n}", "after": "init() {}"],
["before": "init(\n x: Int,\n y: Int\n) {\n \n}", "after": "init(\n x: Int,\n y: Int\n) {}"],
["before": "func foo2bar() { }", "after": "func foo2bar() {}"],
["before": "func foo2bar(x: Int, y: Int) { }", "after": "func foo2bar(x: Int, y: Int) {}"],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lint.swift
checkInfo: "EmptyTodo: `// TODO:` comments should not be empty.",
regex: #"// TODO: ?(\[[\d\-_a-z]+\])? *\n"#,
matchingExamples: ["// TODO:\n", "// TODO: [2020-03-19]\n", "// TODO: [cg_2020-03-19] \n"],
nonMatchingExamples: ["// TODO: refactor", "// TODO: not yet implemented", "// TODO: [cg_2020-03-19] not yet implemented"],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lint.swift

// MARK: SingleLineGuard
try Lint.checkFileContents(
checkInfo: "SingleLineGuard: Use a single line guard for simple checks.",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread lint.swift
],
[
"before": "param: callFunction(errorMessage != nil ? errorMessage! : L10n.Global.Info.success),\n",
"after": "param: callFunction(errorMessage ?? L10n.Global.Info.success),\n"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jeehut
Copy link
Copy Markdown
Member Author

Jeehut commented Jun 20, 2020

@knothed What do you think of this? Since you implemented this in the first place, do you agree with my changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Withable not working on custom types with init parameters

1 participant