-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Share code between cask token and formula name audits. #17562
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,40 @@ | ||||||||||
# typed: true | ||||||||||
# frozen_string_literal: true | ||||||||||
|
||||||||||
module Homebrew | ||||||||||
class TokenAuditor | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Thoughts? Token is cask-specific so I think maybe "name" is clearer in this case. NBD though either way There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, but also I'll leave it up to other people for their thoughts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
or something. I agree |
||||||||||
sig { returns(String) } | ||||||||||
attr_reader :token | ||||||||||
|
||||||||||
sig { params(token: String).void } | ||||||||||
def initialize(token) | ||||||||||
@token = token | ||||||||||
end | ||||||||||
|
||||||||||
sig { returns(T::Array[String]) } | ||||||||||
def errors | ||||||||||
errors = [] | ||||||||||
|
||||||||||
errors << "uppercase letters" if token.match?(/[A-Z]/) | ||||||||||
errors << "whitespace" if token.match?(/\s/) | ||||||||||
errors << "non-ASCII characters" unless token.ascii_only? | ||||||||||
errors << "double hyphens" if token.include?("--") | ||||||||||
|
||||||||||
# A bunch of formulae contain these: | ||||||||||
# errors << "underscores" if token.include?("_") | ||||||||||
# errors << "plus symbols" if token.include?("+") | ||||||||||
Comment on lines
+24
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe accept the formula or cask itself in the initializer and then check these only if it's a cask? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given we allow There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't feel strongly at the moment, but the comments should be removed if this is the plan There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I'll remove the comments before merging. We should check if casks should be renamed/aliased ( |
||||||||||
|
||||||||||
errors << "a leading @" if token.start_with?("@") | ||||||||||
errors << "a trailing @" if token.end_with?("@") | ||||||||||
errors << "a leading hyphen" if token.start_with?("-") | ||||||||||
errors << "a trailing hyphen" if token.end_with?("-") | ||||||||||
|
||||||||||
errors << "multiple @ symbols" if token.count("@") > 1 | ||||||||||
|
||||||||||
errors << "a hyphen followed by an @" if token.include? "-@" | ||||||||||
errors << "an @ followed by a hyphen" if token.include? "@-" | ||||||||||
|
||||||||||
errors | ||||||||||
end | ||||||||||
end | ||||||||||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or