Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove RustPython fork #523

Merged
merged 1 commit into from
Oct 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ once_cell = { version = "1.13.1" }
path-absolutize = { version = "3.0.14", features = ["once_cell_cache", "use_unix_paths_on_wasm"] }
rayon = { version = "1.5.3" }
regex = { version = "1.6.0" }
rustpython-ast = { features = ["unparse"], git = "https://github.com/charliermarsh/RustPython.git", rev = "1b253a12705f84972cd76e8dc1cdaaccb233e5a5" }
rustpython-common = { git = "https://github.com/charliermarsh/RustPython.git", rev = "1b253a12705f84972cd76e8dc1cdaaccb233e5a5" }
rustpython-parser = { features = ["lalrpop"], git = "https://github.com/charliermarsh/RustPython.git", rev = "1b253a12705f84972cd76e8dc1cdaaccb233e5a5" }
rustpython-ast = { features = ["unparse"], git = "https://github.com/RustPython/RustPython.git", rev = "77b821a1941019fe34f73ce17cea013ae1b98fd0" }
rustpython-common = { git = "https://github.com/RustPython/RustPython.git", rev = "77b821a1941019fe34f73ce17cea013ae1b98fd0" }
rustpython-parser = { features = ["lalrpop"], git = "https://github.com/RustPython/RustPython.git", rev = "77b821a1941019fe34f73ce17cea013ae1b98fd0" }
serde = { version = "1.0.143", features = ["derive"] }
serde_json = { version = "1.0.83" }
strum = { version = "0.24.1", features = ["strum_macros"] }
Expand Down
5 changes: 5 additions & 0 deletions foo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def function_with_nesting():
"""Foo bar documentation."""
@overload
def nested_overloaded_func(a: int) -> str:
...
2 changes: 1 addition & 1 deletion src/ast/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub fn to_absolute(relative: &Location, base: &Location) -> Location {
if relative.row() == 1 {
Location::new(
relative.row() + base.row() - 1,
relative.column() + base.column() - 1,
relative.column() + base.column(),
)
} else {
Location::new(relative.row() + base.row() - 1, relative.column())
Expand Down
33 changes: 16 additions & 17 deletions src/autofix/fixer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,18 @@ fn apply_fixes<'a>(fixes: impl Iterator<Item = &'a mut Fix>, contents: &str) ->

if fix.patch.location.row() > last_pos.row() {
if last_pos.row() > 0 || last_pos.column() > 0 {
output.push_str(&lines[last_pos.row() - 1][last_pos.column() - 1..]);
output.push_str(&lines[last_pos.row() - 1][last_pos.column()..]);
output.push('\n');
}
for line in &lines[last_pos.row()..fix.patch.location.row() - 1] {
output.push_str(line);
output.push('\n');
}
output
.push_str(&lines[fix.patch.location.row() - 1][..fix.patch.location.column() - 1]);
output.push_str(&lines[fix.patch.location.row() - 1][..fix.patch.location.column()]);
output.push_str(&fix.patch.content);
} else {
output.push_str(
&lines[last_pos.row() - 1][last_pos.column() - 1..fix.patch.location.column() - 1],
&lines[last_pos.row() - 1][last_pos.column()..fix.patch.location.column()],
);
output.push_str(&fix.patch.content);
}
Expand All @@ -95,7 +94,7 @@ fn apply_fixes<'a>(fixes: impl Iterator<Item = &'a mut Fix>, contents: &str) ->
&& (last_pos.row() - 1) < lines.len()
&& (last_pos.row() > 0 || last_pos.column() > 0)
{
output.push_str(&lines[last_pos.row() - 1][last_pos.column() - 1..]);
output.push_str(&lines[last_pos.row() - 1][last_pos.column()..]);
output.push('\n');
}
if last_pos.row() < lines.len() {
Expand Down Expand Up @@ -133,8 +132,8 @@ mod tests {
let mut fixes = vec![Fix {
patch: Patch {
content: "Bar".to_string(),
location: Location::new(1, 9),
end_location: Location::new(1, 15),
location: Location::new(1, 8),
end_location: Location::new(1, 14),
},
applied: false,
}];
Expand All @@ -159,8 +158,8 @@ mod tests {
let mut fixes = vec![Fix {
patch: Patch {
content: "".to_string(),
location: Location::new(1, 8),
end_location: Location::new(1, 16),
location: Location::new(1, 7),
end_location: Location::new(1, 15),
},
applied: false,
}];
Expand All @@ -186,16 +185,16 @@ mod tests {
Fix {
patch: Patch {
content: "".to_string(),
location: Location::new(1, 8),
end_location: Location::new(1, 17),
location: Location::new(1, 7),
end_location: Location::new(1, 16),
},
applied: false,
},
Fix {
patch: Patch {
content: "".to_string(),
location: Location::new(1, 17),
end_location: Location::new(1, 24),
location: Location::new(1, 16),
end_location: Location::new(1, 23),
},
applied: false,
},
Expand All @@ -222,16 +221,16 @@ mod tests {
Fix {
patch: Patch {
content: "".to_string(),
location: Location::new(1, 8),
end_location: Location::new(1, 16),
location: Location::new(1, 7),
end_location: Location::new(1, 15),
},
applied: false,
},
Fix {
patch: Patch {
content: "ignored".to_string(),
location: Location::new(1, 10),
end_location: Location::new(1, 12),
location: Location::new(1, 9),
end_location: Location::new(1, 11),
},
applied: false,
},
Expand Down
4 changes: 2 additions & 2 deletions src/autofix/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ pub fn remove_stmt(stmt: &Stmt, parent: Option<&Stmt>, deleted: &[&Stmt]) -> Res
// Otherwise, nuke the entire line.
// TODO(charlie): This logic assumes that there are no multi-statement physical lines.
Ok(Fix::deletion(
Location::new(stmt.location.row(), 1),
Location::new(stmt.end_location.unwrap().row() + 1, 1),
Location::new(stmt.location.row(), 0),
Location::new(stmt.end_location.unwrap().row() + 1, 0),
))
}
}
4 changes: 2 additions & 2 deletions src/check_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ where
}
StmtKind::Import { names } => {
if self.settings.enabled.contains(&CheckCode::E402) {
if self.seen_import_boundary && stmt.location.column() == 1 {
if self.seen_import_boundary && stmt.location.column() == 0 {
self.checks.push(Check::new(
CheckKind::ModuleImportNotAtTopOfFile,
self.locate_check(Range::from_located(stmt)),
Expand Down Expand Up @@ -493,7 +493,7 @@ where
level,
} => {
if self.settings.enabled.contains(&CheckCode::E402) {
if self.seen_import_boundary && stmt.location.column() == 1 {
if self.seen_import_boundary && stmt.location.column() == 0 {
self.checks.push(Check::new(
CheckKind::ModuleImportNotAtTopOfFile,
self.locate_check(Range::from_located(stmt)),
Expand Down
24 changes: 12 additions & 12 deletions src/check_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ pub fn check_lines(
let check = Check::new(
CheckKind::LineTooLong(line_length, settings.line_length),
Range {
location: Location::new(lineno + 1, 1),
end_location: Location::new(lineno + 1, line_length + 1),
location: Location::new(lineno + 1, 0),
end_location: Location::new(lineno + 1, line_length),
},
);

Expand Down Expand Up @@ -164,14 +164,14 @@ pub fn check_lines(
let mut check = Check::new(
CheckKind::UnusedNOQA(None),
Range {
location: Location::new(row + 1, start + 1),
end_location: Location::new(row + 1, end + 1),
location: Location::new(row + 1, start),
end_location: Location::new(row + 1, end),
},
);
if autofix.patch() {
check.amend(Fix::deletion(
Location::new(row + 1, start + 1),
Location::new(row + 1, lines[row].chars().count() + 1),
Location::new(row + 1, start),
Location::new(row + 1, lines[row].chars().count()),
));
}
line_checks.push(check);
Expand All @@ -192,21 +192,21 @@ pub fn check_lines(
let mut check = Check::new(
CheckKind::UnusedNOQA(Some(invalid_codes)),
Range {
location: Location::new(row + 1, start + 1),
end_location: Location::new(row + 1, end + 1),
location: Location::new(row + 1, start),
end_location: Location::new(row + 1, end),
},
);
if autofix.patch() {
if valid_codes.is_empty() {
check.amend(Fix::deletion(
Location::new(row + 1, start + 1),
Location::new(row + 1, lines[row].chars().count() + 1),
Location::new(row + 1, start),
Location::new(row + 1, lines[row].chars().count()),
));
} else {
check.amend(Fix::replacement(
format!(" # noqa: {}", valid_codes.join(", ")),
Location::new(row + 1, start + 1),
Location::new(row + 1, lines[row].chars().count() + 1),
Location::new(row + 1, start),
Location::new(row + 1, lines[row].chars().count()),
));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/docstrings/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn leading_space(line: &str) -> String {
pub fn indentation<'a>(checker: &'a Checker, docstring: &Expr) -> &'a str {
let range = Range::from_located(docstring);
checker.locator.slice_source_code_range(&Range {
location: Location::new(range.location.row(), 1),
location: Location::new(range.location.row(), 0),
end_location: Location::new(range.location.row(), range.location.column()),
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,45 @@ expression: checks
BadQuotesMultilineString: single
location:
row: 5
column: 1
column: 0
end_location:
row: 7
column: 4
column: 3
fix: ~
- kind:
BadQuotesMultilineString: single
location:
row: 16
column: 5
column: 4
end_location:
row: 18
column: 8
column: 7
fix: ~
- kind:
BadQuotesMultilineString: single
location:
row: 21
column: 21
column: 20
end_location:
row: 22
column: 38
column: 37
fix: ~
- kind:
BadQuotesMultilineString: single
location:
row: 30
column: 9
column: 8
end_location:
row: 32
column: 12
column: 11
fix: ~
- kind:
BadQuotesMultilineString: single
location:
row: 35
column: 13
column: 12
end_location:
row: 37
column: 16
column: 15
fix: ~

Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ expression: checks
BadQuotesMultilineString: single
location:
row: 3
column: 5
column: 4
end_location:
row: 3
column: 28
column: 27
fix: ~
- kind:
BadQuotesMultilineString: single
location:
row: 5
column: 23
column: 22
end_location:
row: 5
column: 44
column: 43
fix: ~

Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,45 @@ expression: checks
BadQuotesMultilineString: single
location:
row: 3
column: 5
column: 4
end_location:
row: 3
column: 27
column: 26
fix: ~
- kind:
BadQuotesMultilineString: single
location:
row: 11
column: 5
column: 4
end_location:
row: 11
column: 27
column: 26
fix: ~
- kind:
BadQuotesMultilineString: single
location:
row: 15
column: 39
column: 38
end_location:
row: 17
column: 4
column: 3
fix: ~
- kind:
BadQuotesMultilineString: single
location:
row: 17
column: 5
column: 4
end_location:
row: 17
column: 20
column: 19
fix: ~
- kind:
BadQuotesMultilineString: single
location:
row: 21
column: 5
column: 4
end_location:
row: 21
column: 28
column: 27
fix: ~