DEV: Apply syntax_tree formatting to lib/*

This commit is contained in:
David Taylor
2023-01-09 12:10:19 +00:00
parent b0fda61a8e
commit 6417173082
507 changed files with 16550 additions and 12627 deletions

View File

@@ -3,14 +3,19 @@
class StrippedLengthValidator < ActiveModel::EachValidator
def self.validate(record, attribute, value, range)
if value.nil?
record.errors.add attribute, I18n.t('errors.messages.blank')
record.errors.add attribute, I18n.t("errors.messages.blank")
elsif value.length > range.end
record.errors.add attribute, I18n.t('errors.messages.too_long_validation', max: range.end, length: value.length)
record.errors.add attribute,
I18n.t(
"errors.messages.too_long_validation",
max: range.end,
length: value.length,
)
else
value = get_sanitized_value(value)
if value.length < range.begin
record.errors.add attribute, I18n.t('errors.messages.too_short', count: range.begin)
record.errors.add attribute, I18n.t("errors.messages.too_short", count: range.begin)
end
end
end
@@ -23,10 +28,10 @@ class StrippedLengthValidator < ActiveModel::EachValidator
def self.get_sanitized_value(value)
value = value.dup
value.gsub!(/<!--(.*?)-->/, '') # strip HTML comments
value.gsub!(/<!--(.*?)-->/, "") # strip HTML comments
value.gsub!(/:\w+(:\w+)?:/, "X") # replace emojis with a single character
value.gsub!(/\.{2,}/, '…') # replace multiple ... with …
value.gsub!(/\,{2,}/, ',') # replace multiple ,,, with ,
value.gsub!(/\.{2,}/, "") # replace multiple ... with …
value.gsub!(/\,{2,}/, ",") # replace multiple ,,, with ,
value.strip
end
end