Repository: sqlfluff/sqlfluff

Issue:
Double backticks in Lint description
![image](https://user-images.githubusercontent.com/80432516/150420352-57452c80-ad25-423b-8251-645e541579ad.png)
(n.b. this affects a lot more rules than L051)

This was introduced in #2234 in which docstrings such as
```
`INNER JOIN` must be fully qualified.
```
were replaced with 
```
``INNER JOIN`` must be fully qualified.
```
so that they appear as code blocks in Sphinx for docs.
![image](https://user-images.githubusercontent.com/80432516/150420294-eb9d3127-db1d-457c-a637-d614e0267277.png)

However, our rules will use the first line of these docstrings in the event that no `description` is provided to the lint results.

This doesn't look great on the CLI so we should fix this. As far as I'm aware there are two approaches for this:
1. Pass a `description` to all the `LintResult`s.
2. Update the code that gets the default description from the docstring to do something like, replace the double backticks with a single one, or remove them, or do something clever like make them bold for the CLI and remove them for non-CLI.

My strong preference is number 2, but I'm open to discussion as to how exactly we do this 😄 

@barrywhart @tunetheweb 


Discussion:
Number 2 sounds good to me!
@barrywhart which variation?
I would replace with single "normal" quotes: ' rather than \`.

The clever approach could be cool for later, but I wouldn't try it now. I can't remember if we already handle detecting whether we're running in a terminal or not, because the techniques for doing bold or colored text don't work well when redirecting output to a file, etc.
> The clever approach could be cool for later, but I wouldn't try it now. I can't remember if we already handle detecting whether we're running in a terminal or not, because the techniques for doing bold or colored text don't work well when redirecting output to a file, etc.

Yeah I think there's some `isatty` function we use in the formatter, but agree on the simple replace method for now 😄 

Patch:
diff --git a/src/sqlfluff/core/rules/base.py b/src/sqlfluff/core/rules/base.py
--- a/src/sqlfluff/core/rules/base.py
+++ b/src/sqlfluff/core/rules/base.py
@@ -875,7 +875,7 @@ def eval(self, **kwargs):
 
         plugin_name, code = rule_name_match.groups()
         # If the docstring is multiline, then we extract just summary.
-        description = cls.__doc__.split("\n")[0]
+        description = cls.__doc__.replace("``", "'").split("\n")[0]
 
         if plugin_name:
             code = f"{plugin_name}_{code}"


Test patch:
diff --git a/test/core/rules/docstring_test.py b/test/core/rules/docstring_test.py
--- a/test/core/rules/docstring_test.py
+++ b/test/core/rules/docstring_test.py
@@ -1,6 +1,7 @@
 """Test rules docstring."""
 import pytest
 
+from sqlfluff import lint
 from sqlfluff.core.plugin.host import get_plugin_manager
 
 KEYWORD_ANTI = "\n    | **Anti-pattern**"
@@ -34,3 +35,19 @@ def test_keyword_anti_before_best():
                 assert rule.__doc__.index(KEYWORD_ANTI) < rule.__doc__.index(
                     KEYWORD_BEST
                 ), f"{rule.__name__} keyword {KEYWORD_BEST} appears before {KEYWORD_ANTI}"
+
+
+def test_backtick_replace():
+    """Test replacing docstring double backticks for lint results."""
+    sql = """
+    SELECT
+        foo.a,
+        bar.b
+    FROM foo
+    JOIN bar;
+    """
+    result = lint(sql, rules=["L051"])
+    # L051 docstring looks like:
+    # ``INNER JOIN`` must be fully qualified.
+    # Check the double bacticks (``) get replaced by a single quote (').
+    assert result[0]["description"] == "'INNER JOIN' must be fully qualified."
diff --git a/test/rules/std_L054_test.py b/test/rules/std_L054_test.py
--- a/test/rules/std_L054_test.py
+++ b/test/rules/std_L054_test.py
@@ -29,7 +29,7 @@ def test__rules__std_L054_raised() -> None:
     assert len(results_l054) == 2
     assert (
         results_l054[0]["description"]
-        == "Inconsistent column references in ``GROUP BY/ORDER BY`` clauses."
+        == "Inconsistent column references in 'GROUP BY/ORDER BY' clauses."
     )