22from sys import exit # pylint: disable=redefined-builtin
33
44import sqlfluff
5+ from sqlfluff .core import FluffConfig
56from termcolor import cprint
67
7- from .config_utils import find_config_file , load_config
88from .constants import EXIT_FAIL
99from .formatters .javascript import validate_prettier_installation
1010from .formatters .sqlx import format_sqlx
@@ -21,7 +21,7 @@ def main():
2121 description = "A script that formats and lints Dataform SQLX files."
2222 )
2323 parser .add_argument (
24- "-c" , "--config" , help = "Path to the configuration file" , default = None
24+ "-c" , "--config-path " , help = "Path to the configuration file" , default = None
2525 )
2626 dialects = [d .name for d in sqlfluff .core .dialect_readout ()]
2727 parser .add_argument (
@@ -33,38 +33,37 @@ def main():
3333 opts = parser .parse_args ()
3434
3535 for filename in opts .files :
36- if opts .config is None :
37- opts .config = find_config_file (filename )
38- if opts .dialect is None :
39- opts .dialect = load_config (opts .config ).get ("sqlfluff" , {}).get ("dialect" )
36+ config = FluffConfig .from_path (
37+ filename if opts .config_path is None else opts .config_path
38+ )
39+ config .set_value (
40+ ["rules" , "convention.terminator" , "require_final_semicolon" ], False
41+ )
42+ if opts .dialect is not None :
43+ config .set_value (["dialect" ], opts .dialect )
4044
4145 with open (filename , "r" , encoding = "utf-8" ) as f :
4246 raw_file_contents = f .read ()
4347 parsed_file_contents = parse_sqlx (raw_file_contents )
4448
45- parsing_violations = parse_sql (parsed_file_contents ["main" ], opts .dialect )
49+ cprint (filename , attrs = ["bold" ], end = " " )
50+
51+ parsing_violations = parse_sql (parsed_file_contents ["main" ], config )
4652 if parsing_violations is not None :
4753 cprint (parsing_violations , "red" )
4854 exit (EXIT_FAIL )
4955
50- lint_result = sqlfluff .lint (
51- parsed_file_contents ["main" ],
52- dialect = opts .dialect ,
53- config_path = opts .config ,
54- )
55- cprint (filename , attrs = ["bold" ], end = " " )
56+ lint_result = sqlfluff .lint (parsed_file_contents ["main" ], config = config )
5657 if not lint_result :
5758 cprint ("PASS" , color = "green" )
5859 else :
5960 cprint ("FAIL" , color = "red" )
6061 for result in lint_result :
6162 print_lint_result (result )
6263
63- formatted_file_contents = format_sqlx (
64- parsed_file_contents , opts .dialect , opts .config
65- )
64+ formatted_file_contents = format_sqlx (parsed_file_contents , config )
6665 formatted_file_contents_again = format_sqlx (
67- parse_sqlx (formatted_file_contents ), opts . dialect , opts . config
66+ parse_sqlx (formatted_file_contents ), config
6867 )
6968 if formatted_file_contents != formatted_file_contents_again :
7069 cprint ("Formatter unable to determine final formatted form." , "red" )
0 commit comments