Skip to content

Commit 8628dcb

Browse files
Fix stylelint violations when using Tailwind (#1153)
When we introduced #1148 we did not test it against applications that invoked `suspenders:styles --css=tailwind`.
1 parent 551d60b commit 8628dcb

File tree

5 files changed

+59
-1
lines changed

5 files changed

+59
-1
lines changed

lib/generators/suspenders/lint_generator.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ def install_gems
2121
end
2222

2323
def configure_stylelint
24-
copy_file "stylelintrc.json", ".stylelintrc.json"
24+
if using_tailwind?
25+
copy_file "tailwind.stylelintrc.json", ".stylelintrc.json"
26+
else
27+
copy_file "stylelintrc.json", ".stylelintrc.json"
28+
end
2529
end
2630

2731
def configure_eslint
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"extends": "@thoughtbot/stylelint-config",
3+
"rules": {
4+
"scss/at-rule-no-unknown": [
5+
true,
6+
{
7+
"ignoreAtRules": ["tailwind"]
8+
}
9+
]
10+
}
11+
}

lib/suspenders/generators.rb

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def default_test_helper_present?
1818
def rspec_test_helper_present?
1919
File.exist? Rails.root.join("spec/rails_helper.rb")
2020
end
21+
22+
def using_tailwind?
23+
File.exist? Rails.root.join("tailwind.config.js")
24+
end
2125
end
2226

2327
module APIAppUnsupported

test/generators/suspenders/lint_generator_test.rb

+24
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,30 @@ class LintGeneratorTest < Rails::Generators::TestCase
5353
end
5454
end
5555

56+
test "configures stylelint for tailwind" do
57+
expected_content = <<~TEXT
58+
{
59+
"extends": "@thoughtbot/stylelint-config",
60+
"rules": {
61+
"scss/at-rule-no-unknown": [
62+
true,
63+
{
64+
"ignoreAtRules": ["tailwind"]
65+
}
66+
]
67+
}
68+
}
69+
TEXT
70+
71+
with_css_option :tailwind do
72+
capture(:stderr) { run_generator }
73+
74+
assert_file app_root(".stylelintrc.json") do |file|
75+
assert_equal expected_content, file
76+
end
77+
end
78+
end
79+
5680
test "configures eslint" do
5781
expected_content = <<~JSON
5882
{

test/test_helper.rb

+15
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,21 @@ def with_test_suite(test_suite, &block)
100100
remove_dir_if_exists "spec"
101101
end
102102

103+
def with_css_option(css, &block)
104+
case css
105+
when :postcss
106+
touch "postcss.config.js"
107+
when :tailwind
108+
touch "tailwind.config.js"
109+
else
110+
raise ArgumentError, "unknown css option: #{css.inspect}"
111+
end
112+
yield
113+
ensure
114+
remove_file_if_exists "postcss.config.js"
115+
remove_file_if_exists "tailwind.config.js"
116+
end
117+
103118
def backup_file(file)
104119
FileUtils.copy app_root(file), app_root("#{file}.bak")
105120
end

0 commit comments

Comments
 (0)