Skip to content
代码片段 群组 项目
未验证 提交 b1498252 编辑于 作者: Paul Gascou-Vaillancourt's avatar Paul Gascou-Vaillancourt 提交者: GitLab
浏览文件

Add Tailwind CSS Dangerfile

This adds a new Dangerfile to do some Tailwind-related reporting.
Currently, we check whether the diff potentially contains interpolated
CSS utils. We might extend this rule to report additional info about CSS
utils usages.
上级 ef3e17b7
No related branches found
No related tags found
无相关合并请求
# frozen_string_literal: true
module Danger
class Tailwind
FRONTEND_INTERPOLATION_PATTERN = /gl-[0-9a-z-]+(\$\{|['"] ?\+)/
BACKEND_INTERPOLATION_PATTERN = /gl-[0-9a-z-]+(#\{|['"] ?\+)/
def initialize(helper, git)
@helper = helper
@git = git
end
def report_interpolated_utils
frontend_files_with_interpolated_utils = files_with_interpolated_utils(
frontend_tailwindy_files(@helper.all_changed_files), FRONTEND_INTERPOLATION_PATTERN)
backend_files_with_interpolated_utils = files_with_interpolated_utils(
backend_tailwindy_files(@helper.all_changed_files), BACKEND_INTERPOLATION_PATTERN)
return "" if frontend_files_with_interpolated_utils.empty? && backend_files_with_interpolated_utils.empty?
<<~MARKDOWN
### Interpolated utils
The following files might contain interpolated utils:
#{format_files_list(frontend_files_with_interpolated_utils + backend_files_with_interpolated_utils)}
If you are leveraging CSS utilities, make sure they are written in full and not built via string
interpolation as that would prevent Tailwind CSS from generating them.
MARKDOWN
end
private
def frontend_tailwindy_files(files)
files.select do |file|
file.end_with?('.vue', '.js')
end
end
def backend_tailwindy_files(files)
files.select do |file|
file.end_with?('.html.haml', '.rb')
end
end
def files_with_interpolated_utils(files, pattern)
files.select do |file|
diff = @git.diff_for_file(file)
diff.patch.each_line.any? do |line|
line.start_with?('+') && line.match?(pattern)
end
end
end
def format_files_list(files)
files.map do |file|
"- `#{file}`"
end.join("\n")
end
end
end
danger_tailwind = Danger::Tailwind.new(helper, git)
report = danger_tailwind.report_interpolated_utils
unless report.empty?
markdown <<~MSG
## Tailwind CSS
#{report}
MSG
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册