Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stylelint violations when using Tailwind #1153

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/generators/suspenders/lint_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ def install_gems
end

def configure_stylelint
copy_file "stylelintrc.json", ".stylelintrc.json"
if using_tailwind?
copy_file "tailwind.stylelintrc.json", ".stylelintrc.json"
else
copy_file "stylelintrc.json", ".stylelintrc.json"
end
end

def configure_eslint
Expand Down
11 changes: 11 additions & 0 deletions lib/generators/templates/lint/tailwind.stylelintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "@thoughtbot/stylelint-config",
"rules": {
"scss/at-rule-no-unknown": [
true,
{
"ignoreAtRules": ["tailwind"]
}
]
}
}
4 changes: 4 additions & 0 deletions lib/suspenders/generators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def default_test_helper_present?
def rspec_test_helper_present?
File.exist? Rails.root.join("spec/rails_helper.rb")
end

def using_tailwind?
File.exist? Rails.root.join("tailwind.config.js")
end
end

module APIAppUnsupported
Expand Down
24 changes: 24 additions & 0 deletions test/generators/suspenders/lint_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,30 @@ class LintGeneratorTest < Rails::Generators::TestCase
end
end

test "configures stylelint for tailwind" do
expected_content = <<~TEXT
{
"extends": "@thoughtbot/stylelint-config",
"rules": {
"scss/at-rule-no-unknown": [
true,
{
"ignoreAtRules": ["tailwind"]
}
]
}
}
TEXT

with_css_option :tailwind do
capture(:stderr) { run_generator }

assert_file app_root(".stylelintrc.json") do |file|
assert_equal expected_content, file
end
end
end

test "configures eslint" do
expected_content = <<~JSON
{
Expand Down
15 changes: 15 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ def with_test_suite(test_suite, &block)
remove_dir_if_exists "spec"
end

def with_css_option(css, &block)
case css
when :postcss
touch "postcss.config.js"
when :tailwind
touch "tailwind.config.js"
else
raise ArgumentError, "unknown css option: #{css.inspect}"
end
yield
ensure
remove_file_if_exists "postcss.config.js"
remove_file_if_exists "tailwind.config.js"
end

def backup_file(file)
FileUtils.copy app_root(file), app_root("#{file}.bak")
end
Expand Down