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

Simplify and allow to configure rubocop formatter #403

Merged
merged 5 commits into from
Jan 28, 2021

Commits on Jan 28, 2021

  1. fix(formatter): avoid temporary files when formatting with RuboCop

    By supplying the file content to RubyCop as a in-memory string the same
    way as RuboCop's own CLI tool handles STDIN, we completely avoid having
    to write any temporary files to disk, and formatting can occur purely
    in-memory.
    
    This also has the benefit of Solargraph no longer needing to be
    responsible for finding and passing along any config file paths. RuboCop
    will correctly find any relevant .rubocop.yml files for the file being
    formatted, as RuboCop behaves exactly as if it was running against the
    real file in it's original location on disk, except with the content it
    is formatting coming from the in-memory string rather than reading it
    from the file on disk.
    
    A new blank formatter is also passed to RuboCop, just to make it print
    as little as possible to STDOUT, since we don't need and ignore the
    STDOUT produced.
    jimeh committed Jan 28, 2021
    Configuration menu
    Copy the full SHA
    17eb6d1 View commit details
    Browse the repository at this point in the history
  2. feat(formatter): add "formatter" option to .solargraph.yml

    Allows customizing if format command should run safe, or all cops when
    formatting files.
    
    Also includes a `extra_args` option to pass custom CLI arguments to
    RuboCop. If you primarily only format via solargraph interactively from
    an editor, it might be useful to disable certain cops that causes
    annoyances in interactive use. For example:
    
        formatter:
          cops: safe # use "all" to include unsafe cops
          extra_args:
            - --except
            - Lint/Debugger,Lint/UnusedBlockArgument,Lint/UnusedMethodArgument,Style/EmptyMethod
    jimeh committed Jan 28, 2021
    Configuration menu
    Copy the full SHA
    b2ca68c View commit details
    Browse the repository at this point in the history
  3. chore(diagnostics): don't pass .rubocop.yml file path to RuboCop

    RuboCop will itself find and use any relevant configuration files based
    on the file path of the file it is analyzing. Hence there is no need for
    Solargraph to have it's own implementation of this logic.
    jimeh committed Jan 28, 2021
    Configuration menu
    Copy the full SHA
    730fa47 View commit details
    Browse the repository at this point in the history
  4. chore(formatter): future proof rubocop formatter configuration structure

    Solargraph will gain support for multiple formatters soon, so let's
    ensure configuration for the rubocop formatter is future proof.
    
    New nested configuration:
    
        formatter:
          rubocop:
            cops: all
            extra_args: []
    
    Previously:
    
        formatter:
          cops: all
          extra_args: []
    jimeh committed Jan 28, 2021
    Configuration menu
    Copy the full SHA
    10fd861 View commit details
    Browse the repository at this point in the history
  5. feat(formatter): add "except" and "only" rubocop formatter options

    They take a list or comma separated string of cops, which will be passed
    to rubocop as --except and/or --only.
    
    The "except" option is useful to disable cops which can cause annoyance
    when using solargraph's formatter as a before save hook in text
    editors.
    
    I'm less aware of what the "only" option might be useful for, but might
    as well add it so both are covered.
    jimeh committed Jan 28, 2021
    Configuration menu
    Copy the full SHA
    7122c49 View commit details
    Browse the repository at this point in the history