Repository: sqlfluff/sqlfluff

Issue:
Update warning for parsing errors found on the ansi dialect
### Search before asking

- [X] I searched the [issues](https://github.com/sqlfluff/sqlfluff/issues) and found no similar issues.


### Description

In the past specifying a dialect was **optional**. If unspecified, the dialect defaulted to `ansi`. Because of this there is a warning presented when sqlfluff runs in parse mode and the dialect is set to ansi and parsing errors are encountered.

`WARNING: Parsing errors found and dialect is set to 'ansi'. Have you configured your dialect?`

Currently, specifying a dialect is **mandatory**. Therefore this warning is perhaps not needed... and certainly not needed in its current form.

I opened this issue to document the idea and solicit feedback. 
1. The simplest improvement to make the message more appropriate is to just change it to this:

`WARNING: Parsing errors found and dialect is set to 'ansi'. Is 'ansi' the correct dialect?`

2. On the other hand, we know that the user explicitly set the dialect to `ansi`. So why bother asking if it was intentional? We don't ask if you meant postgres or tsql. There's an argument to simply remove the warning altogether.

3. Finally, we could potentially differentiate between `--dialect ansi` passed on the command line vs the dialect being picked up from a `.sqlfluff` config file. Perhaps the warning should be displayed only the in the case where the dialect was picked up implicitly from the config file.

### Use case

_No response_

### Dialect

ansi

### Are you willing to work on and submit a PR to address the issue?

- [X] Yes I am willing to submit a PR!

### Code of Conduct

- [X] I agree to follow this project's [Code of Conduct](https://github.com/sqlfluff/sqlfluff/blob/main/CODE_OF_CONDUCT.md)



Discussion:
Pending feedback from the admins, I'm happy to submit a pull request on this one.
Been thinking about it, and I think we should show the message for all dialects. Some people might be using an incorrect dialect if their dialect is not supported.

Patch:
diff --git a/src/sqlfluff/cli/commands.py b/src/sqlfluff/cli/commands.py
--- a/src/sqlfluff/cli/commands.py
+++ b/src/sqlfluff/cli/commands.py
@@ -1079,8 +1079,10 @@ def _print_out_violations_and_timing(
             output_stream.write("==== parsing violations ====")  # pragma: no cover
         for v in parsed_string.violations:
             output_stream.write(format_violation(v))  # pragma: no cover
-        if parsed_string.violations and parsed_string.config.get("dialect") == "ansi":
-            output_stream.write(format_dialect_warning())  # pragma: no cover
+        if parsed_string.violations:
+            output_stream.write(
+                format_dialect_warning(parsed_string.config.get("dialect"))
+            )
 
         if verbose >= 2:
             output_stream.write("==== timings ====")
diff --git a/src/sqlfluff/cli/formatters.py b/src/sqlfluff/cli/formatters.py
--- a/src/sqlfluff/cli/formatters.py
+++ b/src/sqlfluff/cli/formatters.py
@@ -187,12 +187,12 @@ def format_dialects(dialect_readout, verbose=0):
     return text_buffer.getvalue()
 
 
-def format_dialect_warning():  # pragma: no cover
-    """Output a warning for parsing errors found on the ansi dialect."""
+def format_dialect_warning(dialect):
+    """Output a warning for parsing errors."""
     return colorize(
         (
             "WARNING: Parsing errors found and dialect is set to "
-            "'ansi'. Have you configured your dialect?"
+            f"'{dialect}'. Have you configured your dialect correctly?"
         ),
         Color.lightgrey,
     )
@@ -321,9 +321,9 @@ def dispatch_compilation_header(self, templater, message):
             f"=== [{colorize(templater, Color.lightgrey)}] {message}"
         )  # pragma: no cover
 
-    def dispatch_dialect_warning(self) -> None:
+    def dispatch_dialect_warning(self, dialect) -> None:
         """Dispatch a warning for dialects."""
-        self._dispatch(format_dialect_warning())  # pragma: no cover
+        self._dispatch(format_dialect_warning(dialect))  # pragma: no cover
 
     def _format_file_violations(
         self, fname: str, violations: List[SQLBaseError]
diff --git a/src/sqlfluff/core/linter/linter.py b/src/sqlfluff/core/linter/linter.py
--- a/src/sqlfluff/core/linter/linter.py
+++ b/src/sqlfluff/core/linter/linter.py
@@ -723,11 +723,11 @@ def lint_parsed(
             )
 
         # Safety flag for unset dialects
-        if parsed.config.get("dialect") == "ansi" and linted_file.get_violations(
+        if linted_file.get_violations(
             fixable=True if fix else None, types=SQLParseError
         ):
             if formatter:  # pragma: no cover TODO?
-                formatter.dispatch_dialect_warning()
+                formatter.dispatch_dialect_warning(parsed.config.get("dialect"))
 
         return linted_file
 


Test patch:
diff --git a/test/cli/commands_test.py b/test/cli/commands_test.py
--- a/test/cli/commands_test.py
+++ b/test/cli/commands_test.py
@@ -100,6 +100,53 @@ def test__cli__command_dialect():
     )
 
 
+def test__cli__command_parse_error_dialect_explicit_warning():
+    """Check parsing error raises the right warning."""
+    # For any parsing error there should be a non-zero exit code
+    # and a human-readable warning should be dislayed.
+    # Dialect specified as commandline option.
+    result = invoke_assert_code(
+        ret_code=66,
+        args=[
+            parse,
+            [
+                "-n",
+                "--dialect",
+                "postgres",
+                "test/fixtures/cli/fail_many.sql",
+            ],
+        ],
+    )
+    assert (
+        "WARNING: Parsing errors found and dialect is set to 'postgres'. "
+        "Have you configured your dialect correctly?" in result.stdout
+    )
+
+
+def test__cli__command_parse_error_dialect_implicit_warning():
+    """Check parsing error raises the right warning."""
+    # For any parsing error there should be a non-zero exit code
+    # and a human-readable warning should be dislayed.
+    # Dialect specified in .sqlfluff config.
+    result = invoke_assert_code(
+        ret_code=66,
+        args=[
+            # Config sets dialect to tsql
+            parse,
+            [
+                "-n",
+                "--config",
+                "test/fixtures/cli/extra_configs/.sqlfluff",
+                "test/fixtures/cli/fail_many.sql",
+            ],
+        ],
+    )
+    assert (
+        "WARNING: Parsing errors found and dialect is set to 'tsql'. "
+        "Have you configured your dialect correctly?" in result.stdout
+    )
+
+
 def test__cli__command_dialect_legacy():
     """Check the script raises the right exception on a legacy dialect."""
     result = invoke_assert_code(