lxxxvi / ruboclean

Ruby gem that puts `.rubocop.yml` into order.
MIT License
18 stars 4 forks source link

wrong identation: expected 4 but 2 #46

Open lain0 opened 1 month ago

lain0 commented 1 month ago

After applying ruboclean .rubocop.yml with:

Lint/ConstantDefinitionInBlock:
  Exclude:
    - test/**/*

it makes it like:

Lint/ConstantDefinitionInBlock:
  Exclude:
  - test/**/*

and my yamllint returns error wrong indentation: expected 4 but found 2 (indentation)

lxxxvi commented 4 weeks ago

Hi @lain0

Thanks for bringing this up. In this gem we use Ruby's built-in YAML parser/emitter named Psych. If I understand correctly, Psych doesn't seem to support setting the indentation level for Lists/Sequences. There is an :indentation option, but that doesn't have the effect that you're looking for.

Let me investigate this a bit more and I'll come back to you later.

lain0 commented 3 weeks ago

https://github.com/ruby/psych/issues/190 in that ticket https://jsonformatter.org/yaml-formatter is supposed to be used to check and it's output for my test and your README.md example is the same identation

---
require:
  - rubocop-rails
AllCops:
  Exclude:
    - path/file_exists.rb
    - path_with_files/**/*
Rails:
  Enabled: true
Layout/LineLength:
  Max: 120
Rails/ShortI18n:
  Enabled: true

instead of

---

require:
- rubocop-rails

AllCops:
  Exclude:
  - path/file_exists.rb
  - path_with_files/**/*

Rails:
  Enabled: true

Layout/LineLength:
  Max: 120

Rails/ShortI18n:
  Enabled: true

yep but you'r right even psych do it wrong even with :indentation option (

data = Psych.load_file('test.yaml')

out = File.open('out.yaml', 'w') do |file|
  file.write(Psych.dump(data))
end
lxxxvi commented 4 days ago

It looks like we cannot/should not fix the indentation problem, in my opinion. What do you think?

For your workflow, could it make sense to have yamllint to autofix the indentation (not just report it) after ruboclean has run? There may be even no need to yamllint .rubocop.yml in the first place, since it has been processed by ruboclean? (I'm not here to judge your setup/workflow, please don't get me wrong)

lain0 commented 3 days ago

You are right becouse two most problem cases and In both of them i belive we just want to keep identation that we have befor ruboclean. So wnen needed add hook for yamllint after ruboclean is good idea.