Class: Ea::Lint::Rules::NamingConventionRule
- Defined in:
- lib/ea/lint/rules/naming_convention.rb
Overview
Class names should be CamelCase. Attribute names should be camelCase. Detect deviations.
Constant Summary collapse
- CLASS_PATTERN =
/\A[A-Z][A-Za-z0-9]*\z/- ATTR_PATTERN =
/\A[a-z][A-Za-z0-9]*\z/
Instance Method Summary collapse
Methods inherited from LintRule
Instance Method Details
#check(model) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ea/lint/rules/naming_convention.rb', line 14 def check(model) offenses = [] classes = (model.collections[:objects] || []) .select { |o| o.object_type == "Class" } classes.each do |klass| next if klass.name.nil? || klass.name.empty? unless klass.name.match?(CLASS_PATTERN) offenses << offense(entity_id: klass.object_id, entity_name: klass.name, message: "Class name is not CamelCase") end end attrs = model.collections[:attributes] || [] attrs.each do |attr| next if attr.name.nil? || attr.name.empty? unless attr.name.match?(ATTR_PATTERN) offenses << offense(entity_id: attr.attribute_id || attr.object_id, entity_name: attr.name, message: "Attribute name is not camelCase") end end offenses end |