summaryrefslogtreecommitdiff
path: root/danger
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2018-07-25 14:32:44 -0700
committerRobert Speicher <rspeicher@gmail.com>2018-07-25 14:32:44 -0700
commitf5df4976b66caee8bf5c7bdf1f2073251467821d (patch)
tree46e83dea738753f3ebbd30af775a789710e8368a /danger
parent7b6d3974d416bca12360327b147feefeeead01f6 (diff)
downloadgitlab-ce-f5df4976b66caee8bf5c7bdf1f2073251467821d.tar.gz
Make the frozen_string Danger check more resilient
It's possible for a Ruby file to be empty and thus `gets` returns `nil`. Also indents the Markdown since we're using `<<~` and removes an unneeded variable.
Diffstat (limited to 'danger')
-rw-r--r--danger/frozen_string/Dangerfile11
1 files changed, 5 insertions, 6 deletions
diff --git a/danger/frozen_string/Dangerfile b/danger/frozen_string/Dangerfile
index 595176d597d..b9687ef6b83 100644
--- a/danger/frozen_string/Dangerfile
+++ b/danger/frozen_string/Dangerfile
@@ -6,22 +6,21 @@ MAGIC_COMMENT = "# frozen_string_literal: true"
def get_files_with_no_magic_comment(files)
files.select do |file|
file.end_with?(FILE_EXTENSION) &&
- !File.open(file, &:gets).start_with?(MAGIC_COMMENT)
+ !File.open(file, &:gets)&.start_with?(MAGIC_COMMENT)
end
end
-files_to_check = git.added_files
-files_to_fix = get_files_with_no_magic_comment(files_to_check)
+files_to_fix = get_files_with_no_magic_comment(git.added_files)
if files_to_fix.any?
warn 'This merge request adds files that do not enforce frozen string literal. ' \
'See https://gitlab.com/gitlab-org/gitlab-ce/issues/47424 for more information.'
markdown(<<~MARKDOWN)
-## Enable Frozen String Literal
+ ## Enable Frozen String Literal
-The following files should have `#{MAGIC_COMMENT}` in the first line:
+ The following files should have `#{MAGIC_COMMENT}` on the first line:
-* #{files_to_fix.map { |path| "`#{path}`" }.join("\n* ")}
+ * #{files_to_fix.map { |path| "`#{path}`" }.join("\n* ")}
MARKDOWN
end