Commit 944ff4a6 authored by Markus Koller's avatar Markus Koller

Remove custom Danger check for frozen_string_literal comments

This is redundant with Rubocop's Style/FrozenStringLiteralComment cop,
which we didn't have enabled when this was introduced.

To preserve the same behaviour we also:

- Switch to `EnforcedStyle: always_true`, to forbid `false` values.
- Replace the wildcard list with an explicit list of all violations,
  so we still catch all newly added files.
parent 83c7e006
...@@ -78,21 +78,7 @@ Style/AccessModifierDeclarations: ...@@ -78,21 +78,7 @@ Style/AccessModifierDeclarations:
# Frozen String Literal # Frozen String Literal
Style/FrozenStringLiteralComment: Style/FrozenStringLiteralComment:
Enabled: true Enabled: true
Exclude: EnforcedStyle: always_true
- 'config.ru'
- 'Dangerfile'
- 'Gemfile'
- 'Rakefile'
- 'app/views/**/*'
- 'config/**/*'
- 'danger/**/*'
- 'db/**/*'
- 'ee/db/**/*'
- 'ee/lib/tasks/**/*'
- 'lib/tasks/**/*'
- 'qa/**/*'
- 'rubocop/**/*'
- 'scripts/**/*'
RSpec/FilePath: RSpec/FilePath:
Exclude: Exclude:
......
This diff is collapsed.
# frozen_string_literal: true
FILE_EXTENSION = ".rb"
FROZEN_STRING_MAGIC_COMMENT = "# frozen_string_literal: true"
SHEBANG_COMMENT = "#!"
def get_files_with_no_magic_comment(files)
files.select do |path|
path.end_with?(FILE_EXTENSION) &&
!file_has_frozen_string_magic_comment?(path)
end
end
def file_has_frozen_string_magic_comment?(path)
File.open(path) do |file|
first_line = file.gets
line_has_frozen_string_magic_comment?(first_line) ||
(line_has_shebang?(first_line) &&
line_has_frozen_string_magic_comment?(file.gets))
end
end
def line_has_frozen_string_magic_comment?(line)
line&.start_with?(FROZEN_STRING_MAGIC_COMMENT)
end
def line_has_shebang?(line)
line&.start_with?(SHEBANG_COMMENT)
end
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-foss/issues/47424 for more information.'
if GitlabDanger.new(helper.gitlab_helper).ci?
markdown(<<~MARKDOWN)
## Enable Frozen String Literal
The following files should have `#{FROZEN_STRING_MAGIC_COMMENT}` on the first line:
* #{files_to_fix.map { |path| "`#{path}`" }.join("\n* ")}
MARKDOWN
end
end
...@@ -4,7 +4,6 @@ class GitlabDanger ...@@ -4,7 +4,6 @@ class GitlabDanger
LOCAL_RULES ||= %w[ LOCAL_RULES ||= %w[
changes_size changes_size
documentation documentation
frozen_string
duplicate_yarn_dependencies duplicate_yarn_dependencies
prettier prettier
eslint eslint
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment