Autofix with S&RX linter

Is it possible to configure autofixes with the S&RX linter? In my case, the linter is configured to run a script that matches regex against a given file to find tabs and warn that they should be replaced with spaces - is there a way the linter can then replace the tabs with spaces?

Should be possible. See original and replacement parameters. https://secure.phabricator.com/book/phabricator/article/arcanist_lint_script_and_regex/

Yup, looks like this is what I need. I am having some trouble getting the regex parser to work as expected, though.

For the sake of not having to deal with parsing whitespace for my testing, I’m currently having the linter replace foo with bar.

My script-and-regex.script prints the following line when ran against a file that contains foo; at line 3:

autofix:3 Use 4 spaces instead of tabs:foo:bar

This is in the format severity:line message:original:replacement, which I am then attempting to capture with the following script-and-regex.regex:

/^(?P<severity>disabled|autofix|advice|warning|error):(?P<line>[0-9]+) (?P<message>[^:]*):(?P<original>[^:]*):(?P<replacement>[^:]*)$/m

From what I can tell, foo is being captured as the original, and bar is being captured as the replacement, but the actual patch itself is behaving strangely:

>>> Lint for file:


   Auto-Fix  (S&RX) Lint
    Use 4 spaces instead of tabs

               1 <?php
               2 
    >>> -      3 foo;
        +        foobar
               4 
               5
               6 
--- file	2019-06-25 10:48:34.236577968 -0500
+++ /tmp/1nmob1nqs0u8wow4/22481-CcKMfK	2019-06-25 10:48:35.444557762 -0500
@@ -1,6 +1,6 @@
 <?php
-
-foo;
+bar
+o;
 

 


    Apply this patch to file? [Y/n] y

The original file contained the following:

<?php

foo;

But the autofix patch generates this file:

<?php
bar
o;

Is this perhaps a regex issue? I’m unsure, since it seems to be capturing the original and replacement fine, but something in the actual patch logic seems wonky. I’d appreciate any insight on this.

bump

Try https://regex101.com/ for testing your regex.

Try https://regex101.com/ for testing your regex.

I’ve been testing my regex with sed and grep, and also tried using that site, and as far as I can tell, everything should be working fine. Since the linter is attempting to modify multiple lines, I don’t believe it to be an issue with my regex.