Uniword enforces a consistent code style using RuboCop with project-specific configuration.
1. RuboCop
Run RuboCop before committing:
# Check for issues
bundle exec rubocop
# Auto-fix issues where possible
bundle exec rubocop -A --auto-gen-config
2. Code Style Guidelines
- Indentation
-
Use 2 spaces for indentation. No tabs.
- Line length
-
Maximum line length of 80 characters.
- File loading
-
Use
require_relativefor files in the same codebase. Never userequirefor internal files. - Unused requires
-
Remove unused
requireorrequire_relativestatements. - Attributes
-
Use
attr_reader,attr_writer, andattr_accessorfor simple attributes in non-model classes. - Object-oriented design
-
Follow SOLID principles and object-oriented design.
- File size
-
Keep files under 700 lines of code.
- Method size
-
Keep methods focused and under 50 lines.
- Data structures
-
Never use
StructorOpenStruct. Use proper model classes.
3. Documentation Standards
Document all public classes and methods with YARD:
# Calculate the sum of two numbers
#
# @param a [Integer] The first number
# @param b [Integer] The second number
# @return [Integer] The sum of a and b
# @raise [ArgumentError] if inputs are not integers
#
# @example
# add(2, 3) # => 5
def add(a, b)
raise ArgumentError unless a.is_a?(Integer) && b.is_a?(Integer)
a + b
end
Documentation requirements:
-
Include
@param,@return, and@raisetags -
Provide code examples in documentation
-
Use clear, descriptive names for classes and methods
-
Add YARD documentation for all new public methods