Skip to content

Commit 00a18e1

Browse files
committed
Add skip_lints
1 parent 4761a85 commit 00a18e1

4 files changed

Lines changed: 39 additions & 1 deletion

File tree

sqlmesh/cli/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ def diff(ctx: click.Context, environment: t.Optional[str] = None) -> None:
339339
is_flag=True,
340340
help="Skip tests prior to generating the plan if they are defined.",
341341
)
342+
@click.option(
343+
"--skip-lints",
344+
is_flag=True,
345+
help="Skip linting prior to generating the plan if the linter is enabled.",
346+
)
342347
@click.option(
343348
"--restate-model",
344349
"-r",

sqlmesh/core/context.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,7 @@ def plan(
11351135
no_diff: t.Optional[bool] = None,
11361136
run: bool = False,
11371137
diff_rendered: bool = False,
1138+
skip_lints: bool = False,
11381139
) -> Plan:
11391140
"""Interactively creates a plan.
11401141
@@ -1179,6 +1180,7 @@ def plan(
11791180
no_diff: Hide text differences for changed models.
11801181
run: Whether to run latest intervals as part of the plan application.
11811182
diff_rendered: Whether the diff should compare raw vs rendered models
1183+
skip_lints: Linter runs by default so this will skip it if enabled
11821184
11831185
Returns:
11841186
The populated Plan object.
@@ -1205,6 +1207,7 @@ def plan(
12051207
enable_preview=enable_preview,
12061208
run=run,
12071209
diff_rendered=diff_rendered,
1210+
skip_lints=skip_lints,
12081211
)
12091212

12101213
if no_auto_categorization:
@@ -1246,6 +1249,7 @@ def plan_builder(
12461249
enable_preview: t.Optional[bool] = None,
12471250
run: bool = False,
12481251
diff_rendered: bool = False,
1252+
skip_lints: bool = False,
12491253
) -> PlanBuilder:
12501254
"""Creates a plan builder.
12511255
@@ -1301,7 +1305,8 @@ def plan_builder(
13011305
if run and is_dev:
13021306
raise ConfigError("The '--run' flag is only supported for the production environment.")
13031307

1304-
self.lint_models(*self.models.values())
1308+
if not skip_lints:
1309+
self.lint_models(*self.models.values())
13051310

13061311
self._run_plan_tests(skip_tests=skip_tests)
13071312

sqlmesh/magics.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ def test(self, context: Context, line: str, test_def_raw: t.Optional[str] = None
343343
action="store_true",
344344
help="Skip the unit tests defined for the model.",
345345
)
346+
@argument(
347+
"--skip-lints",
348+
action="store_true",
349+
help="Skip the linter for the model.",
350+
)
346351
@argument(
347352
"--restate-model",
348353
"-r",

tests/cli/test_cli.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,29 @@ def test_plan_skip_tests(runner, tmp_path):
198198
assert_backfill_success(result)
199199

200200

201+
def test_plan_skip_lints(runner, tmp_path):
202+
create_example_project(tmp_path)
203+
204+
with open(tmp_path / "config.yaml", "a", encoding="utf-8") as f:
205+
f.write(
206+
"""linter:
207+
enabled: True
208+
rules: "ALL"
209+
"""
210+
)
211+
212+
# Successful test run message should not appear with `--skip-tests`
213+
# Input: `y` to apply and backfill
214+
result = runner.invoke(
215+
cli, ["--log-file-dir", tmp_path, "--paths", tmp_path, "plan", "--skip-lints"], input="y\n"
216+
)
217+
218+
assert result.exit_code == 0
219+
assert "Linter warnings" not in result.output
220+
assert_new_env(result)
221+
assert_backfill_success(result)
222+
223+
201224
def test_plan_restate_model(runner, tmp_path):
202225
create_example_project(tmp_path)
203226
init_prod_and_backfill(runner, tmp_path)

0 commit comments

Comments
 (0)