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

Validate explicit ACL modifiers for top-level declarations #58

Closed
jpsim opened this issue May 28, 2015 · 5 comments
Closed

Validate explicit ACL modifiers for top-level declarations #58

jpsim opened this issue May 28, 2015 · 5 comments
Labels
rule-request Requests for a new rules.

Comments

@jpsim
Copy link
Collaborator

jpsim commented May 28, 2015

Top-level declarations should use explicit ACL keywords (public, internal, private).

@jpsim jpsim added the rule-request Requests for a new rules. label May 28, 2015
@keith
Copy link
Collaborator

keith commented Aug 11, 2015

It looks like there's no difference to sourcekit whether or not internal is specified. Using sourcekitten's structure the only difference between:

class Foo {}

And:

internal class Foo {}

Is the offset. This would have to be handled by examining the file as well.

@segiddins
Copy link
Contributor

@keith examining the contents of the declaration would probably suffice for this?

@keith
Copy link
Collaborator

keith commented Aug 11, 2015

It seems like the class declaration key's offset starts after the modifiers. So in the second example from above the offset is 9. This could cause issue for cases like:

internal final class Foo {}

Or something crazier like:

internal
class Foo {}

@jpsim
Copy link
Collaborator Author

jpsim commented Aug 23, 2015

Here's a rough algorithm to do this:

  1. find all top-level internal type declarations: see https://github.com/realm/SwiftLint/blob/master/Source/SwiftLintFramework/Rules/TypeNameRule.swift.
  2. find all internal modifiers: File.matchPattern("internal", withSyntaxKinds: [.AttributeBuiltin]).
  3. throw style violations for declarations found in step 1 with no associated internal modifier from step 2.

@jdmarshall90
Copy link

Could this be enhanced to include all declarations, and not just top-level ones?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule-request Requests for a new rules.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants