@@ -801,7 +801,7 @@ def lint(
801801 extra_config_path : Path | str | None = None ,
802802 ignore_local_config : bool = False ,
803803 fluff_conf : FluffConfig | None = None ,
804- ) -> LintingRecord | None :
804+ ) -> list [ LintingRecord ] :
805805 """Lint specified file or SQL string."""
806806 from sqlfluff .cli .commands import get_linter_and_formatter
807807
@@ -815,15 +815,34 @@ def lint(
815815 lint , _ = get_linter_and_formatter (fluff_conf )
816816
817817 if sql is None :
818- # TODO: lint whole project
819- return
818+
819+ def _lint (node : ManifestNode ) -> list [LintingRecord ]:
820+ records : list [LintingRecord ] = []
821+ try :
822+ if node .resource_type == "model" :
823+ records = self .lint (
824+ Path (node .original_file_path ),
825+ extra_config_path = extra_config_path ,
826+ ignore_local_config = ignore_local_config ,
827+ fluff_conf = fluff_conf ,
828+ )
829+ except Exception as e :
830+ logger .error (f"Error formatting node { node .name } : { e } " )
831+ return records
832+
833+ all_records : list [LintingRecord ] = []
834+ for records in self .pool .map (_lint , self .manifest .nodes .values ()):
835+ all_records .extend (records )
836+
837+ return all_records
820838 elif isinstance (sql , str ):
821839 result = lint .lint_string_wrapped (sql )
822840 else :
841+ if not sql .is_absolute () and not sql .exists ():
842+ sql = self .project_root / sql
823843 result = lint .lint_paths ((str (sql ),), ignore_files = False )
824844
825- records = result .as_records ()
826- return records [0 ] if records else None
845+ return result .as_records ()
827846
828847 def format (
829848 self ,
@@ -836,13 +855,6 @@ def format(
836855 from sqlfluff .cli .commands import get_linter_and_formatter
837856 from sqlfluff .core import SQLLintError
838857
839- logger .info (f"""format_command(
840- { self .project_root } ,
841- { str (sql )[:100 ]} ,
842- { extra_config_path } ,
843- { ignore_local_config } )
844- """ )
845-
846858 fluff_conf = fluff_conf or self .get_sqlfluff_configuration (
847859 sql if isinstance (sql , Path ) else None ,
848860 extra_config_path ,
@@ -868,11 +880,27 @@ def format(
868880
869881 result_sql = None
870882 if sql is None :
871- # TODO: format whole project
872- return True , result_sql
883+
884+ def _format (node : ManifestNode ) -> bool :
885+ success = True
886+ try :
887+ if node .resource_type == "model" :
888+ success , _ = self .format (
889+ Path (node .original_file_path ),
890+ extra_config_path = extra_config_path ,
891+ ignore_local_config = ignore_local_config ,
892+ fluff_conf = fluff_conf ,
893+ )
894+ except Exception as e :
895+ logger .error (f"Error formatting node { node .name } : { e } " )
896+ success = False
897+ return success
898+
899+ return all (res for res in self .pool .map (_format , self .manifest .nodes .values ())), None
873900 if isinstance (sql , str ):
874901 logger .info (f"Formatting SQL string: { sql [:100 ]} " )
875902 result = lint .lint_string_wrapped (sql , fname = "stdin" , fix = True )
903+
876904 _ , num_filtered_errors = result .count_tmp_prs_errors ()
877905 result .discard_fixes_for_lint_errors_in_files_with_tmp_or_prs_errors ()
878906 success = not num_filtered_errors
@@ -886,6 +914,8 @@ def format(
886914 logger .info ("No fixable errors in SQL string" )
887915 result_sql = sql
888916 else :
917+ if not sql .is_absolute () and not sql .exists ():
918+ sql = self .project_root / sql
889919 logger .info (f"Formatting SQL file: { sql } " )
890920 before_modified = datetime .fromtimestamp (sql .stat ().st_mtime ).strftime (
891921 "%Y-%m-%d %H:%M:%S"
@@ -898,6 +928,7 @@ def format(
898928 apply_fixes = True ,
899929 fix_even_unparsable = False ,
900930 )
931+
901932 _ , num_filtered_errors = lint_result .count_tmp_prs_errors ()
902933 lint_result .discard_fixes_for_lint_errors_in_files_with_tmp_or_prs_errors ()
903934 success = not num_filtered_errors
0 commit comments