Page MenuHomePhabricator

Grep Linter
Closed, WontfixPublic

Description

It would be nice to have a "grep linter" which one would specify a list of keywords and their severity. For example:

def foo():
  # FIXME(someone): uncomment this before landing.
  #failing_function()

def bar():
  # REVIEWER: Please advise.
  #call_backend_1()
  call_backend_2()

def fib(x):
    # TODO(someonelese): this is to slow. Consider alternative design.
    if x <= 0:
        return 0
    if x == 1:
        return 1
    return fib(x-1) + fib(x-2)

Configuration example:

{
  "linters": {
    "grep": {
      "type": "grep",
      "severity": {
        "FIXME": "error",
        "REVIEWER": "error",
        "TODO": "warning"
      }
    }
  }
}

Supporting regex would be a plus.

Event Timeline

igorgatis raised the priority of this task from to Needs Triage.
igorgatis updated the task description. (Show Details)
igorgatis added a project: Arcanist.
igorgatis added a subscriber: igorgatis.

I think that this is already achievable with the ScriptAndRegexLinter. In addition, ArcanistXHPASTLinter also has this functionality (for PHP only). I feel that language specific linters would be better than just simply grep.

ArcanistMergeConflictLinter does 99% of the job and it is language agnostic. GrepLinter sounds like a very handy tool, IMO.

epriestley claimed this task.
epriestley added a subscriber: epriestley.

ScriptAndRegexLinter needs to be modernized, but is strictly more powerful than the proposed linter. Something like this will implement your desired lint rule after the linter modernizes:

"todo": {
  "type": "script-and-regex",
  "script-and-regex.script": "grep -n TODO --",
  "script-and-regex.regex": "/^(?P<file>[^:]+):(?P<line>\\d+):/"
},

ScriptAndRegexLinter needs to be modernized, but is strictly more powerful than the proposed linter. Something like this will implement your desired lint rule after the linter modernizes:

"todo": {
  "type": "script-and-regex",
  "script-and-regex.script": "grep -n TODO --",
  "script-and-regex.regex": "/^(?P<file>[^:]+):(?P<line>\\d+):/"
},

If anybody wants to use this example, it is currently broken

❯ arc lint
 Exception
Some linters failed:
    - CommandException: Command failed with error #1!
      COMMAND
      grep -n TODO -- 'src/AppBundle/Entity/Serca/obtenerStock.php'

      STDOUT
      (empty)

       STDERR
       (empty)
 (Run with `--trace` for a full exception trace.)

I tried too with the sh workaround and says OKAY No lint warnings..

"script-and-regex.script": "sh -c 'grep -n TODO --\"$0\" || true'",