rubocop-pixelforce 2.0.0 → 2.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16bc89330d3996087dffc1f7e3ec8e3b50d8965ba6190d643e9177befe1ccf6f
4
- data.tar.gz: 901f067575c85f4a2d5b3556ca8e99a834ac7323997e991cd1e5c4c00245d55e
3
+ metadata.gz: cd94f0a6e83044823c99b918495faa1a159e902995a358d642760eb89383140e
4
+ data.tar.gz: 254b7384bd4c79bea3e4406815619c0c96ad34efea1991934bd4827e2b854620
5
5
  SHA512:
6
- metadata.gz: 619e39e98a72ccd21a93dd177b9b28b6353eae540a03f9417ffff3f1d44426ee38aa9d790b5bcec172ea4248ffc35f9b03ab2afe79bf8afa76b111ee148f91b3
7
- data.tar.gz: bd417a44a6b93879987cf76a238318faa6fd7c89c282ceeb68185d82389e18217dfe1378138ae03ad25eb8570adb73baf3499d91231d48f2f84c0726ee8ac0fa
6
+ metadata.gz: 778cece340e324267da10f497def005ecc4dffbdad1d10c69aedf491e051c558cd9d83211c207238fd73173caea65448b2b960c4e96ffbfd86bbf9856a90944e
7
+ data.tar.gz: 1cf1db1efbb5fd26f86b1b7121bde6f31a6d3f33e96404549dcb08daaa2b8cd334c066fbb04cd142aa5fa522a0175805fd5282fc6273fbff3e9b939601d32a8f
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubocop-pixelforce (2.0.0)
5
- rubocop (~> 1.21)
4
+ rubocop-pixelforce (2.3.0)
5
+ rubocop (~> 1.75)
6
6
  rubocop-performance
7
7
  rubocop-rails
8
8
 
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Rubocop::Pixelforce
2
2
 
3
- Custom Rubocop cop for PixlForce
4
-
3
+ Custom Rubocop cop for PixelForce
5
4
 
6
5
  ## Installation
7
6
 
@@ -15,14 +14,24 @@ And then execute:
15
14
 
16
15
  $ bundle
17
16
 
18
- and create .rubocop file like this
17
+ Create a `.rubocop.yml` file in your project root:
19
18
 
20
- ```
19
+ ```yaml
21
20
  inherit_gem:
22
21
  rubocop-pixelforce: default.yml
23
22
  ```
24
23
 
25
- ## Pixelforce/ClassStructure: Don't Use empty lines between same categories.
24
+ ### Dependencies
25
+
26
+ This gem automatically includes the following dependencies:
27
+ - `rubocop-performance` - for performance-related cops
28
+ - `rubocop-rails` - for Rails-specific cops
29
+
30
+ If you encounter any issues with missing cops, make sure these gems are properly installed.
31
+
32
+ ## Usage
33
+
34
+ ### Pixelforce/EmptyLineBetweenCategories: Don't Use empty lines between same categories.
26
35
 
27
36
  ```ruby
28
37
  # bad
@@ -39,7 +48,7 @@ belongs_to :category
39
48
  after_commit :update_geo_location
40
49
  ```
41
50
 
42
- ## Pixelforce/ClassStructure: Use empty lines between categories.
51
+ ### Pixelforce/EmptyLineBetweenCategories: Use empty lines between categories.
43
52
 
44
53
  ```ruby
45
54
  # bad
@@ -57,6 +66,27 @@ belongs_to :category
57
66
  after_commit :update_geo_location
