Add Dangerfile for frozen_string_literal
Checks that new Ruby files will enable frozen string literal. Partially addresses #47424.
This commit is contained in:
parent
d4e9cd9de4
commit
db00a9c641
4 changed files with 35 additions and 3 deletions
|
@ -447,9 +447,8 @@ danger-review:
|
|||
- retry gem install danger --no-ri --no-rdoc
|
||||
cache: {}
|
||||
only:
|
||||
refs:
|
||||
- branches@gitlab-org/gitlab-ce
|
||||
- branches@gitlab-org/gitlab-ee
|
||||
variables:
|
||||
- $DANGER_GITLAB_API_TOKEN
|
||||
except:
|
||||
refs:
|
||||
- master
|
||||
|
|
|
@ -4,3 +4,4 @@ danger.import_dangerfile(path: 'danger/changelog')
|
|||
danger.import_dangerfile(path: 'danger/specs')
|
||||
danger.import_dangerfile(path: 'danger/gemfile')
|
||||
danger.import_dangerfile(path: 'danger/database')
|
||||
danger.import_dangerfile(path: 'danger/frozen_string')
|
||||
|
|
5
changelogs/unreleased/frozen-string-danger.yml
Normal file
5
changelogs/unreleased/frozen-string-danger.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Add Dangerfile for frozen_string_literal
|
||||
merge_request: 20767
|
||||
author: gfyoung
|
||||
type: performance
|
27
danger/frozen_string/Dangerfile
Normal file
27
danger/frozen_string/Dangerfile
Normal file
|
@ -0,0 +1,27 @@
|
|||
# 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) &&
|
||||
!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)
|
||||
|
||||
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
|
||||
|
||||
The following files should have `#{MAGIC_COMMENT}` in the first line:
|
||||
|
||||
* #{files_to_fix.map { |path| "`#{path}`" }.join("\n* ")}
|
||||
MARKDOWN
|
||||
end
|
Loading…
Reference in a new issue