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

Integration with ERB Lint / StandardRB / Rubocop? #47

Open
thewatts opened this issue Feb 24, 2024 · 2 comments
Open

Integration with ERB Lint / StandardRB / Rubocop? #47

thewatts opened this issue Feb 24, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@thewatts
Copy link

Hi there! :)

I love that you're working on this - it's something my team has needed for a long long time.

Reaching out because we use erb-lint, as well as standard throughout our project.

The fact that this formatted will autoformat is amazing - but I'm finding that it's clashing with our linting rules.

Is it possible for the formatting, for blocks of Ruby content, to possibly leverage another tool's rules? (ex: for erb-lint, we've configured it to use standardrb).

I suppose practically - is it possible to format based on erb-lint's ruleset?

Thanks for your help!

@elia
Copy link
Member

elia commented Feb 26, 2024

Hey @thewatts, thanks!

Before settling on SyntaxTree I tried a few different formatters, including Rufo and Rubocop (Rubocop was especially slow for this use case hard to use for small snippets).

But if you're ok with slower times I'm happy to accept a PR extracting the ruby formatting code

https://github.com/nebulab/erb-formatter/blob/a0955e056da4dff00ed46afd2584087687e103b0/lib/erb/formatter.rb#L266C5-L273

with a pluggable thing and allow for alternative formatters, e.g.:

SYNTAX_TREE_FORMATTER = ->(code) {

    SyntaxTree::Command.prepend SyntaxTreeCommandPatch

    code = begin
      SyntaxTree.format(code, @line_width)
    rescue SyntaxTree::Parser::ParseError => error
      p RUBY_PARSE_ERROR: error if @debug
      code
    end
}

def initialize(...)
  @ruby_formatter = ruby_formatter || SYNTAX_TREE_FORMATTER

# …

def format_ruby(code, autoclose: false)
  # …
  code = @ruby_formatter.call(code)
  # …
end

I just jotted down this code, no need to take names and organization too seriously, I just wanted to convey the idea 😊

@elia elia added the enhancement New feature or request label Feb 26, 2024
@nickpoorman
Copy link

Having the ability to autocrrect the ruby code with something like rubocop would be super helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants