Skip to content

Commit 633bd05

Browse files
authoredDec 5, 2024··
Stop raising error if CSS classes are used instead of system arguments (#3219)
Co-authored-by: camertron <camertron@users.noreply.github.com>
1 parent 0bbb076 commit 633bd05

File tree

3 files changed

+6
-57
lines changed

3 files changed

+6
-57
lines changed
 

‎.changeset/wild-shirts-heal.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/view-components": minor
3+
---
4+
5+
Removing the validate classname check that forces system arguments instead of utility classes

‎lib/primer/classify.rb

+1-26
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ def call(args = {})
4949
case key
5050
when :classes
5151
# insert :classes first to avoid huge doc diffs
52-
if (class_names = validated_class_names(val))
53-
result.unshift(class_names)
54-
end
52+
result.unshift(val)
5553
next
5654
when :style
5755
style = val
@@ -105,29 +103,6 @@ def validate(key, val, brk)
105103
brk_str = Primer::Classify::Utilities::BREAKPOINTS[brk]
106104
Primer::Classify::Utilities.validate(key, val, brk_str)
107105
end
108-
109-
def validated_class_names(classes)
110-
return if classes.blank?
111-
112-
if raise_on_invalid_options? && !ENV["PRIMER_WARNINGS_DISABLED"]
113-
invalid_class_names =
114-
classes.split.each_with_object([]) do |class_name, memo|
115-
memo << class_name if Primer::Classify::Validation.invalid?(class_name)
116-
end
117-
118-
if invalid_class_names.any?
119-
raise ArgumentError, "Use System Arguments (https://primer.style/view-components/system-arguments) "\
120-
"instead of Primer CSS class #{'name'.pluralize(invalid_class_names.length)} #{invalid_class_names.to_sentence}. "\
121-
"This warning will not be raised in production. Set PRIMER_WARNINGS_DISABLED=1 to disable this warning."
122-
end
123-
end
124-
125-
classes
126-
end
127-
128-
def raise_on_invalid_options?
129-
Rails.application.config.primer_view_components.raise_on_invalid_options
130-
end
131106
end
132107
end
133108
end

‎test/lib/classify_test.rb

-31
Original file line numberDiff line numberDiff line change
@@ -411,43 +411,12 @@ def test_animation
411411
assert_generated_class("anim-hover-grow", { animation: :hover_grow })
412412
end
413413

414-
def test_does_not_raise_error_when_passing_in_a_primer_css_class_name_in_development_and_flag_is_set
415-
ENV["PRIMER_WARNINGS_DISABLED"] = "1"
416-
with_raise_on_invalid_options(true) do
417-
assert_generated_class("color-bg-primary text-center float-left ml-1", { classes: "color-bg-primary text-center float-left ml-1" })
418-
end
419-
ensure
420-
ENV["PRIMER_WARNINGS_DISABLED"] = nil
421-
end
422-
423-
def test_does_not_raise_error_when_passing_in_a_primer_css_class_otherwise
424-
with_raise_on_invalid_options(false) do
425-
assert_generated_class("color-bg-primary text-center float-left ml-1", { classes: "color-bg-primary text-center float-left ml-1" })
426-
end
427-
end
428-
429414
def test_does_include_leading_trailing_whitespace_in_class
430415
generated_class = Primer::Classify.call(classes: "foo-class")[:class]
431416
refute(generated_class.start_with?(" "))
432417
refute(generated_class.end_with?(" "))
433418
end
434419

435-
def test_raises_if_not_using_system_arguments_when_raise_on_invalid_options_is_true
436-
with_raise_on_invalid_options(true) do
437-
exception = assert_raises ArgumentError do
438-
Primer::Classify.call(classes: "d-block")
439-
end
440-
441-
assert_includes exception.message, "Use System Arguments (https://primer.style/view-components/system-arguments) instead of Primer CSS class"
442-
end
443-
end
444-
445-
def test_does_not_raise_if_not_using_system_arguments_when_raise_on_invalid_options_is_false
446-
with_raise_on_invalid_options(false) do
447-
assert_generated_class("d-block", { classes: "d-block" })
448-
end
449-
end
450-
451420
private
452421

453422
def assert_generated_class(generated_class_name, input)

0 commit comments

Comments
 (0)
Please sign in to comment.