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

Support filePrivate for Private Unit Test Rule in Swift 3 #781

Closed
cfilipov opened this issue Aug 26, 2016 · 4 comments
Closed

Support filePrivate for Private Unit Test Rule in Swift 3 #781

cfilipov opened this issue Aug 26, 2016 · 4 comments

Comments

@cfilipov
Copy link
Collaborator

#761 has been merged which adds a rule to detect private XCTests (which XCTest will silently not skip). This issue is to serve as a reminder that this rule should be updated when Swift 3 support is added because filePrivate has the same effect as private on unit tests.

@bdbergeron
Copy link

Any update on fileprivate support? I'd like to enable some opt-in rules such as private_outlet that currently give me warnings.

@cfilipov
Copy link
Collaborator Author

@bdbergeron I don't know if it's possible for SwiftLint to lint Swift < 3.x sources without itself being Swift 3 (which as far as I can tell it is not yet). In any case, I can probably guess at what the AST keys will be but unless I can run/debug and unit test against Swift 3 I don't see much point. I'm waiting for SwiftLint itself to move to Swift 3 before I can update this rule. There are a number of dependencies that would probably also need to update to Swift 3 before this project (SourceKitten being the most relevant).

@cfilipov
Copy link
Collaborator Author

@bdbergeron By the way, can you elaborate on what you mean about private_outlet? I can't imagine any case where you would want IBOutlets in unit tests. Are you getting false positives on private outlets? If that's the case, that might be my fault and that issue is now fixed but hasn't been cut into a release yet (though I would expect that to only occur on IBActions and only when the action's name begins with test).

@jpsim
Copy link
Collaborator

jpsim commented Nov 24, 2016

Sorry for my absence @cfilipov. Slowly trying to work through my backlog of SwiftLint notifications 😅 .

I don't know if it's possible for SwiftLint to lint Swift < 3.x sources without itself being Swift 3 (which as far as I can tell it is not yet)

Yes! The Swift version used to build SwiftLint is unrelated to the versions of Swift it can lint! That's because SourceKit is dynamically found and linked. SwiftLint looks for a Swift toolchain in the following order:

  • $XCODE_DEFAULT_TOOLCHAIN_OVERRIDE
  • $TOOLCHAIN_DIR
  • xcrun -find swift
  • /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
  • /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
  • ~/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
  • ~/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain

There are a number of dependencies that would probably also need to update to Swift 3 before this project

SourceKitten has supported Swift 3 essentially since day one, thanks to the same runtime linking mechanism as above, even though its codebase itself was only converted to Swift 3 a few weeks ago.

No other dependencies interact with SourceKit, so nothing needs to be updated.


I think the "only" things that need to be changed to support fileprivate and open ACL keywords is to add them to the AccessControlLevel enum in MissingDocsRule.swift and adapt rules that would be affected. This can be done now, without having to update any dependencies.

norio-nomura added a commit that referenced this issue Nov 30, 2016
* commit '83830861d6c6b7fee3218461f699c7d3b457bf2a':
  refactor isPrivateLevel(identifier:)
  refactor nameStrippingLeadingUnderscoreIfPrivate
  combine changelog entries for #781 and #831
  Add support for filePrivate and open in rules

# Conflicts:
#	Source/SwiftLintFramework/Extensions/String+SwiftLint.swift
#	Source/SwiftLintFramework/Rules/MissingDocsRule.swift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants