neoformat icon indicating copy to clipboard operation
neoformat copied to clipboard

Add support for standardrb formatter

Open halostatue opened this issue 4 years ago • 1 comments

  • https://github.com/testdouble/standard is an opinionated wrapper around rubocop.
  • Update documentation for ruby#standard
  • Also use the current repo URL for rubocop

halostatue avatar Feb 10 '22 18:02 halostatue

The commit message has been updated to reflect a number of changes required. Please note that this PR now also contains a bug fix for ruby#rubocop when the $SHELL is not bash or zsh (I use fish). There may be other formatters that require similar fixes.

The key point of the updated commit message -- and the bug fixed -- is described below:

  • Adjusted the error output remover for ruby#rubocop and used the same for ruby#standard. The previous version had multiple issues.

    • If the default shell was not more-or-less POSIXly correct (e.g., bash or zsh), the sed recipe might not run correctly because the regex line terminator ($) might result in an attempt to interpret that as a variable. On my macOS machine with fish as my $SHELL, I was getting "could not open file /tmp/…" errors.

    • If there were no errors reported, the terminator line would be found on line 1, which means that it would not be found again, and the format step would clear the file. The cleanest sed-based fix depends on a GNU sed extension, 0,/^====================$/d. This is not how non-GNU seds work, so in the same SO answer where I found the extension, I also found the awk statement used here. I have tested it with constructs that produce errors and those without; only the errors are removed and the reformatted code is returned. It works with both rubocop and standard.

      https://stackoverflow.com/questions/17364951/remove-all-lines-before-a-match-with-sed

      Because the awk statement is relatively complex, it is put into a file-local variable and reused that way.

@sbdchd

halostatue avatar Apr 02 '22 05:04 halostatue

Is it possible get this reviewed?

halostatue avatar Mar 18 '23 00:03 halostatue

Sorry for the delay!

sbdchd avatar Mar 18 '23 00:03 sbdchd