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

[Linter] check frameworks attribute for invalid frameworks #96

Merged
merged 5 commits into from
Apr 5, 2014
Merged

[Linter] check frameworks attribute for invalid frameworks #96

merged 5 commits into from
Apr 5, 2014

Conversation

squarefrog
Copy link
Contributor

Added regex to fail any frameworks/libraries that allow non-alphanumeric characters. Closes #66

@@ -381,7 +382,7 @@ def frameworks_invalid?(frameworks)
# @return [Boolean] true if a library ends with `.a`, `.dylib`, or
Copy link
Member

Choose a reason for hiding this comment

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

Can you update the comment here like you did above for frameworks?

@joshkalpin
Copy link
Member

Just a few small comments but awesome job. Can you make sure to add an entry to the CHANGELOG.md file?

#
def frameworks_invalid?(frameworks)
frameworks.any? { |framework| framework.end_with?('.framework') }
frameworks.any? { |framework| framework =~ /[^a-zA-Z\d]/ }
Copy link
Member

Choose a reason for hiding this comment

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

This may be bad ruby conventions (not the ruby expert here), but it might make sense to make the regex a variable so we can easily modify it we need to add/remove stuff from it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it would help to document the code. E.g.

framework_regex = /[^a-zA-Z\d]/
framework ~= framework_regex

But we'll see how it looks when the old lines are added back in.

@squarefrog
Copy link
Contributor Author

👍 some great comments there. Ill action them all tomorrow morning.

@@ -381,7 +382,7 @@ def frameworks_invalid?(frameworks)
# @return [Boolean] true if a library ends with `.a`, `.dylib`, or
# starts with `lib`.
def libraries_invalid?(libs)
libs.any? { |lib| lib.end_with?('.a', '.dylib') || lib.start_with?('lib') }
Copy link
Member

Choose a reason for hiding this comment

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

same for this please keep it:

This can be changed to:

libs.any? do |lib| 
  next true if lib.end_with?('.a', '.dylib')
  next true if lib.start_with?('lib')
  next true if lib =~ /^(lib)|([^a-zA-Z\d])/
  false
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic is covered by the regex. Anything that starts lib will be covered by ^(lib). While not explicit, the [a-zA-Z\d] picks up any strings with a file extension.

If you want the old behaviour for documentation purposes, then thats fine, but in terms of a matcher it's possibly redundant.

@fabiopelosin
Copy link
Member

This logic is covered by the regex. Anything that starts lib will be covered by ^(lib). While not explicit, the [a-zA-Z\d] picks up any strings with a file extension.

Sorry, I missed this point... so for me the code is fine as it is (without the duplication). The important is that the different tests cases are preserved to clarify the intent of the code and that the documentation at the top of each method explicits mentions the goals.

@@ -367,10 +367,11 @@ def _validate_compiler_flags(flags)
# @params frameworks [Array<String>]
# The frameworks to be validated
#
# @return [Boolean] true if a framework ends in `.framework`
# @return [Boolean] true if a framework contains any
# non-alphanumeric character
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer to be explicit: ... or includes an extension.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@irrationalfab I agree that is much clearer. I'll add that now.

I did not remove any of the tests which test the old behaviour, as they exercise this new code as well. It's better to have too many tests than not enough!

Copy link
Member

Choose a reason for hiding this comment

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

gif

@joshkalpin
Copy link
Member

Looks good to me if @irrationalfab agrees 😸

@fabiopelosin fabiopelosin merged commit 8fd22cd into CocoaPods:master Apr 5, 2014
@fabiopelosin
Copy link
Member

Ace thanks for the patch!

@squarefrog
Copy link
Contributor Author

It was my pleasure! Hopefully I can contribute again soon! Thanks for your support.

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.

[Linter] check frameworks attribute for invalid frameworks
3 participants