logo
Sourcery Documentation
Rule Configuration
Initializing search
    GitHub
    GitHub
    • Welcome
      • Products
        • CLI
        • pre-commit
        • CI
        • IDE plugins
      • Features
      • Introduction to Sourcery
      • Writing Custom Rules
      • Install and Use Sourcery
        • Command Line
        • pre-commit
        • CI
        • GitHub Action
        • VSCode
        • PyCharm
        • Emacs
        • Sublime
        • Vim
        • GitHub
      • Custom Rule Recipes
        • Enforce Naming Conventions
        • Establish Rules for Dependencies Between Your Packages
        • Get Rid Of Deprecated Code
        • Flag Dependencies to a Library
        • Flag Hard-Coded Values
        • Remove Debugging Statements
      • How To Create Custom Rules for Libraries?
      • IDE Autocompletion (Schema)
      • Command Line
        • review
        • hub
        • Configuration Sources
          • `.sourcery.yaml`: The Configuration File
          • Rule Settings
          • Rule Configuration
          • GitHub Configuration
          • Clone Detection Configuration
          • Proxy Configuration
        • Inline Configuration
      • Default Rules
        • Refactorings
          • Assign If Expression
          • Augmented Assign
          • 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
          • Comprehension to Generator
          • Convert Any to In
          • Convert to Enumerate
          • De Morgan's Laws
          • Default Get
          • Del Comprehension
          • Dict Assign-Update to Union
          • Dictionary Comprehension
          • Dictionary Literal
          • 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
          • 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
          • Min/Max identity
          • Move Assign
          • Move Assign In Block
          • Non Equal Comparison
          • None Compare
          • Or If Expression Identity
          • pathlib.Path Read
          • Reintroduce Else
          • Remove Assert True
          • Remove Dict Items
          • Remove Dictionary Keys
          • 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 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
          • 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 `itertools.product`
          • Use str.join()
          • Use len()
          • Use Named Expression
          • Use Next
          • Use or For Fallback
          • Use String Remove Affix
          • Useless else on loop
          • While Guard To Condition
          • Replace while with for
          • Yield from
        • Suggestions
          • Aware datetime For UTC
          • Compare Via Equals
          • Default Mutable Arguments
          • Do Not Use Bare Except
          • Missing Dict Items
          • Raise From Previous Error
          • Remove Duplicate Dict Key
        • Comments
          • Avoid Builtin Shadow
          • Low Code Quality
          • Raise Specific Error
      • Optional Rules
        • Google Python Style Guide
      • Custom Rules
        • Pattern Syntax
        • Conditions
      • Sourcery's GitHub Quality Report
      • Plans
      • Permissions and Security
      • FAQs
      • Troubleshooting
      • Supported Operating Systems
      • Glossary

    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.
    Back to top
    Made with Material for MkDocs