logo
Sourcery Documentation
Rule Configuration
Initializing search
    GitHub
    GitHub
    • Welcome to Sourcery
      • Overview
      • Setting Up Your Account
        • Connecting Your Repos
        • Adding Sourcery to Your IDE
        • Select and Inviting Team Members
        • Managing Billing
        • Rate Limits
      • Sourcery Code Reviews
        • Overview
        • Components of a Code Review
        • Interacting with Sourcery
      • Code Reviews in IDE
      • Customizing Sourcery
      • Teaching Sourcery
      • Overview
      • Security Scan Results
      • Resolving Security Issues
      • Managing Your Repos
      • Plans and Pricing
      • Overview
      • Linking Sourcery & Sentry
      • Investigating Issues
      • Fixing Issues
      • Configuration
      • Connecting Slack, Sourcery, & Sentry
    • Integrations
        • GitHub
        • GitLab
        • Cursor
        • VS Code
        • JetBrains IDEs
        • GitHub Issues
        • Jira
        • Sentry
        • Slack
      • Legacy Configuration
          • .sourcery.yaml: The Configuration File
          • Clone Detection
          • Inline Configuration
          • Proxy Configuration
          • Legacy Sourcery Rule Settings
          • Legacy Configuration Sources
        • Overview
        • Python
          • Default Rules
            • Assign If Expression
            • Augmented Assign
            • Avoid Builtin Shadow
            • Aware datetime For UTC
            • Binary Operator Identity
            • Boolean If Expression Identity
            • Break-Or-Continue-Outside-Loop
            • Chain Compares
            • Class Extract Method
            • Class Method First Parameter Should Be cls
            • Collection to Comprehension
            • Collection Into Set
            • Collection to Bool
            • Compare Via Equals
            • Comprehension to Generator
            • Convert Any to In
            • Convert to Enumerate
            • DataFrame Append to Concat
            • De Morgan's Laws
            • Default Get
            • Default Mutable Arguments
            • Del Comprehension
            • Dict Assign-Update to Union
            • Dictionary Comprehension
            • Dict-Literal
            • Do Not Use Bare Except
            • Dont-Import-Test-Modules
            • Ensure File Closed
            • Equality Identity
            • Extract Duplicate Method
            • Extract Method
            • Flatten Nested Try
            • Flip Comparison
            • For Append To Extend
            • For Index Replacement
            • Replace For Index with Underscore
            • Guard
            • Hoist If from If
            • Hoist Loop from If
            • Hoist Repeated If Condition
            • Hoist Similar Statements from If
            • Hoist Statements from If
            • Hoist Statement from Loop
            • Identity Comprehensions
            • Inline Immediately Returned Variables
            • Inline Immediately Yielded Variable
            • Inline Variable
            • Instance Method First Parameter Should Be self
            • Introduce Default Else
            • Invert Any/All
            • Invert Any/All in Body
            • Last if statement guard
            • Lift Duplicated Conditional
            • Lift Return into If
            • List Comprehension
            • List Literal
            • Low Code Quality
            • Max/min Default
            • Merge Assignment and Augmented Assignment
            • Merge Comparisons
            • Merge Dictionary Assignments
            • Merge Duplicate Blocks
            • Merge Else If Into Elif
            • Merge Exception Handlers
            • Merge isinstance
            • Merge List Append
            • Merge List Appends Into Extend
            • Merge List Extend
            • Merge-Nested-Ifs
            • Merge Repeated Ifs
            • Merge Set Add
            • Method_chaining
            • Min/Max identity
            • Missing Dict Items
            • Move Assign
            • Move Assign In Block
            • No-Conditionals-In-Tests
            • No-Loop-In-Tests
            • Non Equal Comparison
            • None Compare
            • Or-If-Exp-Identity
            • Pandas: Avoid inplace
            • pathlib.Path Read
            • Raise From Previous Error
            • Raise-Specific-Error
            • Reintroduce Else
            • Remove Assert True
            • Remove Dict Items
            • Remove Dictionary Keys
            • Remove Duplicate Dict Key
            • Remove Duplicate Set Key
            • Remove Empty Nested Block
            • Remove-None-From-Default-Get
            • Remove Pass From Body
            • Remove Pass From Elif
            • Remove Redundant Boolean
            • Remove Redundant Condition
            • Remove Redundant Constructor in Dict Union
            • Remove Redundant Continue
            • Remove Redundant Except Handler
            • Remove Redundant Exception
            • Remove Redundant f-string
            • Remove Redundant If Statements
            • Remove Redundant Pass
            • Remove-Redundant-Path-Exists
            • Remove Redundant Slice Index
            • Remove Str From Fstring
            • Remove str() from call to print()
            • Remove-Unit-Step-From-Range
            • Remove Unnecessary Cast
            • Remove Unnecessary Else
            • Remove Unreachable Code
            • Remove Unused Enumerate
            • Remove-Zero-From-Range
            • Replace apply With Method Call
            • Replace apply With NumPy Operation
            • Replace Dict Items with Values
            • Replace Interpolation With Fstring
            • Return or Yield Outside Function
            • Set Comprehension
            • Simplify Boolean Comparison
            • Simplify-Constant-Sum
            • Simplify Dictionary Update
            • Simplify Division
            • Simplify Empty Collection Comparison
            • Simplify f-string Formatting
            • Simplify Generator
            • Simplify Length Comparison
            • Simplify Negative Index
            • Simplify Numeric Comparison
            • Simplify Single Exception Tuple
            • Simplify String Length Comparison
            • Simplify substring search
            • Skip Sorted List Construction
            • Split or ifs
            • Square Identity
            • Str Prefix Suffix
            • Sum Comprehension
            • Swap If Else Branches
            • Swap-If-Expression
            • Swap Nested Ifs
            • Swap Variable
            • Switch
            • Ternary to If Expression
            • Tuple-Literal
            • Unwrap Iterable Construction
            • Use Any
            • Use Assigned Variable
            • Use contextlib.suppress
            • Use Count
            • Use Datetime Now Not Today
            • Use Dictionary Items
            • Use Dictionary Union
            • Use File Iterator
            • Use Fstring For Concatenation
            • Use FString For Formatting
            • Use Getitem For Re Match Groups
            • Use-Isna
            • Use itertools.product
            • Use str.join()
            • Use len()
            • Use Named Expression
            • Use Next
            • Use-Or-For-Fallback
            • Use String Remove Affix
            • Use_iloc
            • Useless-Else-On-Loop
            • While-Guard-To-Condition
            • Replace while with for
            • Yield from
          • Optional Rules
            • Google Python Style Guide
        • JavaScript
            • Assignment-Operator
            • Avoid-Function-Declarations-In-Blocks
            • Avoid-Infinite-Loops
            • Avoid-Jumping-In-Finally
            • Avoid-Using-Var
            • Binary-Operator-Identity
            • Combine-Object-Destructuring
            • Dont-Concatenate-String-Literals
            • Dont-Negate-Is-Instanceof-Operands
            • Dont-Reassign-Caught-Exceptions
            • Dont-Reassign-Foreach-Variables
            • Dont-Reassign-Parameters
            • Dont-Self-Assign-Variables
            • Dont-Shadow-Arguments
            • Dont-Use-With
            • Dont-Use-Wrappers-For-Builtins
            • Flatten-Nested-Try
            • Flip-Comparison
            • Generators-Should-Yield
            • Inline-Immediately-Returned-Variable
            • Invert-Ternary
            • Max-Min-Identity
            • Merge-Else-If
            • Merge-Nested-Ifs
            • Misplaced-Break-Or-Continue
            • No-Eval
            • No-New-Function
            • No-New-Symbol
            • Only-Delete-Object-Properties
            • Possible-Incorrect-Bitwise-Operator
            • Remove-Redundant-Boolean
            • Remove-Redundant-If-Statement
            • Remove-Redundant-Slice-Index
            • Remove-Unreachable-Code
            • Return-Outside-Function
            • Simplify-Ternary
            • Throw-New-Errors
            • Use-Array-Literal
            • Use-Object-Destructuring
            • Use-Ternary-Operator
            • While-Guard-To-Condition
            • Yield-Outside-Generator
        • Custom Rules
          • Pattern Syntax
          • Conditions
      • Code Quality Metrics
      • FAQ
      • Supported Operating Systems
      • Troubleshooting
    • Privacy and Security
    • Plans and Pricing
    • Support

    Rule ConfigurationΒΆ

    You can define project-specific rules in your Sourcery config file

    For the syntax of these rules, check out the Project-Specific Rules reference documentation

    Was this page helpful?
    Thanks for your feedback! Help us improve this page by using our feedback form.
    Thanks for your feedback! Help us improve this page by using our feedback form.
    Made with Material for MkDocs