docs
  • Overview
  • 🐍 PYTHON
    • Type Hints
    • PEP8 Style Guide for Python Code
    • 🏡Pipenv
    • Pathlib
  • 🕸Django
    • 🗄models
      • 🎯Best Practices
      • 🚦Django Signals
    • ⚙️ settings
    • DRF
      • Serializer
      • Authentication
      • Permissions
      • Viewsets
    • Testing
      • Faker and Factory Boy
    • 🧪Test Coverage
    • 💦Python-Decouple
    • Django Tips:
    • 💾Django ORM Queryset
    • Custom Exceptions
    • Celery
    • Resources
  • Deploy
    • 🚀Django Deployment
    • 🔒Setup SSL Certificate
  • 💾Database
    • MongoDB
  • 🛠️DevOps
    • 🖥Scripting
      • A First Script
      • Loops
      • Test
      • Variables
      • External programs
      • Functions
    • Command Line Shortcuts
    • Basic Linux Commands
    • 🎛Microservices
    • 🐳Docker
      • Docker Commands
      • Docker Compose
      • Django project
    • Kubernates
  • 📝Software IDE
    • EditorConfig
    • Linters
    • VsCode
Powered by GitBook
On this page
  • EditorConfig to standardize Code Styles
  • The Benefit of using common EditorConfig
  • Django Editor Config

Was this helpful?

  1. 📝Software IDE

EditorConfig

EditorConfig to standardize Code Styles

We should use EditorConfig to define formatting conventions for textual files in a project. Without consistency, the code can appear untidy and be a pain to read, depending on a user's development environment. A common solution is to share editor settings as part of the project, but this assumes all committers are using the same editor.

The Benefit of using common EditorConfig

  • EditorConfig makes code more readable

  • EditorConfig makes Code Reviews Easier

  • EditorConfig makes development easier

.editorconfig
# Declares that this is the top-level configuration

root = true

# Applies to all files
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
curly_bracket_next_line = false
spaces_around_operators = true

[*.{js,py}]
charset = utf-8


# 4 space indentation
[*.py]
indent_style = space
indent_size = 4


# Tab indentation (no size specified)
[Makefile]
indent_style = tab

# Applies to all Markdown files
[*.md]
trim_trailing_whitespace = false

[*.cs]
curly_bracket_next_line = true

# Applies to all C# and Java files, overriding rules declared before
[*.{cs,java}]
indent_size = 4

[*.{js,ts}]
quote_type = single

[*.tsv]
indent_style = tab


# Indentation override for all JS under lib directory
[lib/**.js]
indent_style = space
indent_size = 2

# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml}]
indent_style = space
indent_size = 2

Django Editor Config

# https://editorconfig.org/

root = true

[*]
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
charset = utf-8

# Docstrings and comments use max_line_length = 79
[*.py]
max_line_length = 119

# Use 2 spaces for the HTML files
[*.html]
indent_size = 2

# The JSON files contain newlines inconsistently
[*.json]
indent_size = 2
insert_final_newline = ignore

[**/admin/js/vendor/**]
indent_style = ignore
indent_size = ignore

# Minified JavaScript files shouldn't be changed
[**.min.js]
indent_style = ignore
insert_final_newline = ignore

# Makefiles always use tabs for indentation
[Makefile]
indent_style = tab

# Batch files use tabs for indentation
[*.bat]
indent_style = tab

[docs/**.txt]
max_line_length = 79

[*.yml]
indent_size = 2

Previous📝Software IDENextLinters

Last updated 3 years ago

Was this helpful?