Skip to content

Commit 489252d

Browse files
committed
update linter script
1 parent ae8a0b0 commit 489252d

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

clouds/databricks/common/.sqlfluff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ verbose = 0
55
nocolor = False
66
# Supported dialects https://docs.sqlfluff.com/en/stable/dialects.html
77
# Or run 'sqlfluff dialects'
8-
dialect = None
8+
dialect = databricks
99
# One of [raw|jinja|python|placeholder]
1010
templater = jinja
1111
# Comma separated list of rules to check, default to all

clouds/databricks/common/sql_lint.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ def restore_variables(content):
2121

2222

2323
def lint_error(name, error):
24-
code = error['code']
25-
line_no = error['line_no']
26-
line_pos = error['line_pos']
27-
description = error['description']
24+
code = error.get('code', 'UNKNOWN')
25+
line_no = error.get('line_no', 0)
26+
line_pos = error.get('line_pos', 0)
27+
description = error.get('description', 'Unknown error')
2828
print(f'{name}:{line_no}:{line_pos}: {code} {description}')
2929

3030

3131
def fix_and_lint(script):
32+
if not script or not os.path.exists(script):
33+
return False
34+
3235
name = ''
3336
content = ''
3437
with open(script, 'r') as file:
@@ -54,14 +57,13 @@ def fix_and_lint(script):
5457

5558

5659
if __name__ == '__main__' and sys.argv[1]:
57-
scripts = sys.argv[1].split(' ')
58-
ignored_files = sys.argv[3]
59-
if ignored_files:
60+
scripts = [s for s in sys.argv[1].split(' ') if s.strip()]
61+
ignored_files = sys.argv[3] if len(sys.argv) > 3 else None
62+
if ignored_files and os.path.exists(ignored_files):
6063
with open(ignored_files, 'r') as ignored_file:
61-
ignored_scripts = ignored_file.read().split('\n')
64+
ignored_scripts = [s.strip() for s in ignored_file.read().split('\n') if s.strip()]
6265
for ignored_script in ignored_scripts:
63-
if ignored_script:
64-
scripts = list(filter(lambda x: not x.endswith(ignored_script), scripts))
66+
scripts = list(filter(lambda x: not x.endswith(ignored_script), scripts))
6567

6668
pool = mp.Pool(processes=int(mp.cpu_count() / 2))
6769
output = pool.map(fix_and_lint, scripts)

0 commit comments

Comments
 (0)