58
67
  ```
59
68
 
69
+ ## Troubleshooting
70
+
71
+ ### Error: "Rails cops have been extracted to the rubocop-rails gem"
72
+
73
+ If you see this error, it means the `rubocop-rails` plugin is not properly loaded. This gem automatically includes `rubocop-rails` as a dependency, but if you're still seeing this error:
74
+
75
+ 1. Make sure you're using the latest version of this gem
76
+ 2. Run `bundle update rubocop-pixelforce` to update to the latest version
77
+ 3. Ensure your `.rubocop.yml` inherits from this gem's configuration:
78
+ ```yaml
79
+ inherit_gem:
80
+ rubocop-pixelforce: default.yml
81
+ ```
82
+
83
+ ### Error: "unrecognized cop or department"
84
+
85
+ If you see errors about unrecognized cops, make sure you have the latest version of RuboCop and this gem installed:
86
+
87
+ ```bash
88
+ bundle update rubocop rubocop-pixelforce
89
+ ```
60
90
 
61
91
  ## Development
62
92
 
@@ -66,4 +96,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
66
96
 
67
97
  ## Contributing
68
98
 
69
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rubocop-pixelforce.
99
+ Bug reports and pull requests are welcome on GitHub at https://github.com/BenZhang/rubocop-pixelforce.
data/default.yml CHANGED
@@ -1,3 +1,13 @@
1
+ # RuboCop Pixelforce Configuration
2
+ #
3
+ # This configuration requires the following gems to be installed:
4
+ # - rubocop-performance
5
+ # - rubocop-rails
6
+ #
7
+ # Make sure these are included in your Gemfile:
8
+ # gem 'rubocop-performance', require: false
9
+ # gem 'rubocop-rails', require: false
10
+
1
11
  plugins:
2
12
  - rubocop-performance
3
13
  - rubocop-rails
@@ -13,19 +23,6 @@ AllCops:
13
23
  - 'config/**/*'
14
24
  - 'test/**/*'
15
25
 
16
- Rails/UnknownEnv:
17
- Environments:
18
- - production
19
- - development
20
- - test
21
- - staging
22
-
23
- Rails/HasManyOrHasOneDependent:
24
- Enabled: false
25
-
26
- Rails/FilePath:
27
- Enabled: false
28
-
29
26
  Layout/ClassStructure: &class_structures
30
27
  Enabled: true
31
28
  ExpectedOrder:
@@ -80,7 +77,7 @@ Layout/ClassStructure: &class_structures
80
77
  - prepend
81
78
  - extend
82
79
 
83
- Pixelforce/EmptyLineBwteenCategories:
80
+ Pixelforce/EmptyLineBetweenCategories:
84
81
  <<: *class_structures
85
82
  Enabled: true
86
83
 
@@ -142,4 +139,21 @@ Style/GlobalVars:
142
139
  Enabled: false
143
140
 
144
141
  Metrics/ParameterLists:
142
+ Enabled: false
143
+
144
+ # Rails cops - these require the rubocop-rails plugin to be installed
145
+ # If you get an error about Rails cops being extracted, make sure you have
146
+ # 'rubocop-rails' gem installed and listed in the plugins section above
147
+
148
+ Rails/UnknownEnv:
149
+ Environments:
150
+ - production
151
+ - development
152
+ - test
153
+ - staging
154
+
155
+ Rails/HasManyOrHasOneDependent:
156
+ Enabled: false
157
+
158
+ Rails/FilePath:
145
159
  Enabled: false
@@ -3,16 +3,19 @@ module RuboCop
3
3
  module Pixelforce
4
4
  class EmptyLineBetweenCategories < Base
5
5
  include RangeHelp
6
+ extend AutoCorrector
6
7
 
7
8
  HUMANIZED_NODE_TYPE = {
8
9
  casgn: :constants,
9
10
  defs: :class_methods,
10
11
  def: :public_methods,
11
- sclass: :class_singleton
12
+ sclass: :class_singleton,
13
+ send: :method_calls
12
14
  }.freeze
13
15
 
14
16
  VISIBILITY_SCOPES = %i[private protected public].freeze
15
- MSG = 'Use empty lines between categories.'
17
+ MSG_EMPTY_LINE_BETWEEN_CATEGORIES = 'Use empty lines between categories.'.freeze
18
+ MSG_EMPTY_LINE_BETWEEN_SAME_CATEGORIES = "Don't Use empty lines between same categories.".freeze
16
19
 
17
20
  def_node_matcher :visibility_block?, <<~PATTERN
18
21
  (send nil? { :private :protected :public })
@@ -22,41 +25,46 @@ module RuboCop
22
25
  # Add offense when find a node out of expected order.
23
26
  def on_class(class_node)
24
27
  previous_category = nil
25
- previous_node_end_line = -1
26
- previous_method_name = nil
27
- walk_over_nested_class_definition(class_node) do |node, category|
28
- next unless node.respond_to?(:method_name)
29
28
 
30
- if previous_category && category != previous_category && node.loc.first_line - previous_node_end_line < 2
31
- add_offense(node, message: MSG)
29
+ walk_over_nested_class_definition(class_node) do |node, category|
30
+ # Skip empty line enforcement for method definitions
31
+ next if method_definition?(node)
32
+
33
+ if previous_category && previous_category != category
34
+ count = blank_lines_count_between(prev_node(node), node)
35
+ if count < 2
36
+ add_offense(node, message: MSG_EMPTY_LINE_BETWEEN_CATEGORIES) do |corrector|
37
+ prev_category = prev_node(node)
38
+ end_pos = end_position_for(prev_category)
39
+ newline_pos = buffer.source.index("\n", end_pos)
40
+ where_to_insert = range_between(newline_pos, newline_pos + 1)
41
+ corrector.insert_after(where_to_insert, "\n")
42
+ end
43
+ end
44
+ elsif previous_category && previous_category == category
45
+ count = blank_lines_count_between(prev_node(node), node)
46
+ if count > 1
47
+ add_offense(node, message: MSG_EMPTY_LINE_BETWEEN_SAME_CATEGORIES) do |corrector|
48
+ prev_category = prev_node(node)
49
+ end_pos = end_position_for(prev_category)
50
+ newline_pos = buffer.source.index("\n", end_pos)
51
+ range_to_remove = range_between(newline_pos, newline_pos + 1)
52
+ corrector.remove(range_to_remove)
53
+ end
54
+ end
32
55
  end
33
56
 
34
- if previous_method_name && previous_method_name == node.method_name && node.loc.first_line - previous_node_end_line > 1
35
- add_offense(node, message: "Don't Use empty lines between same categories.")
36
- end
37
57
  previous_category = category
38
- previous_node_end_line = node.loc.last_line
39
- previous_method_name = node.method_name
40
58
  end
41
59
  end
42
60
 
43
- def autocorrect(node)
44
- prev_category = prev_node(node)
45
- # finds position of first newline
46
- end_pos = end_position_for(prev_category)
47
- newline_pos = buffer.source.index("\n", end_pos)
48
-
49
- count = blank_lines_count_between(prev_category, node)
61
+ private
50
62
 
51
- if count > 1
52
- autocorrect_remove_lines(newline_pos, count)
53
- else
54
- autocorrect_insert_lines(newline_pos, count)
55
- end
63
+ # Check if a node is a method definition
64
+ def method_definition?(node)
65
+ node.def_type? || node.defs_type?
56
66
  end
57
67
 
58
- private
59
-
60
68
  # Classifies a node to match with something in the {expected_order}
61
69
  # @param node to be analysed
62
70
  # @return String when the node type is a `:block` then
@@ -221,20 +229,6 @@ module RuboCop
221
229
  def categories
222
230
  cop_config['Categories']
223
231
  end
224
-
225
- def autocorrect_remove_lines(newline_pos, _count)
226
- range_to_remove = range_between(newline_pos, newline_pos + 1)
227
- lambda do |corrector|
228
- corrector.remove(range_to_remove)
229
- end
230
- end
231
-
232
- def autocorrect_insert_lines(newline_pos, _count)
233
- where_to_insert = range_between(newline_pos, newline_pos + 1)
234
- lambda do |corrector|
235
- corrector.insert_after(where_to_insert, "\n")
236
- end
237
- end
238
232
  end
239
233
  end
240
234
  end
@@ -1,5 +1,5 @@
1
1
  module Rubocop
2
2
  module Pixelforce
3
- VERSION = '2.0.0'
3
+ VERSION = '2.3.0'
4
4
  end
5
5
  end
@@ -1,35 +1,35 @@
1
- lib = File.expand_path("lib", __dir__)
1
+ lib = File.expand_path('lib', __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "rubocop/pixelforce/version"
3
+ require 'rubocop/pixelforce/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "rubocop-pixelforce"
6
+ spec.name = 'rubocop-pixelforce'
7
7
  spec.version = Rubocop::Pixelforce::VERSION
8
- spec.authors = ["Ben Zhang"]
9
- spec.email = ["bzbnhang@gmail.com"]
8
+ spec.authors = ['Ben Zhang']
9
+ spec.email = ['bzbnhang@gmail.com']
10
10
 
11
- spec.summary = %q{Custom Rubocop cop for PixelForce.}
12
- spec.description = %q{Use empty lines between categories and Don't Use empty lines between same categories.}
13
- spec.homepage = "https://github.com/BenZhang/rubocop-pixelforce"
11
+ spec.summary = 'Custom Rubocop cop for PixelForce.'
12
+ spec.description = "Use empty lines between categories and Don't Use empty lines between same categories."
13
+ spec.homepage = 'https://github.com/BenZhang/rubocop-pixelforce'
14
14
 
15
- spec.metadata["homepage_uri"] = spec.homepage
16
- spec.metadata["source_code_uri"] = "https://github.com/BenZhang/rubocop-pixelforce"
17
- spec.metadata["changelog_uri"] = "https://github.com/BenZhang/rubocop-pixelforce"
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+ spec.metadata['source_code_uri'] = 'https://github.com/BenZhang/rubocop-pixelforce'
17
+ spec.metadata['changelog_uri'] = 'https://github.com/BenZhang/rubocop-pixelforce'
18
18
 
19
19
  # Specify which files should be added to the gem when it is released.
20
20
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
22
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
23
  end
24
- spec.bindir = "exe"
24
+ spec.bindir = 'exe'
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
- spec.require_paths = ["lib"]
26
+ spec.require_paths = ['lib']
27
27
 
28
- spec.add_development_dependency "bundler", "~> 2.0"
29
- spec.add_development_dependency "rake", "~> 13.0"
30
- spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency 'bundler', '~> 2.0'
29
+ spec.add_development_dependency 'rake', '~> 13.0'
30
+ spec.add_development_dependency 'rspec', '~> 3.0'
31
31
 
32
- spec.add_runtime_dependency "rubocop", "~> 1.21"
33
- spec.add_runtime_dependency "rubocop-performance"
34
- spec.add_runtime_dependency "rubocop-rails"
32
+ spec.add_runtime_dependency 'rubocop', '~> 1.75'
33
+ spec.add_runtime_dependency 'rubocop-performance'
34
+ spec.add_runtime_dependency 'rubocop-rails'
35
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-pixelforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Zhang
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.21'
61
+ version: '1.75'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.21'
68
+ version: '1.75'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubocop-performance
71
71
  requirement: !ruby/object:Gem::Requirement