rubocop-nueca 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4a58e87bfcf5ac18b1e87c51da6a3fd4b37e53c664ec86518ae05c5275b446b2
4
+ data.tar.gz: 9f08cc06b6f03c0bd16ab76fd3b66e2540f2e4c1ba06d23a02f0bffe49c778fa
5
+ SHA512:
6
+ metadata.gz: 436c241836f68bd0136f66d6639ea08c2d8e935583609a421c1045222903aff380a4553df6169dd9131e7e6fddeaf82110a003e4050f0966c1955bbcaa8d3d33
7
+ data.tar.gz: 27fb4e271c37e2ee980669e81f8c0237d3314a3fc77ba0310bc2401c75430b99cbe765991c418b848432c3ff20de036e338c09a86d26370171368bcac46aedae
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # About
2
+
3
+ This enforces custom rules for Nueca according to culture.
4
+
5
+ ## Installation
6
+
7
+ Add to your Gemfile the following code.
8
+
9
+ ```ruby
10
+ gem 'rubocop-nueca', require: false
11
+ ```
12
+
13
+ Run `bundle install`.
14
+
15
+ # Usage
16
+
17
+ Add to your `.rubocop.yml` the following code.
18
+
19
+ ```yaml
20
+ plugins:
21
+ - rubocop-nueca
22
+ ```
23
+
24
+ ## License
25
+
26
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,106 @@
1
+ plugins:
2
+ - rubocop-capybara
3
+ - rubocop-factory_bot
4
+ - rubocop-performance
5
+ - rubocop-rails
6
+ - rubocop-rspec
7
+ - rubocop-rspec_rails
8
+
9
+ AllCops:
10
+ NewCops: enable
11
+ Exclude:
12
+ - 'bin/**/*'
13
+ - 'config/environments/**/*'
14
+ - 'db/*schema.rb'
15
+
16
+ Style/SymbolArray:
17
+ EnforcedStyle: brackets
18
+
19
+ Style/WordArray:
20
+ EnforcedStyle: brackets
21
+
22
+ Metrics/BlockLength:
23
+ CountComments: false
24
+ CountAsOne: [array, hash, heredoc, method_call]
25
+ Exclude:
26
+ - '**/config/routes.rb'
27
+ - '**/config/routes/**/*'
28
+
29
+ Metrics/ClassLength:
30
+ CountComments: false
31
+ CountAsOne: [array, hash, heredoc, method_call]
32
+ Exclude:
33
+ - 'db/migrate/**/*'
34
+
35
+ Metrics/MethodLength:
36
+ Max: 20
37
+ CountComments: false
38
+ CountAsOne: [array, hash, heredoc, method_call]
39
+ Exclude:
40
+ - 'db/migrate/**/*'
41
+
42
+ Metrics/ModuleLength:
43
+ CountComments: false
44
+ CountAsOne: [array, hash, heredoc, method_call]
45
+
46
+ Naming/PredicateMethod:
47
+ AllowedMethods:
48
+ - call
49
+ - data
50
+ - action
51
+
52
+ Naming/AccessorMethodName:
53
+ Exclude:
54
+ - 'app/datatables/**/*'
55
+
56
+ Lint/MissingSuper:
57
+ Enabled: false
58
+
59
+ Style/ClassAndModuleChildren:
60
+ Enabled: false
61
+
62
+ Style/HashSyntax:
63
+ EnforcedShorthandSyntax: never
64
+
65
+ Metrics/AbcSize:
66
+ Max: 21
67
+
68
+ Rails/I18nLocaleTexts:
69
+ Enabled: false
70
+
71
+ RSpec/ImplicitSubject:
72
+ EnforcedStyle: single_statement_only
73
+
74
+ RSpec/SharedExamples:
75
+ EnforcedStyle: symbol
76
+
77
+ RSpec/MultipleMemoizedHelpers:
78
+ Max: 10
79
+
80
+ RSpec/NestedGroups:
81
+ Max: 5
82
+
83
+ RSpec/VerifiedDoubles:
84
+ Enabled: false
85
+
86
+ Rails/HelperInstanceVariable:
87
+ Enabled: false
88
+
89
+ RSpec/ExampleLength:
90
+ Enabled: false
91
+
92
+ Rails/UnknownEnv:
93
+ Environments:
94
+ - production
95
+ - development
96
+ - test
97
+ - staging
98
+
99
+ RSpec/MultipleExpectations:
100
+ Enabled: false
101
+
102
+ Rails/CreateTableWithTimestamps:
103
+ Enabled: false
104
+
105
+ Style/Documentation:
106
+ Enabled: false
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Rails
6
+ class DateTimeConversion < RuboCop::Cop::Base
7
+ MSG = 'Use in_time_zone(...) instead of using to_datetime.'
8
+ RESTRICT_ON_SEND = [:to_datetime].freeze
9
+
10
+ def on_send(node)
11
+ add_offense(node)
12
+ end
13
+
14
+ def on_csend(node)
15
+ return unless node.method_name == :to_datetime
16
+
17
+ add_offense(node)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Rails
6
+ class DateTimeCurrent < RuboCop::Cop::Base
7
+ MSG = 'Use Time.current instead of DateTime.current.'
8
+ RESTRICT_ON_SEND = [:current].freeze
9
+
10
+ def_node_matcher :datetime_curent_usage, <<~PATTERN
11
+ (send
12
+ (const nil? :DateTime) :current)
13
+ PATTERN
14
+
15
+ def on_send(node)
16
+ return unless datetime_curent_usage(node)
17
+
18
+ add_offense(node)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Rails
6
+ class MigrationTableVariable < RuboCop::Cop::Base
7
+ MSG = 'Use `t` as the variable name for table operations in migrations.'
8
+
9
+ def_node_matcher :create_table_block, <<~PATTERN
10
+ (block (send nil? :create_table ...) (args (arg $_)) ...)
11
+ PATTERN
12
+
13
+ def_node_matcher :change_table_block, <<~PATTERN
14
+ (block (send nil? :change_table ...) (args (arg $_)) ...)
15
+ PATTERN
16
+
17
+ def on_block(node)
18
+ return unless in_migration_file?
19
+
20
+ variable_name = extract_table_variable(node)
21
+ return unless variable_name
22
+ return if variable_name == :t
23
+
24
+ add_offense(node.arguments.first, message: MSG)
25
+ end
26
+
27
+ private
28
+
29
+ def extract_table_variable(node)
30
+ create_table_block(node) ||
31
+ change_table_block(node)
32
+ end
33
+
34
+ def in_migration_file?
35
+ processed_source.file_path&.include?('db/migrate/') || false
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Rails
6
+ class ModelAssociationConsistentSpacing < RuboCop::Cop::Base
7
+ MSG = 'Do not leave blank lines between associations of the same type.'
8
+ ASSOCIATION_METHODS = [
9
+ :belongs_to,
10
+ :has_one,
11
+ :has_many,
12
+ :has_and_belongs_to_many
13
+ ].freeze
14
+
15
+ def on_class(node)
16
+ return unless model_class?(node)
17
+
18
+ associations = find_associations(node)
19
+ return if associations.empty?
20
+
21
+ check_consistent_spacing(associations)
22
+ end
23
+
24
+ private
25
+
26
+ def model_class?(node)
27
+ node_parent = node.parent_class
28
+ return false unless node_parent
29
+
30
+ parent_class = node_parent
31
+ parent_class_name = case parent_class.type
32
+ when :const
33
+ parent_class.const_name
34
+ else
35
+ parent_class.source
36
+ end
37
+
38
+ parent_class_name&.include?('ApplicationRecord') ||
39
+ parent_class_name&.include?('ActiveRecord::Base')
40
+ end
41
+
42
+ def find_associations(class_node)
43
+ associations = []
44
+
45
+ body = class_node.body
46
+ body&.each_child_node do |child|
47
+ next unless child.type == :send
48
+
49
+ method_name = child.method_name
50
+ associations << child if ASSOCIATION_METHODS.include?(method_name)
51
+ end
52
+
53
+ associations
54
+ end
55
+
56
+ def check_consistent_spacing(associations)
57
+ associations.each_cons(2) do |prev_assoc, curr_assoc|
58
+ next unless prev_assoc.method_name == curr_assoc.method_name
59
+
60
+ prev_end_line = prev_assoc.loc.last_line
61
+ curr_start_line = curr_assoc.loc.line
62
+
63
+ next unless curr_start_line - prev_end_line > 1
64
+
65
+ add_offense(curr_assoc, message: MSG)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Rails
6
+ class ModelAssociationGrouping < RuboCop::Cop::Base
7
+ MSG = 'Group associations of the same type together.'
8
+ ASSOCIATION_METHODS = [
9
+ :belongs_to,
10
+ :has_one,
11
+ :has_many,
12
+ :has_and_belongs_to_many
13
+ ].freeze
14
+
15
+ def on_class(node)
16
+ return unless model_class?(node)
17
+
18
+ associations = find_associations(node)
19
+ return if associations.empty?
20
+
21
+ check_association_grouping(associations)
22
+ end
23
+
24
+ private
25
+
26
+ def model_class?(node)
27
+ node_parent = node.parent_class
28
+ return false unless node_parent
29
+
30
+ parent_class = node_parent
31
+ parent_class_name = case parent_class.type
32
+ when :const
33
+ parent_class.const_name
34
+ else
35
+ parent_class.source
36
+ end
37
+
38
+ parent_class_name&.include?('ApplicationRecord') ||
39
+ parent_class_name&.include?('ActiveRecord::Base')
40
+ end
41
+
42
+ def find_associations(class_node)
43
+ associations = []
44
+
45
+ body = class_node.body
46
+ body&.each_child_node do |child|
47
+ child_type = child.type
48
+ next unless child_type == :send
49
+
50
+ method_name = child.method_name
51
+ associations << child if ASSOCIATION_METHODS.include?(method_name)
52
+ end
53
+
54
+ associations
55
+ end
56
+
57
+ def check_association_grouping(associations)
58
+ grouped_associations = associations.group_by(&:method_name)
59
+
60
+ grouped_associations.each_value do |same_type_associations|
61
+ next if same_type_associations.length <= 1
62
+
63
+ check_same_type_grouping(same_type_associations, associations)
64
+ end
65
+ end
66
+
67
+ def check_same_type_grouping(same_type_associations, all_associations)
68
+ groups = find_contiguous_groups(same_type_associations, all_associations)
69
+
70
+ return unless groups.length > 1
71
+
72
+ groups[1..].each do |group|
73
+ add_offense(group.first, message: MSG)
74
+ end
75
+ end
76
+
77
+ def find_contiguous_groups(same_type_associations, all_associations)
78
+ return [] if same_type_associations.empty?
79
+
80
+ target_method = same_type_associations.first.method_name
81
+ sorted_associations = all_associations.sort_by { |assoc| assoc.loc.line }
82
+
83
+ build_contiguous_groups(sorted_associations, target_method)
84
+ end
85
+
86
+ def build_contiguous_groups(sorted_associations, target_method)
87
+ groups = []
88
+ current_group = []
89
+
90
+ (sorted_associations + [nil]).each do |association|
91
+ if association && matches_target_method?(association, target_method)
92
+ current_group << association
93
+ else
94
+ finalize_group(groups, current_group)
95
+ end
96
+ end
97
+
98
+ groups
99
+ end
100
+
101
+ def finalize_group(groups, current_group)
102
+ return unless current_group.any?
103
+
104
+ groups << current_group.dup
105
+ current_group.clear
106
+ end
107
+
108
+ def matches_target_method?(association, target_method)
109
+ association.method_name == target_method
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Rails
6
+ class ModelAssociationScattering < RuboCop::Cop::Base
7
+ MSG = 'Group all associations together without non-association code scattered between them.'
8
+ ASSOCIATION_METHODS = [
9
+ :belongs_to,
10
+ :has_one,
11
+ :has_many,
12
+ :has_and_belongs_to_many
13
+ ].freeze
14
+
15
+ def on_class(node)
16
+ return unless model_class?(node)
17
+
18
+ associations = find_associations(node)
19
+ return if associations.empty?
20
+
21
+ check_association_scattering(associations, node)
22
+ end
23
+
24
+ private
25
+
26
+ def model_class?(node)
27
+ node_parent = node.parent_class
28
+ return false unless node_parent
29
+
30
+ parent_class = node_parent
31
+ parent_name = parent_class.const_name
32
+ ['ApplicationRecord', 'ActiveRecord::Base'].include?(parent_name)
33
+ end
34
+
35
+ def find_associations(class_node)
36
+ associations = []
37
+
38
+ class_node.body&.each_child_node do |child|
39
+ next unless child.type == :send
40
+ next unless association_method?(child)
41
+
42
+ associations << child
43
+ end
44
+
45
+ associations.sort_by { |assoc| assoc.loc.line }
46
+ end
47
+
48
+ def association_method?(node)
49
+ return false unless node.receiver.nil?
50
+
51
+ ASSOCIATION_METHODS.include?(node.method_name)
52
+ end
53
+
54
+ def check_association_scattering(associations, class_node)
55
+ scattered_associations = find_scattered_associations(associations, class_node)
56
+
57
+ scattered_associations.each do |association|
58
+ add_offense(association, message: MSG)
59
+ end
60
+ end
61
+
62
+ def find_scattered_associations(associations, class_node)
63
+ return [] if associations.size <= 1
64
+
65
+ scattered = []
66
+ body_node = class_node.body
67
+
68
+ associations.each_with_index do |assoc, index|
69
+ next if index.zero?
70
+
71
+ current_line = assoc.loc.line
72
+ prev_assoc = associations[index - 1]
73
+ prev_line = prev_assoc.loc.line
74
+
75
+ if non_association_between?(body_node, prev_line, current_line) && !scattered.include?(assoc) # rubocop:disable Rails/NegateInclude
76
+ scattered << assoc
77
+ end
78
+ end
79
+
80
+ scattered
81
+ end
82
+
83
+ def non_association_between?(body_node, start_line, end_line)
84
+ body_node&.each_child_node do |child|
85
+ child_line = child.loc.line
86
+ return true if child_line > start_line && child_line < end_line && !association_node?(child)
87
+ end
88
+ false
89
+ end
90
+
91
+ def association_node?(node)
92
+ node.type == :send && ASSOCIATION_METHODS.include?(node.method_name)
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end