diff --git a/.gitattributes b/.gitattributes index 610c6b39ba8dd..8f333acef68b9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8,6 +8,9 @@ crates/ruff_linter/resources/test/fixtures/pycodestyle/W391_3.py text eol=crlf crates/ruff_python_formatter/resources/test/fixtures/ruff/docstring_code_examples_crlf.py text eol=crlf crates/ruff_python_formatter/tests/snapshots/format@docstring_code_examples_crlf.py.snap text eol=crlf +crates/ruff_python_parser/resources/invalid/re_lex_logical_token_windows_eol.py text eol=crlf +crates/ruff_python_parser/resources/invalid/re_lex_logical_token_mac_eol.py text eol=cr + crates/ruff_python_parser/resources/inline linguist-generated=true ruff.schema.json linguist-generated=true text=auto eol=lf diff --git a/crates/ruff_python_parser/resources/invalid/re_lex_logical_token_mac_eol.py b/crates/ruff_python_parser/resources/invalid/re_lex_logical_token_mac_eol.py new file mode 100644 index 0000000000000..0038f8b1518ff --- /dev/null +++ b/crates/ruff_python_parser/resources/invalid/re_lex_logical_token_mac_eol.py @@ -0,0 +1 @@ +if call(foo, [a, b def bar(): pass \ No newline at end of file diff --git a/crates/ruff_python_parser/resources/invalid/re_lex_logical_token_windows_eol.py b/crates/ruff_python_parser/resources/invalid/re_lex_logical_token_windows_eol.py new file mode 100644 index 0000000000000..e59a3af014a59 --- /dev/null +++ b/crates/ruff_python_parser/resources/invalid/re_lex_logical_token_windows_eol.py @@ -0,0 +1,3 @@ +if call(foo, [a, b + def bar(): + pass diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_mac_eol.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_mac_eol.py.snap new file mode 100644 index 0000000000000..72eca32ab69cf --- /dev/null +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_mac_eol.py.snap @@ -0,0 +1,104 @@ +--- +source: crates/ruff_python_parser/tests/fixtures.rs +input_file: crates/ruff_python_parser/resources/invalid/re_lex_logical_token_mac_eol.py +--- +## AST + +``` +Module( + ModModule { + range: 0..46, + body: [ + If( + StmtIf { + range: 0..46, + test: Call( + ExprCall { + range: 3..19, + func: Name( + ExprName { + range: 3..7, + id: "call", + ctx: Load, + }, + ), + arguments: Arguments { + range: 7..19, + args: [ + Name( + ExprName { + range: 8..11, + id: "foo", + ctx: Load, + }, + ), + List( + ExprList { + range: 13..18, + elts: [ + Name( + ExprName { + range: 14..15, + id: "a", + ctx: Load, + }, + ), + Name( + ExprName { + range: 17..18, + id: "b", + ctx: Load, + }, + ), + ], + ctx: Load, + }, + ), + ], + keywords: [], + }, + }, + ), + body: [ + FunctionDef( + StmtFunctionDef { + range: 23..46, + is_async: false, + decorator_list: [], + name: Identifier { + id: "bar", + range: 27..30, + }, + type_params: None, + parameters: Parameters { + range: 30..32, + posonlyargs: [], + args: [], + vararg: None, + kwonlyargs: [], + kwarg: None, + }, + returns: None, + body: [ + Pass( + StmtPass { + range: 42..46, + }, + ), + ], + }, + ), + ], + elif_else_clauses: [], + }, + ), + ], + }, +) +``` +## Errors + + | +1 | if call(foo, [a, b def bar(): pass + | Syntax Error: Expected ']', found NonLogicalNewline + | diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_windows_eol.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_windows_eol.py.snap new file mode 100644 index 0000000000000..d11a5cf9263c2 --- /dev/null +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_windows_eol.py.snap @@ -0,0 +1,107 @@ +--- +source: crates/ruff_python_parser/tests/fixtures.rs +input_file: crates/ruff_python_parser/resources/invalid/re_lex_logical_token_windows_eol.py +--- +## AST + +``` +Module( + ModModule { + range: 0..50, + body: [ + If( + StmtIf { + range: 0..48, + test: Call( + ExprCall { + range: 3..20, + func: Name( + ExprName { + range: 3..7, + id: "call", + ctx: Load, + }, + ), + arguments: Arguments { + range: 7..20, + args: [ + Name( + ExprName { + range: 8..11, + id: "foo", + ctx: Load, + }, + ), + List( + ExprList { + range: 13..18, + elts: [ + Name( + ExprName { + range: 14..15, + id: "a", + ctx: Load, + }, + ), + Name( + ExprName { + range: 17..18, + id: "b", + ctx: Load, + }, + ), + ], + ctx: Load, + }, + ), + ], + keywords: [], + }, + }, + ), + body: [ + FunctionDef( + StmtFunctionDef { + range: 24..48, + is_async: false, + decorator_list: [], + name: Identifier { + id: "bar", + range: 28..31, + }, + type_params: None, + parameters: Parameters { + range: 31..33, + posonlyargs: [], + args: [], + vararg: None, + kwonlyargs: [], + kwarg: None, + }, + returns: None, + body: [ + Pass( + StmtPass { + range: 44..48, + }, + ), + ], + }, + ), + ], + elif_else_clauses: [], + }, + ), + ], + }, +) +``` +## Errors + + | +1 | if call(foo, [a, b + | ___________________^ +2 | | def bar(): + | |_^ Syntax Error: Expected ']', found NonLogicalNewline +3 | pass + |