How to make script-and-regex linter accept unified diff input?


#1

I have a tool that outputs error messages in this format:

<FILE> has incorrect formatting
<UNIFIED DIFF>
<FILE> has incorrect formatting
<UNIFIED DIFF>
<... repeat ...>
<number of files> file(s) formatted incorrectly

How do I capture the uppercase elements with the script-and-regex linter in order to provide autofix support? I had a look at the docstring in arcanist/src/lint/linter/ArcanistScriptAndRegexLinter.php, but could not figure it out.

With my current configuration it appears that this linter treats every line separately, which would make it impossible to capture a diff. In this case: Would it be possible to extend it with a patch capture, that captures the unified diff until the next appearance of file or EOF, and apply that to the last mentioned file?

As an alternative, this tool also comes with an own command to automatically fix the issues. Could an script-and-regex.autofix-script option (or similar) be added, which can be run to autofix the reported issues, if the users requests it?


#2

The regex must be a valid PHP PCRE regex, including delimiters and flags.
The regex will be matched against the entire output of the script, so it should generally be in this form if messages are one-per-line:
/^...$/m

In this syntax, ^ means “beginning of line” and $ means “end of line”. In your case, you’d want to replace them with whatever string delimits the different sections/files.

script-and-regex is not likely to ever gain more features, because it’s already too complicated for its own good. See https://secure.phabricator.com/T10038 for the future of linters in general, which is basically “write your own, and one day will have an app-store for them”. There are plenty of examples for lint wrappers, so it shouldn’t be too hard.