Repository: sqlfluff/sqlfluff

Issue:
Disable the safeties on `fix`
>  `The fix option is only available in combination with --rules. This is for your own safety!`
> I appreciate the concern, but git takes care of my safety needs, and while evaluating sqlfluff it would be really useful to see what it wants our SQL to be.

We should consider removing the requirement to specify rules on the `fix` command if it's hindering people trying the tool. This feature may just be a relic of when the `fix` routines were less reliable.

@barrywhart - thoughts?

Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7b7057b26..4414f9f43 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -72,6 +72,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
   sensible caching and optimising loops within functions.
 
 ### Removed
+- From the CLI, the `--no-safety` option has been removed, the default
+  is now that all enabled rules will be fixed.
 - Removed `BaseSegment.grammar`, `BaseSegment._match_grammar()` and
   `BaseSegment._parse_grammar()` instead preferring references directly
   to `BaseSegment.match_grammar` and `BaseSegment.parse_grammar`.
diff --git a/benchmarks/benchmarks.yml b/benchmarks/benchmarks.yml
index ee77ed5f7..9fdafc038 100644
--- a/benchmarks/benchmarks.yml
+++ b/benchmarks/benchmarks.yml
@@ -4,5 +4,5 @@ benchmarks:
     - name: B_001_package
       cmd: ['sqlfluff', 'parse', '--bench', 'benchmarks/bench_001_package.sql']
     - name: B_002_pearson
-      cmd: ['sqlfluff', 'fix', '-f', '-s', '--bench',
+      cmd: ['sqlfluff', 'fix', '-f', '--bench',
             '--fixed-suffix', '_fix', 'benchmarks/bench_002/bench_002_pearson.sql']
diff --git a/src/sqlfluff/cli/commands.py b/src/sqlfluff/cli/commands.py
index c0d0feecb..a930d548f 100644
--- a/src/sqlfluff/cli/commands.py
+++ b/src/sqlfluff/cli/commands.py
@@ -375,18 +375,8 @@ def do_fixes(lnt, result, formatter=None, **kwargs):
 @click.option(
     "--fixed-suffix", default=None, help="An optional suffix to add to fixed files."
 )
-@click.option(
-    "-s",
-    "--no-safety",
-    is_flag=True,
-    help=(
-        "Disable the safety of requiring --rules to be specified. **Use this with caution.**"
-    ),
-)
 @click.argument("paths", nargs=-1)
-def fix(
-    force, paths, bench=False, fixed_suffix="", no_safety=False, logger=None, **kwargs
-):
+def fix(force, paths, bench=False, fixed_suffix="", logger=None, **kwargs):
     """Fix SQL files.
 
     PATH is the path to a sql file or directory to lint. This can be either a
@@ -396,7 +386,6 @@ def fix(
     """
     # some quick checks
     fixing_stdin = ("-",) == paths
-    no_safety = no_safety or fixing_stdin  # saftey not needed if fixing stdin
 
     c = get_config(**kwargs)
     lnt, formatter = get_linter_and_formatter(c, silent=fixing_stdin)
@@ -409,23 +398,6 @@ def fix(
     # Set up logging.
     set_logging_level(verbosity=verbose, logger=logger)
 
-    # Check that if fix is specified, that we have picked only a subset of rules
-    if no_safety:
-        if not fixing_stdin:
-            click.echo(
-                colorize("NO SAFETY", "red")
-                + ": Attempting fixes for all enabled rules."
-            )
-    elif lnt.config.get("rule_whitelist") is None:
-        click.echo(
-            (
-                "The fix option is only available in combination"
-                " with --rules. This is for your own safety! To"
-                " disable this safety feature use --no-safety or --s."
-            )
-        )
-        sys.exit(1)
-
     # handle stdin case. should output formatted sql to stdout and nothing else.
     if fixing_stdin:
         stdin = sys.stdin.read()


Test patch:
diff --git a/test/cli/commands_test.py b/test/cli/commands_test.py
index 8c677e4f1..80b7ea858 100644
--- a/test/cli/commands_test.py
+++ b/test/cli/commands_test.py
@@ -177,11 +177,10 @@ def test__cli__command_lint_stdin(command):
                 "test/fixtures/cli/fail_many.sql",
             ],
         ),
-        # Fix without safety
+        # Fix without specifying rules
         (
             fix,
             [
-                "--no-safety",
                 "--fixed-suffix",
                 "_fix",
                 "test/fixtures/cli/fail_many.sql",
@@ -370,10 +369,6 @@ def test__cli__command_fix_stdin_safety():
     result = invoke_assert_code(args=[fix, ("-",)], cli_input=perfect_sql)
     assert result.output.strip() == perfect_sql
 
-    # still no warning if no safety specified unnecessarily
-    result = invoke_assert_code(args=[fix, ("-", "--no-safety")], cli_input=perfect_sql)
-    assert result.output.strip() == perfect_sql
-
 
 @pytest.mark.parametrize(
     "rule,fname,prompt,exit_code",
@@ -454,7 +449,7 @@ def test__cli__command_lint_serialize_from_stdin(serialize, sql, expected, exit_
     "command",
     [
         [lint, ("this_file_does_not_exist.sql")],
-        [fix, ("this_file_does_not_exist.sql", "--no-safety")],
+        [fix, ("this_file_does_not_exist.sql")],
     ],
 )
 def test__cli__command_fail_nice_not_found(command):