Skip to content

Commit 4b9171d

Browse files
authored
fix: Merge pull request #32 from seuros/feat/compact-toml-annotations
Release-as: 0.3.0
2 parents 2b684d4 + 7dec354 commit 4b9171d

76 files changed

Lines changed: 1903 additions & 1403 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/rails_lens/analyzers/association_analyzer.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ def analyze
1515

1616
def analyze_inverse_of
1717
associations_needing_inverse.map do |association|
18-
"Association '#{association.name}' should specify inverse_of"
18+
NoteCodes.note(association.name.to_s, NoteCodes::INVERSE_OF)
1919
end
2020
end
2121

2222
def analyze_n_plus_one_risks
2323
has_many_associations.map do |association|
24-
# Warn about N+1 query risks for has_many associations
25-
"Association '#{association.name}' has N+1 query risk. Consider using includes/preload"
24+
NoteCodes.note(association.name.to_s, NoteCodes::N_PLUS_ONE)
2625
end
2726
end
2827

@@ -32,9 +31,8 @@ def analyze_counter_caches
3231
belongs_to_associations.each do |association|
3332
next if association.polymorphic?
3433

35-
# Check if the associated model has a matching counter column
3634
if should_have_counter_cache?(association) && !has_counter_cache?(association)
37-
notes << "Consider adding counter cache for '#{association.name}'"
35+
notes << NoteCodes.note(association.name.to_s, NoteCodes::COUNTER_CACHE)
3836
end
3937
end
4038

@@ -74,8 +72,6 @@ def bidirectional_association?(association)
7472
end
7573

7674
def should_have_counter_cache?(association)
77-
# A counter cache is needed if there is a has_many association
78-
# on the other side of the belongs_to, and no counter_cache is defined.
7975
return false unless association.macro == :belongs_to
8076

8177
inverse_association = association.inverse_of

lib/rails_lens/analyzers/best_practices_analyzer.rb

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def analyze
88
notes.concat(analyze_timestamps)
99
notes.concat(analyze_soft_deletes)
1010
notes.concat(analyze_sti_columns)
11-
notes.concat(analyze_naming_conventions)
11+
notes.concat(analyze_large_text_columns)
1212
notes
1313
end
1414

@@ -17,63 +17,38 @@ def analyze
1717
def analyze_timestamps
1818
notes = []
1919

20-
notes << 'Missing timestamp columns (created_at, updated_at)' unless has_timestamps?
20+
notes << NoteCodes::NO_TIMESTAMPS unless has_timestamps?
2121

2222
if has_column?('created_at') && !has_column?('updated_at')
23-
notes << 'Has created_at but missing updated_at'
23+
notes << NoteCodes::PARTIAL_TS
2424
elsif !has_column?('created_at') && has_column?('updated_at')
25-
notes << 'Has updated_at but missing created_at'
25+
notes << NoteCodes::PARTIAL_TS
2626
end
2727

2828
notes
2929
end
3030

3131
def analyze_soft_deletes
32-
notes = []
33-
34-
soft_delete_columns.each do |column|
35-
notes << "Soft delete column '#{column.name}' should be indexed" unless indexed?(column)
32+
soft_delete_columns.reject { |col| indexed?(col) }.map do |column|
33+
NoteCodes.note(column.name, NoteCodes::INDEX)
3634
end
37-
38-
notes
3935
end
4036

4137
def analyze_sti_columns
4238
notes = []
4339

4440
if sti_model? && type_column
45-
notes << "STI type column '#{type_column.name}' should be indexed" unless indexed?(type_column)
46-
47-
notes << "STI type column '#{type_column.name}' should have NOT NULL constraint" if type_column.null
41+
notes << NoteCodes.note(type_column.name, NoteCodes::INDEX) unless indexed?(type_column)
42+
notes << NoteCodes.note(type_column.name, NoteCodes::STI_NOT_NULL) if type_column.null
4843
end
4944

5045
notes
5146
end
5247

53-
def analyze_naming_conventions
54-
notes = []
55-
56-
# Check for non-conventional column names
57-
columns.each do |column|
58-
if column.name.match?(/^(is|has)_/i)
59-
notes << "Column '#{column.name}' uses non-conventional prefix - consider removing 'is_' or 'has_'"
60-
end
61-
62-
if column.name.match?(/Id$/) # Capital I
63-
notes << "Column '#{column.name}' should use snake_case (e.g., '#{column.name.underscore}')"
64-
end
65-
end
66-
67-
# Check table naming
68-
# Extract the actual table name without schema prefix for PostgreSQL
69-
# PostgreSQL uses schema.table format (e.g., "ai.skills" -> "skills")
70-
unqualified_table = table_name.to_s.split('.').last
71-
72-
if !unqualified_table.match?(/^[a-z_]+$/) || unqualified_table != unqualified_table.pluralize
73-
notes << "Table name '#{table_name}' doesn't follow Rails conventions (should be plural, snake_case)"
48+
def analyze_large_text_columns
49+
columns.select { |c| c.type == :text }.map do |column|
50+
NoteCodes.note(column.name, NoteCodes::STORAGE)
7451
end
75-
76-
notes
7752
end
7853

7954
def has_timestamps?

0 commit comments

Comments
 (0)