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

Remove init requirement & syntax sugar from Withable #50

Merged
merged 6 commits into from
Jun 20, 2020
Merged

Conversation

Jeehut
Copy link
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
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

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

Choose a reason for hiding this comment

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

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
Member Author

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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
Member Author

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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
Member Author

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

["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
Member Author

Choose a reason for hiding this comment

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

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
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
{
dataExporterHelper.exportData(
"""
]
Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -0,0 +1,547 @@
#!/usr/local/bin/swift-sh
import AnyLint // @Flinesoft ~> 0.8.2
Copy link
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
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
Member Author

Choose a reason for hiding this comment

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


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

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

}
""",
"""
guard let collection = viewModel.myCollection(),
Copy link
Member Author

Choose a reason for hiding this comment

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

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
Member Author

Choose a reason for hiding this comment

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

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
Member Author

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

["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
Member Author

Choose a reason for hiding this comment

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

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
Member Author

Choose a reason for hiding this comment

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


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

Choose a reason for hiding this comment

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

],
[
"before": "param: callFunction(errorMessage != nil ? errorMessage! : L10n.Global.Info.success),\n",
"after": "param: callFunction(errorMessage ?? L10n.Global.Info.success),\n"
Copy link
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
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