2018-07-22 14:28:17 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
FILE_EXTENSION = ".rb"
|
|
|
|
MAGIC_COMMENT = "# frozen_string_literal: true"
|
|
|
|
|
|
|
|
def get_files_with_no_magic_comment(files)
|
|
|
|
files.select do |file|
|
|
|
|
file.end_with?(FILE_EXTENSION) &&
|
2018-07-25 17:32:44 -04:00
|
|
|
!File.open(file, &:gets)&.start_with?(MAGIC_COMMENT)
|
2018-07-22 14:28:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-25 17:32:44 -04:00
|
|
|
files_to_fix = get_files_with_no_magic_comment(git.added_files)
|
2018-07-22 14:28:17 -04:00
|
|
|
|
|
|
|
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)
|
2018-07-25 17:32:44 -04:00
|
|
|
## Enable Frozen String Literal
|
2018-07-22 14:28:17 -04:00
|
|
|
|
2018-07-25 17:32:44 -04:00
|
|
|
The following files should have `#{MAGIC_COMMENT}` on the first line:
|
2018-07-22 14:28:17 -04:00
|
|
|
|
2018-07-25 17:32:44 -04:00
|
|
|
* #{files_to_fix.map { |path| "`#{path}`" }.join("\n* ")}
|
2018-07-22 14:28:17 -04:00
|
|
|
MARKDOWN
|
|
|
|
end
|