diff options
author | Rémy Coutable <remy@rymai.me> | 2018-07-24 13:03:09 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2018-07-24 13:03:09 +0000 |
commit | a90a080aef481828a923f76a99036276032406d8 (patch) | |
tree | 31f8d257c4f8c91495acbc45e9c3d7f20ca9ebd1 | |
parent | 4de8a3dab1d578a6f8176ec40e2b4bae2468adf2 (diff) | |
parent | db00a9c6418377526359ed0bd0efd62491f14084 (diff) | |
download | gitlab-ce-a90a080aef481828a923f76a99036276032406d8.tar.gz |
Merge branch 'frozen-string-danger' into 'master'
Check Frozen String Literal in Danger
See merge request gitlab-org/gitlab-ce!20767
-rw-r--r-- | .gitlab-ci.yml | 5 | ||||
-rw-r--r-- | Dangerfile | 1 | ||||
-rw-r--r-- | changelogs/unreleased/frozen-string-danger.yml | 5 | ||||
-rw-r--r-- | danger/frozen_string/Dangerfile | 27 |
4 files changed, 35 insertions, 3 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index afe9da08495..c7ef75d1c32 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 diff --git a/Dangerfile b/Dangerfile index 84b72673c50..9217610da8b 100644 --- a/Dangerfile +++ b/Dangerfile @@ -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') diff --git a/changelogs/unreleased/frozen-string-danger.yml b/changelogs/unreleased/frozen-string-danger.yml new file mode 100644 index 00000000000..9910139b8a9 --- /dev/null +++ b/changelogs/unreleased/frozen-string-danger.yml @@ -0,0 +1,5 @@ +--- +title: Add Dangerfile for frozen_string_literal +merge_request: 20767 +author: gfyoung +type: performance diff --git a/danger/frozen_string/Dangerfile b/danger/frozen_string/Dangerfile new file mode 100644 index 00000000000..595176d597d --- /dev/null +++ b/danger/frozen_string/Dangerfile @@ -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 |