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
move err msg strings to frozen constants #1
Conversation
Hmm. I would probably do this with
at the top of the file instead of multiple https://docs.ruby-lang.org/en/3.2/syntax/comments_rdoc.html#label-frozen_string_literal+Directive |
Also, looking for and not finding the test run results, this shows that the github action file should be updated from
to
|
Also I think these constant names make more sense to me:
|
|
@smiller changes made, action is requiring your approval before running 🤞 bow down before my power (🔋 ) and abuse ( 😈 ) of emjoi's! |
Hmm. The approved action ran and failed. Not for cause – from the run-tests step, the tests passed and the coverage was maintained, but the SimpleCov Report step failed with the complaint Possibly there are different permissions for the GITHUB_TOKEN used in the pull request case? I'll keep digging, and the github action file might need to change again accordingly. I'd like this to run green before I pull it in, but there are no further changes required to the code. Just possibly the action. This has been a useful exercise, thank you! |
Hmm. Went into settings and temporarily gave github actions default “read and write permissions” instead of the basic default of “Read repository contents and packages permissions” and re-ran and it's still failing. (Which, it shouldn't need to write to access the coverage file and generate a report from it, so, that's probably reasonable.) |
And a push to a local branch with the same changes as the PR passes with no problem – https://github.com/smiller/format-dual-language/actions/runs/6339261819 – so it's definitely something to do with the PR case. |
But the same push to a local branch turned into a PR fails in the same place on SimpleCov Report: https://github.com/smiller/format-dual-language/actions/runs/6339437587/job/17218559180 |
lib/processor.rb
Outdated
ERR_INPUT_REQ = "-i FILE option for input file required".freeze | ||
ERR_OUTPUT_REQ = "-o FILE option for output file required".freeze | ||
ERR_INPUT_MISSING = "input file must exist".freeze | ||
ERR_OUTPUT_MISSING = "output file must not exist".freeze |
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.
ERR_INPUT_REQ = "-i FILE option for input file required".freeze | |
ERR_OUTPUT_REQ = "-o FILE option for output file required".freeze | |
ERR_INPUT_MISSING = "input file must exist".freeze | |
ERR_OUTPUT_MISSING = "output file must not exist".freeze | |
ERROR_INPUT_OPTION_MISSING = "-i FILE option for input file required" | |
ERROR_OUTPUT_OPTION_MISSING = "-o FILE option for output file required" | |
ERROR_INPUT_FILE_NOT_FOUND = "input file must exist" | |
ERROR_OUTPUT_FILE_FOUND = "output file must not exist" |
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.
Implicit in this suggestion is of course also adding
# frozen_string_literal: true
to the top of the file.
lib/processor.rb
Outdated
@@ -13,17 +18,17 @@ def validate | |||
@errors = [] | |||
|
|||
if !@options.has_key?(:in) | |||
@errors << "-i FILE option for input file required" | |||
@errors << ERR_INPUT_REQ |
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.
@errors << ERR_INPUT_REQ | |
@errors << ERROR_INPUT_OPTION_MISSING |
lib/processor.rb
Outdated
end | ||
if !@options.has_key?(:out) | ||
@errors << "-o FILE option for output file required" | ||
@errors << ERR_OUTPUT_REQ |
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.
@errors << ERR_OUTPUT_REQ | |
@errors << ERROR_OUTPUT_OPTION_MISSING |
lib/processor.rb
Outdated
end | ||
|
||
if @options.include?(:in) && !File.file?(@options[:in]) | ||
@errors << "input file must exist" | ||
@errors << ERR_INPUT_MISSING |
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.
@errors << ERR_INPUT_MISSING | |
@errors << ERROR_INPUT_FILE_NOT_FOUND |
lib/processor.rb
Outdated
end | ||
if @options.include?(:out) && File.file?(@options[:out]) | ||
@errors << "output file must not exist" | ||
@errors << ERR_OUTPUT_MISSING |
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.
@errors << ERR_OUTPUT_MISSING | |
@errors << ERROR_OUTPUT_FILE_FOUND |
moving Error message string into constant string that are frozen.
at minimum you should freeze strings in place
Since there isn't any reuse making a constant is low value, but giving them a constant name is the beginning of giving them a key for a external file for i13n values