Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ ruff's goal is to achieve feature-parity with Flake8 when used (1) without any p
stylistic checks; limiting to Python 3 obviates the need for certain compatibility checks.)

Under those conditions, Flake8 implements about 60 rules, give or take. At time of writing, ruff
implements 38 rules. (Note that these 38 rules likely cover a disproportionate share of errors:
implements 39 rules. (Note that these 39 rules likely cover a disproportionate share of errors:
unused imports, undefined variables, etc.)

The unimplemented rules are tracked in #170, and include:
Expand Down Expand Up @@ -166,6 +166,7 @@ Beyond rule-set parity, ruff suffers from the following limitations vis-à-vis F
| F621 | TooManyExpressionsInStarredAssignment | too many expressions in star-unpacking assignment |
| F622 | TwoStarredExpressions | two starred expressions in assignment |
| F631 | AssertTuple | Assert test is a non-empty tuple, which is always `True` |
| F633 | InvalidPrintSyntax | use of >> is invalid with print function |
| F634 | IfTuple | If test is a tuple, which is always `True` |
| F701 | BreakOutsideLoop | `break` outside loop |
| F702 | ContinueOutsideLoop | `continue` not properly in loop |
Expand Down
3 changes: 2 additions & 1 deletion examples/generate_rules_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ fn main() {
CheckKind::DoNotAssignLambda,
CheckKind::DoNotUseBareExcept,
CheckKind::DuplicateArgumentName,
CheckKind::ForwardAnnotationSyntaxError("...".to_string()),
CheckKind::FStringMissingPlaceholders,
CheckKind::ForwardAnnotationSyntaxError("...".to_string()),
CheckKind::FutureFeatureNotDefined("...".to_string()),
CheckKind::IOError("...".to_string()),
CheckKind::IfTuple,
CheckKind::ImportStarNotPermitted("...".to_string()),
CheckKind::ImportStarUsage("...".to_string()),
CheckKind::InvalidPrintSyntax,
CheckKind::LateFutureImport,
CheckKind::LineTooLong(89, 88),
CheckKind::ModuleImportNotAtTopOfFile,
Expand Down
52 changes: 37 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
[project]
name = "ruff"
keywords = ["automation", "flake8", "pycodestyle", "pyflakes", "pylint", "clippy"]
[tool.poetry]
name = "autobot-ml"
version = "0.0.1"
description = "An automated code refactoring tool powered by GPT-3."
authors = ["Charlie Marsh <charlie.r.marsh@gmail.com>"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/charliermarsh/autobot"
keywords = ["automation", "refactor", "GPT-3"]
classifiers = [
"Development Status :: 3 - Alpha",
"Environment :: Console",
Expand All @@ -17,19 +23,35 @@ classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Software Development :: Quality Assurance",
]
author = "Charlie Marsh"
author_email = "charlie.r.marsh@gmail.com"
description = "An extremely fast Python linter, written in Rust."
requires-python = ">=3.7"
packages = [{ include = "autobot" }]

[project.urls]
repository = "https://github.com/charliermarsh/ruff"

[tool.poetry.dependencies]
python = ">=3.7,<3.11"
openai = "^0.23.0"
python-dotenv = "^0.21.0"
colorama = "^0.4.5"
patch = "^1.16"
rich = "^12.5.1"

[tool.poetry.dev-dependencies]
mypy = "^0.971"
black = "^22.8.0"
isort = "^5.10.1"

[tool.poetry.scripts]
autobot = "autobot.main:main"

[build-system]
requires = ["maturin>=0.13,<0.14"]
build-backend = "maturin"
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.black]
line-length = 88
target-version = ["py310"]
extend-exclude = "schematics"
preview = true

[tool.maturin]
bindings = "bin"
sdist-include = ["Cargo.lock"]
strip = true
[tool.isort]
profile = "black"
extend_skip = "schematics"
4 changes: 4 additions & 0 deletions resources/test/fixtures/F633.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from __future__ import print_function
import sys

print >> sys.stderr, "Hello"
1 change: 1 addition & 0 deletions resources/test/fixtures/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ select = [
"F621",
"F622",
"F631",
"F633",
"F634",
"F701",
"F702",
Expand Down
24 changes: 23 additions & 1 deletion src/check_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::Path;

use rustpython_parser::ast::{
Arg, Arguments, Constant, Excepthandler, ExcepthandlerKind, Expr, ExprContext, ExprKind,
KeywordData, Location, Stmt, StmtKind, Suite,
KeywordData, Location, Operator, Stmt, StmtKind, Suite,
};
use rustpython_parser::parser;

Expand Down Expand Up @@ -668,6 +668,28 @@ where
}
self.in_f_string = true;
}
ExprKind::BinOp {
left,
op: Operator::RShift,
..
} => {
if self.settings.select.contains(&CheckCode::F633) {
if let ExprKind::Name { id, .. } = &left.node {
if id == "print" {
let scope = &self.scopes
[*(self.scope_stack.last().expect("No current scope found."))];
if let Some(Binding {
kind: BindingKind::Builtin,
..
}) = scope.values.get("print")
{
self.checks
.push(Check::new(CheckKind::InvalidPrintSyntax, left.location));
}
}
}
}
}
ExprKind::UnaryOp { op, operand } => {
let check_not_in = self.settings.select.contains(&CheckCode::E713);
let check_not_is = self.settings.select.contains(&CheckCode::E714);
Expand Down
7 changes: 7 additions & 0 deletions src/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub enum CheckCode {
F621,
F622,
F631,
F633,
F634,
F701,
F702,
Expand Down Expand Up @@ -76,6 +77,7 @@ impl FromStr for CheckCode {
"F621" => Ok(CheckCode::F621),
"F622" => Ok(CheckCode::F622),
"F631" => Ok(CheckCode::F631),
"F633" => Ok(CheckCode::F633),
"F634" => Ok(CheckCode::F634),
"F701" => Ok(CheckCode::F701),
"F702" => Ok(CheckCode::F702),
Expand Down Expand Up @@ -121,6 +123,7 @@ impl CheckCode {
CheckCode::F621 => "F621",
CheckCode::F622 => "F622",
CheckCode::F631 => "F631",
CheckCode::F633 => "F633",
CheckCode::F634 => "F634",
CheckCode::F701 => "F701",
CheckCode::F702 => "F702",
Expand Down Expand Up @@ -179,6 +182,7 @@ pub enum CheckKind {
FutureFeatureNotDefined(String),
IOError(String),
IfTuple,
InvalidPrintSyntax,
ImportStarNotPermitted(String),
ImportStarUsage(String),
LateFutureImport,
Expand Down Expand Up @@ -223,6 +227,7 @@ impl CheckKind {
CheckKind::FutureFeatureNotDefined(_) => "FutureFeatureNotDefined",
CheckKind::IOError(_) => "IOError",
CheckKind::IfTuple => "IfTuple",
CheckKind::InvalidPrintSyntax => "InvalidPrintSyntax",
CheckKind::ImportStarNotPermitted(_) => "ImportStarNotPermitted",
CheckKind::ImportStarUsage(_) => "ImportStarUsage",
CheckKind::LateFutureImport => "LateFutureImport",
Expand Down Expand Up @@ -269,6 +274,7 @@ impl CheckKind {
CheckKind::FutureFeatureNotDefined(_) => &CheckCode::F407,
CheckKind::IOError(_) => &CheckCode::E902,
CheckKind::IfTuple => &CheckCode::F634,
CheckKind::InvalidPrintSyntax => &CheckCode::F633,
CheckKind::ImportStarNotPermitted(_) => &CheckCode::F406,
CheckKind::ImportStarUsage(_) => &CheckCode::F403,
CheckKind::LateFutureImport => &CheckCode::F404,
Expand Down Expand Up @@ -335,6 +341,7 @@ impl CheckKind {
format!("No such file or directory: `{name}`")
}
CheckKind::IfTuple => "If test is a tuple, which is always `True`".to_string(),
CheckKind::InvalidPrintSyntax => "use of >> is invalid with print function".to_string(),
CheckKind::ImportStarNotPermitted(name) => {
format!("`from {name} import *` only allowed at module level")
}
Expand Down
25 changes: 25 additions & 0 deletions src/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,31 @@ mod tests {
Ok(())
}

#[test]
fn f633() -> Result<()> {
let mut actual = check_path(
Path::new("./resources/test/fixtures/F633.py"),
&settings::Settings {
line_length: 88,
exclude: vec![],
select: BTreeSet::from([CheckCode::F633]),
},
&fixer::Mode::Generate,
)?;
actual.sort_by_key(|check| check.location);
let expected = vec![Check {
kind: CheckKind::InvalidPrintSyntax,
location: Location::new(4, 1),
fix: None,
}];
assert_eq!(actual.len(), expected.len());
for i in 0..actual.len() {
assert_eq!(actual[i], expected[i]);
}

Ok(())
}

#[test]
fn f634() -> Result<()> {
let mut actual = check_path(
Expand Down
1 change: 1 addition & 0 deletions src/pyproject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ other-attribute = 1
CheckCode::F621,
CheckCode::F622,
CheckCode::F631,
CheckCode::F633,
CheckCode::F634,
CheckCode::F701,
CheckCode::F702,
Expand Down
1 change: 1 addition & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl Settings {
CheckCode::F621,
CheckCode::F622,
CheckCode::F631,
CheckCode::F633,
CheckCode::F634,
CheckCode::F701,
CheckCode::F702,
Expand Down