Skip to content

Commit 809b6db

Browse files
committed
sort violations
1 parent cd49013 commit 809b6db

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/sqlint/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def parse(sql: str):
3535

3636
def check(sql: str):
3737
tree = SyntaxTree.sqlptree(sql)
38-
for v in check_sql(tree, Config()):
38+
for v in sorted(check_sql(tree, Config())):
3939
logger.info(v)
4040

4141

src/sqlint/checker/violation.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,28 @@ def __init__(self, tree: SyntaxTree, index: int, code: Code, **kwargs):
6565
self.code: Code = code
6666
self.params: Dict = kwargs
6767

68+
@property
69+
def line_num(self):
70+
return self.tree.line_num
71+
72+
@property
73+
def pos(self):
74+
return self.tree.get_position(self.index)
75+
6876
def __str__(self):
6977
_template = '(L{line}, {pos}): ' + self.code.template
7078

7179
return _template.format(
72-
line=self.tree.node.line_num,
73-
pos=self.tree.get_position(self.index),
80+
line=self.line_num,
81+
pos=self.pos,
7482
**self.params)
7583

84+
def __lt__(self, other):
85+
if self.line_num == other.line_num:
86+
return self.pos < other.pos
87+
88+
return self.line_num < other.line_num
89+
7690

7791
class IndentStepsViolation(Violation):
7892
def __init__(self, tree: SyntaxTree, index: int, **kwargs):

src/sqlint/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def main(files, config_file, is_format):
5959
logger.info(formatted_tree.sqlftree())
6060
else:
6161
tree.sqlftree()
62-
for v in check_tree(tree, config):
62+
for v in sorted(check_tree(tree, config)):
6363
logger.info('{} {}'.format(file, v))
6464

6565

0 commit comments

Comments
 (0)