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 cross references #294 #297

Merged

Conversation

stupergenius
Copy link
Contributor

@stupergenius stupergenius commented Oct 24, 2017

Checklist

Description

If I understood #294 correctly, then this should take care of cross-file references at least. I'm not sure of the issue with #286 since none of my findings include any UIKit extension references in the Foundation/Swift extension groups.

What this does not do, currently, is intra-file references to other extensions since this is a difficult one to automate (see below). Specifically, I'm wondering if examples like in NSAttributedString would need to be refactored (since extensions like .bolded use the helper method applying)? Or if just examples like NSURL should be refactored since it's a public extension method that proxies to another? Some guidance here would be appreciated.

Side note: I created a small script that tries to compile each source file individually and emits any errors from the swift compiler to help automate this process. Perhaps this could be cleaned up and added to the Danger file with a nicer report (likely as a separate enhancement PR)?

#!/bin/sh

platformName="$1"

if [ "$platformName" == "" ]; then
	platformName="ios"
fi

if [ "$platformName" == "ios" ]; then
	for sourceFile in Sources/Extensions/**/*.swift; do
		swiftc -target arm64-apple-ios11.0 \
			-sdk $(xcrun --sdk iphoneos --show-sdk-path) \
			-emit-object $sourceFile \
			-o "${sourceFile%.*}.o"
		rm -f "${sourceFile%.*}.o"
		if [ ! $? -eq 0 ]; then
			echo "$sourceFile could not compile"
		fi
	done
fi

if [ "$platformName" == "macos" ]; then
	for sourceFile in Sources/Extensions/**/*.swift; do
		swiftc -target x86_64-apple-macos10.11 \
			-sdk $(xcrun --sdk macosx --show-sdk-path) \
			-emit-object $sourceFile \
			-o "${sourceFile%.*}.o"
		rm -f "${sourceFile%.*}.o"
		if [ ! $? -eq 0 ]; then
			echo "$sourceFile could not compile"
		fi
	done
fi

@SwifterSwiftBot
Copy link

SwifterSwiftBot commented Oct 24, 2017

2 Warnings
⚠️ Consider adding tests for new extensions or updating existing tests for a modified SwifterSwift extension
⚠️ The source files have been modified. Please consider adding a CHANGELOG entry if necessary.
1 Message
📖 Thank you for submitting a pull request to SwifterSwift. The team will review your submission as soon as possible.

Generated by 🚫 Danger

@codecov
Copy link

codecov bot commented Oct 24, 2017

Codecov Report

Merging #297 into master will decrease coverage by 0.03%.
The diff coverage is 93.75%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #297      +/-   ##
=========================================
- Coverage   94.53%   94.5%   -0.04%     
=========================================
  Files          99      99              
  Lines        5529    5639     +110     
=========================================
+ Hits         5227    5329     +102     
- Misses        302     310       +8
Flag Coverage Δ
#ios 94.3% <93.75%> (-0.04%) ⬇️
#osx 60.56% <21.09%> (-0.45%) ⬇️
#tvos 89.34% <93.75%> (+0.06%) ⬆️
Impacted Files Coverage Δ
Sources/Extensions/Foundation/DataExtensions.swift 100% <ø> (ø) ⬆️
Tests/SharedTests/ColorExtensionsTests.swift 100% <100%> (ø) ⬆️
Sources/Extensions/UIKit/UIViewExtensions.swift 61.11% <100%> (ø) ⬆️
...rces/Extensions/SwiftStdlib/StringExtensions.swift 99.36% <100%> (ø) ⬆️
Sources/Extensions/SwiftStdlib/IntExtensions.swift 82.05% <100%> (ø) ⬆️
Sources/Extensions/Foundation/DateExtensions.swift 100% <100%> (ø) ⬆️
Sources/Extensions/Shared/ColorExtensions.swift 98.95% <100%> (+0.25%) ⬆️
Sources/Extensions/UIKit/UITabBarExtensions.swift 86.44% <75.75%> (-13.56%) ⬇️
...es/Extensions/SwiftStdlib/OptionalExtensions.swift 100% <0%> (ø) ⬆️
...sts/SwiftStdlibTests/OptionalExtensionsTests.swift 93.93% <0%> (+5.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e0067e2...cbbec14. Read the comment docs.

@SD10
Copy link
Member

SD10 commented Oct 24, 2017

Hey @stupergenius, thanks for this 👍

I'm not going pretend that I understand the script. I'll have to look at it a bit more closely. It would be nice if you could integrate this with Danger like you mentioned.

You asked for a little more context:

Ultimately, we're trying to remove the dependency of any SwifterSwift extension on another SwifterSwift extension. It doesn't matter if both extensions are on the same type, in the same file, or in the same module.

Each SwifterSwift extension should be able to stand alone if you were to copy & paste it into a project.

@stupergenius
Copy link
Contributor Author

Thanks @SD10. Am I on the right track with 73c1dc1? If so... this kind of use is quite prevalent throughout SwifterSwift so this effort might take some time... and it perhaps goes against the norm of DRY coding styles.

I'm happy to continue along the same lines if this is how the project is intended to be structured, but without a linter capable of preventing such cross use (or a diligent code review team), this style might be difficult to maintain going forward.

@SD10
Copy link
Member

SD10 commented Oct 25, 2017

@stupergenius Yeah this is the right track. We don't need to do everything all at once if there are many instances where this structure occurs. I'd be willing to accept this PR -- but we have to take care of the build errors.

As for not following the DRY principle, this is intentional. A common use case of SwifterSwift is using this project as a reference/collection of code snippets. We want to have each extension stand alone because it gets confusing when you want to copy & paste a single extension into your project -- then have to hunt down all the other dependencies.

@stupergenius stupergenius changed the title [WIP] Remove cross references #294 Remove cross references #294 Oct 26, 2017
@stupergenius
Copy link
Contributor Author

So... I don't really know how to pass these coverage checks if the last commit doesn't push up the coverage enough. The lines that aren't covered are... very difficult to actually get covered (they're primarily graphics context methods that return nil in certain scenarios that don't happen in our SwifterSwift's use of them). They were also never actually covered, but by duplicating some methods it reduces coverage since there's now more overall code to cover.

Suggestions?

@SD10
Copy link
Member

SD10 commented Oct 26, 2017

@stupergenius Don't worry about trivial code coverage deltas 😆 We just try to write tests to the best of our ability. The only check that matters is Travis passing 👍 I should set this up so that Travis is required and codecov is optional, thus making it more explicit

@stupergenius
Copy link
Contributor Author

Heh ok whew. Was about to get creative there. 😂 Otherwise this is ready to merge from my perspective. It still does not do the intra-file de-referencing, but it at least knocks out some cross-file references and provides context for later.

Copy link
Member

@SD10 SD10 left a comment

Choose a reason for hiding this comment

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

LGTM 👍 @LucianoPAlmeida any other input? Feel free to squash + merge if this is good for you

@omaralbeik omaralbeik self-requested a review October 26, 2017 12:08
Copy link
Member

@omaralbeik omaralbeik left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thank you guys 💯

Copy link
Member

@LucianoPAlmeida LucianoPAlmeida left a comment

Choose a reason for hiding this comment

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

Look good to me too :)

@LucianoPAlmeida LucianoPAlmeida merged commit 67e5bbd into SwifterSwift:master Oct 26, 2017
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.

5 participants