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:
jpy-git: Whoopsie, Updated that test now 😄 
codecov[bot]: # [Codecov](https://codecov.io/gh/sqlfluff/sqlfluff/pull/2386?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sqlfluff) Report
> Merging [#2386](https://codecov.io/gh/sqlfluff/sqlfluff/pull/2386?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sqlfluff) (e1fbc47) into [main](https://codecov.io/gh/sqlfluff/sqlfluff/commit/23d698607b45b8469c766b521d27e9a6e92e8739?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sqlfluff) (23d6986) will **not change** coverage.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/sqlfluff/sqlfluff/pull/2386/graphs/tree.svg?width=650&height=150&src=pr&token=maM8kLgCmn&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sqlfluff)](https://codecov.io/gh/sqlfluff/sqlfluff/pull/2386?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sqlfluff)

```diff
@@           Coverage Diff           @@
##             main    #2386   +/-   ##
=======================================
  Coverage   99.93%   99.93%           
=======================================
  Files         161      161           
  Lines       11494    11494           
=======================================
  Hits        11486    11486           
  Misses          8        8           
```


| [Impacted Files](https://codecov.io/gh/sqlfluff/sqlfluff/pull/2386?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sqlfluff) | Coverage Δ | |
|---|---|---|
| [src/sqlfluff/core/rules/base.py](https://codecov.io/gh/sqlfluff/sqlfluff/pull/2386/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sqlfluff#diff-c3JjL3NxbGZsdWZmL2NvcmUvcnVsZXMvYmFzZS5weQ==) | `100.00% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/sqlfluff/sqlfluff/pull/2386?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sqlfluff).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sqlfluff)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/sqlfluff/sqlfluff/pull/2386?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sqlfluff). Last update [23d6986...e1fbc47](https://codecov.io/gh/sqlfluff/sqlfluff/pull/2386?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sqlfluff). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=sqlfluff).


Patch:
diff --git a/src/sqlfluff/core/rules/base.py b/src/sqlfluff/core/rules/base.py
index c581b8bd1..737fa0191 100644
--- a/src/sqlfluff/core/rules/base.py
+++ b/src/sqlfluff/core/rules/base.py
@@ -875,7 +875,7 @@ class RuleSet:
 
         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
index 4ee7aec94..edc8e4f19 100644
--- 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
index 09738ef71..599d0d680 100644
--- 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."
     )