rubocop-greppable_rails 0.1.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8dcdbd2384385602ec76c55bbc2d3930a5a941c840a1fe9f953ea56da7841c76
4
- data.tar.gz: ec03c27bf9b70f9c4f2306875148b32c87bda4668c7deb16fff5f5df08095033
3
+ metadata.gz: 2135f6033c07d3419576216846ddc26d6838a0ee77bfcee2eab21316365b9019
4
+ data.tar.gz: 8e94f5c4fdb4347cc47ab5207777bd28c7bf24866089eab85771507e5570f2a6
5
5
  SHA512:
6
- metadata.gz: 2276743cc6dc3bdc68bc76b42e9490cf80488947706a7d925b9e82db3561f456ed9fcc4fe53006d4cddd54336db200f7ede2dbb6729abab5802b5264b92b2c3c
7
- data.tar.gz: 6369f9d1abb1d2b216aca508eddc2ef47ba8ce321fb0fdc87edd91e3049af53d59e9d938c1c2871bb92e2e23982584deed65554bbbc9c5b1e6b5c21502e087e9
6
+ metadata.gz: 3f69c14d595614c6bb236ca0e7603fb1a0eaa4382781ef650043a7d74acb4437fcb11e17b56a00f3ac19f6c55b53fa9c77cdc2911779ed560909c0467409e7ba
7
+ data.tar.gz: 54247ab5282215e5cda7fdfe3ed68a83f82cc92599562862fa83d24d7ed908666af3c809fd14f8398ddf151f980d5fed1983797f6aa388ba916b3a60747bdf8e
@@ -0,0 +1,12 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "github-actions"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "weekly"
7
+ cooldown:
8
+ default-days: 7
9
+ groups:
10
+ actions:
11
+ patterns:
12
+ - "*"
@@ -6,14 +6,17 @@ jobs:
6
6
  build:
7
7
  runs-on: ubuntu-latest
8
8
  strategy:
9
+ fail-fast: false
9
10
  matrix:
10
- ruby: [ '2.7', '3.0' ]
11
+ ruby: [ '3.2', '3.3', '3.4', '4.0', 'head' ]
11
12
  name: Test on Ruby ${{ matrix.ruby }}
12
13
  steps:
13
- - uses: actions/checkout@v2
14
- - uses: ruby/setup-ruby@v1
14
+ - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
15
+ - uses: ruby/setup-ruby@6aaa311d81eba98ae12eaffbcb63296ace0efcde # v1.307.0
15
16
  with:
16
17
  ruby-version: ${{ matrix.ruby }}
17
18
  bundler-cache: true
18
- - name: Execute test & rubocop
19
+ - name: Execute rubocop
19
20
  run: bundle exec rake
21
+ - name: Execute rspec
22
+ run: bundle exec rspec
data/.gitignore CHANGED
@@ -8,3 +8,5 @@
8
8
  /tmp/
9
9
  /spec/examples.txt
10
10
  Gemfile.lock
11
+
12
+ todo.md
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.7
2
+ TargetRubyVersion: 3.2
3
3
  NewCops: disable
4
4
  SuggestExtensions: false
5
5
 
data/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+ # Changelog
2
+
3
+ All notable changes are documented here.
4
+
5
+ ## [1.0.0]
6
+
7
+ ### Added
8
+ - Migrated to the `lint_roller`-based RuboCop plugin system (RuboCop 1.72+). Register with `plugins: rubocop-greppable_rails` in `.rubocop.yml`.
9
+
10
+ ### Fixed
11
+ - `GreppableRails/NoHelperInController` and `GreppableRails/NoIncludeInHelper` now correctly handle namespaced classes/modules (e.g. `Admin::FoosController`).
12
+
13
+ ### Changed
14
+ - **Breaking:** Renamed cops for consistency with the RuboCop ecosystem:
15
+ - `GreppableRails/DontCallHelperInController` → `GreppableRails/NoHelperInController`
16
+ - `GreppableRails/DontIncludeInHelper` → `GreppableRails/NoIncludeInHelper`
17
+ - Bumped required Ruby to `>= 3.2`.
18
+ - Pinned `rubocop` runtime dependency to `>= 1.72`.
19
+ - Modernized CI matrix (Ruby 3.2 ~ head) and now actually run RSpec.
20
+ - Cleaned up gemspec metadata (summary/description).
21
+ - Renamed top-level module `Rubocop::GreppableRails` → `RuboCop::GreppableRails` to match RuboCop convention.
22
+
23
+ ## [0.1.1]
24
+
25
+ _Released before changelog was kept._
data/Gemfile CHANGED
@@ -7,5 +7,3 @@ gemspec
7
7
 
8
8
  gem "rake", "~> 13.0"
9
9
  gem "rspec"
10
-
11
- gem "rubocop", "~> 1.7"
data/README.md CHANGED
@@ -1,38 +1,123 @@
1
- # Rubocop::GreppableRails
1
+ # rubocop-greppable_rails
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rubocop/greppable_rails`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ A collection of RuboCop cops that discourage Rails patterns which obscure where code comes from (helper inclusion, non-inline access modifiers, etc.) so plain `grep` stays a useful tool when navigating your codebase.
6
4
 
7
5
  ## Installation
8
6
 
9
7
  Add this line to your application's Gemfile:
10
8
 
11
9
  ```ruby
12
- gem 'rubocop-greppable_rails'
10
+ gem "rubocop-greppable_rails", require: false
13
11
  ```
14
12
 
15
13
  And then execute:
16
14
 
17
- $ bundle install
15
+ ```sh
16
+ bundle install
17
+ ```
18
18
 
19
- Or install it yourself as:
19
+ ## Usage
20
20
 
21
- $ gem install rubocop-greppable_rails
21
+ Register the plugin in your `.rubocop.yml`:
22
22
 
23
- ## Usage
23
+ ```yaml
24
+ plugins:
25
+ - rubocop-greppable_rails
26
+ ```
27
+
28
+ ## Cops
29
+
30
+ ### `GreppableRails/NoIncludeInHelper`
31
+
32
+ Prohibits `include` inside helper modules. Including makes it hard to grep where a helper method actually lives, and broadens the constant-dependency surface.
33
+
34
+ Applies to: `app/helpers/**/*.rb`.
35
+
36
+ ```ruby
37
+ # bad
38
+ module TopHelper
39
+ include PostHelper
40
+
41
+ def some_link(posts)
42
+ some_post_link(posts.first)
43
+ end
44
+ end
45
+
46
+ # good
47
+ module PostLinkTag
48
+ module_function
49
+
50
+ def some_post_link(post)
51
+ # ...
52
+ end
53
+ end
54
+
55
+ module TopHelper
56
+ def some_link(posts)
57
+ PostLinkTag.some_post_link(posts.first)
58
+ end
59
+ end
60
+ ```
61
+
62
+ ### `GreppableRails/NoHelperInController`
24
63
 
25
- TODO: Write usage instructions here
64
+ Prohibits `helper :name` calls at class scope in controllers. Implicit helper inclusion makes the helper method's call site impossible to grep from the controller.
65
+
66
+ Applies to: `app/controllers/**/*.rb`.
67
+
68
+ ```ruby
69
+ # bad
70
+ class FoosController < ApplicationController
71
+ helper :bar
72
+ end
73
+
74
+ # good — call the helper module explicitly where you need it
75
+ class FoosController < ApplicationController
76
+ def show
77
+ @label = BarHelper.label_for(@foo)
78
+ end
79
+ end
80
+ ```
81
+
82
+ ### `GreppableRails/UseInlineAccessModifier`
83
+
84
+ Enforces inline-style access modifiers (`private def foo`) over group style (`private` then `def foo`) and symbol-arg style (`private :foo`). Inline form makes a method's visibility greppable on the same line as the definition.
85
+
86
+ ```ruby
87
+ # bad
88
+ class Foo
89
+ private
90
+
91
+ def bar; end
92
+ end
93
+
94
+ class Foo
95
+ def bar; end
96
+ private :bar
97
+ end
98
+
99
+ # good
100
+ class Foo
101
+ private def bar; end
102
+ end
103
+ ```
104
+
105
+ ## Configuration
106
+
107
+ Each cop accepts the standard RuboCop options (`Enabled`, `Exclude`, `Include`, …). Default `Include` paths are set in [`config/default.yml`](config/default.yml) and can be overridden in your project's `.rubocop.yml`.
26
108
 
27
109
  ## Development
28
110
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
111
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt.
30
112
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
113
+ ```sh
114
+ bundle exec rspec # tests
115
+ bundle exec rake # rubocop
116
+ ```
32
117
 
33
118
  ## Contributing
34
119
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/riseshia/rubocop-greppable_rails. This project is intended to be a safe, welcoming space for collaboration.
120
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/riseshia/rubocop-greppable_rails>.
36
121
 
37
122
  ## License
38
123
 
data/config/default.yml CHANGED
@@ -4,21 +4,23 @@ inherit_mode:
4
4
  merge:
5
5
  - Exclude
6
6
 
7
- GreppableRails/DontIncludeInHelper:
8
- Description: 'Prohibit include in Helper.'
7
+ GreppableRails/NoIncludeInHelper:
8
+ Description: 'Avoid `include` inside helper modules to keep helper definitions greppable.'
9
9
  Enabled: true
10
10
  VersionAdded: '0.1.0'
11
+ VersionChanged: '1.0.0'
11
12
  Include:
12
13
  - app/helpers/**/*.rb
13
14
 
14
15
  GreppableRails/UseInlineAccessModifier:
15
- Description: 'Use inline style access modifier.'
16
+ Description: 'Use the inline form of `private`/`protected` (`private def foo`) so method visibility stays on the same line as the definition.'
16
17
  Enabled: true
17
18
  VersionAdded: '0.1.0'
18
19
 
19
- GreppableRails/DontCallHelperInController:
20
- Description: 'Prohibit include helper via call helper in Controller.'
20
+ GreppableRails/NoHelperInController:
21
+ Description: 'Avoid `helper :name` at controller class scope; reference the helper module explicitly to keep call sites greppable.'
21
22
  Enabled: true
22
23
  VersionAdded: '0.1.0'
24
+ VersionChanged: '1.0.0'
23
25
  Include:
24
26
  - app/controllers/**/*.rb
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module GreppableRails
6
+ # Prohibits `helper :name` calls at controller class scope. Implicit
7
+ # helper inclusion makes the helper method's call site impossible to
8
+ # grep from the controller — call the helper module explicitly where
9
+ # you need it instead.
10
+ #
11
+ # @example
12
+ # # bad
13
+ # class FoosController < ApplicationController
14
+ # helper :bar
15
+ # end
16
+ #
17
+ # # good
18
+ # class FoosController < ApplicationController
19
+ # def show
20
+ # @label = BarHelper.label_for(@foo)
21
+ # end
22
+ # end
23
+ class NoHelperInController < Base
24
+ MSG = "Don't include helper via call helper in Controller."
25
+
26
+ RESTRICT_ON_SEND = %i[helper].freeze
27
+
28
+ def_node_matcher :helper_call?, <<~PATTERN
29
+ (send nil? {:helper} (sym _))
30
+ PATTERN
31
+
32
+ def on_send(node)
33
+ parent = node.parent
34
+ parent = parent.parent if parent&.begin_type?
35
+ return unless parent&.class_type?
36
+ return unless parent.identifier.const_name.end_with?("Controller")
37
+
38
+ add_offense(node) if offense?(node)
39
+ end
40
+
41
+ private
42
+
43
+ def offense?(node)
44
+ return true if node.arguments.empty?
45
+
46
+ node.arguments.first.type == :sym
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module GreppableRails
6
+ # Prohibits `include` inside helper modules. Including makes it hard
7
+ # to grep where a helper method actually lives, and broadens the
8
+ # constant-dependency surface so that changes to one helper become
9
+ # unpredictably visible from another.
10
+ #
11
+ # @example
12
+ # # bad
13
+ # # app/helpers/top_helper.rb
14
+ # module TopHelper
15
+ # include PostHelper
16
+ #
17
+ # def some_link(posts)
18
+ # some_post_link(posts.first)
19
+ # end
20
+ # end
21
+ #
22
+ # # good
23
+ # # app/helpers/post_link_tag.rb
24
+ # module PostLinkTag
25
+ # module_function
26
+ #
27
+ # def some_post_link(post)
28
+ # # ...
29
+ # end
30
+ # end
31
+ #
32
+ # # app/helpers/top_helper.rb
33
+ # module TopHelper
34
+ # def some_link(posts)
35
+ # PostLinkTag.some_post_link(posts.first)
36
+ # end
37
+ # end
38
+ class NoIncludeInHelper < Base
39
+ MSG = "Do not include in Helper."
40
+ RESTRICT_ON_SEND = %i[include].freeze
41
+
42
+ def_node_matcher :render_with_inline_option?, <<~PATTERN
43
+ (send _ :include (const _ _))
44
+ PATTERN
45
+
46
+ def on_send(node)
47
+ parent = node.parent
48
+ parent = parent.parent if parent&.begin_type?
49
+ return unless parent&.module_type?
50
+ return unless parent.identifier.const_name.end_with?("Helper")
51
+
52
+ add_offense(node) if render_with_inline_option?(node)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -3,6 +3,13 @@
3
3
  module RuboCop
4
4
  module Cop
5
5
  module GreppableRails
6
+ # Enforces the inline form of `private`/`protected` access modifiers
7
+ # (`private def foo`) over the group form (`private` then `def foo`)
8
+ # and the symbol-argument form (`private :foo`). The inline form keeps
9
+ # a method's visibility greppable on the same line as its definition.
10
+ #
11
+ # `public` and `module_function` are intentionally out of scope.
12
+ #
6
13
  # @example
7
14
  # # bad
8
15
  # class Foo
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "greppable_rails/dont_call_helper_in_controller"
4
- require_relative "greppable_rails/dont_include_in_helper"
3
+ require_relative "greppable_rails/no_helper_in_controller"
4
+ require_relative "greppable_rails/no_include_in_helper"
5
5
  require_relative "greppable_rails/use_inline_access_modifier"
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lint_roller"
4
+
5
+ module RuboCop
6
+ module GreppableRails
7
+ # LintRoller plugin entry point. Registers config/default.yml with RuboCop.
8
+ class Plugin < LintRoller::Plugin
9
+ def about
10
+ LintRoller::About.new(
11
+ name: "rubocop-greppable_rails",
12
+ version: VERSION,
13
+ homepage: "https://github.com/riseshia/rubocop-greppable_rails",
14
+ description: "RuboCop cops for keeping Rails code greppable."
15
+ )
16
+ end
17
+
18
+ def supported?(context)
19
+ context.engine == :rubocop
20
+ end
21
+
22
+ def rules(_context)
23
+ project_root = Pathname.new(__dir__).join("../../..")
24
+ LintRoller::Rules.new(
25
+ type: :path,
26
+ config_format: :rubocop,
27
+ value: project_root.join("config/default.yml")
28
+ )
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Rubocop
3
+ module RuboCop
4
4
  module GreppableRails
5
- VERSION = "0.1.1"
5
+ VERSION = "1.0.0"
6
6
  end
7
7
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  require_relative "greppable_rails/version"
4
4
 
5
- module Rubocop
5
+ module RuboCop
6
6
  # Root module for GreppableRails
7
7
  module GreppableRails
8
8
  end
@@ -3,4 +3,5 @@
3
3
  require "rubocop"
4
4
 
5
5
  require_relative "rubocop/greppable_rails"
6
+ require_relative "rubocop/greppable_rails/plugin"
6
7
  require_relative "rubocop/cop/greppable_rails_cops"
@@ -6,21 +6,23 @@ require "rubocop/greppable_rails/version"
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = "rubocop-greppable_rails"
9
- spec.version = Rubocop::GreppableRails::VERSION
9
+ spec.version = RuboCop::GreppableRails::VERSION
10
10
  spec.authors = ["Shia"]
11
11
  spec.email = ["rise.shia@gmail.com"]
12
12
 
13
- spec.summary = "rubocop/ReadableRails"
14
- spec.description = "For greppable rails"
13
+ spec.summary = "RuboCop cops for keeping Rails code greppable."
14
+ spec.description = "An opinionated set of RuboCop cops recommending Rails coding " \
15
+ "patterns that keep your codebase greppable. Each cop discourages " \
16
+ "a construct that obscures where code comes from, so plain text " \
17
+ "search remains a fast, reliable way to navigate the project."
15
18
  spec.homepage = "https://github.com/riseshia/rubocop-greppable_rails"
16
19
  spec.license = "MIT"
17
- spec.required_ruby_version = ">= 2.7.0"
18
-
19
- # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
+ spec.required_ruby_version = ">= 3.2.0"
20
21
 
21
22
  spec.metadata["homepage_uri"] = spec.homepage
22
- spec.metadata["source_code_uri"] = "https://github.com/riseshia/rubocop-greppable_rails"
23
- spec.metadata["changelog_uri"] = "https://github.com/riseshia/rubocop-greppable_rails"
23
+ spec.metadata["source_code_uri"] = spec.homepage
24
+ spec.metadata["changelog_uri"] = "https://github.com/riseshia/rubocop-greppable_rails/blob/main/CHANGELOG.md"
25
+ spec.metadata["default_lint_roller_plugin"] = "RuboCop::GreppableRails::Plugin"
24
26
 
25
27
  # Specify which files should be added to the gem when it is released.
26
28
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -31,9 +33,5 @@ Gem::Specification.new do |spec|
31
33
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
34
  spec.require_paths = ["lib"]
33
35
 
34
- # Uncomment to register a new dependency of your gem
35
- # spec.add_dependency "example-gem", "~> 1.0"
36
-
37
- # For more information and examples about making a new gem, checkout our
38
- # guide at: https://bundler.io/guides/creating_gem.html
36
+ spec.add_dependency "rubocop", ">= 1.72.0"
39
37
  end
metadata CHANGED
@@ -1,27 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-greppable_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shia
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2021-07-30 00:00:00.000000000 Z
12
- dependencies: []
13
- description: For greppable rails
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rubocop
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 1.72.0
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 1.72.0
26
+ description: An opinionated set of RuboCop cops recommending Rails coding patterns
27
+ that keep your codebase greppable. Each cop discourages a construct that obscures
28
+ where code comes from, so plain text search remains a fast, reliable way to navigate
29
+ the project.
14
30
  email:
15
31
  - rise.shia@gmail.com
16
32
  executables: []
17
33
  extensions: []
18
34
  extra_rdoc_files: []
19
35
  files:
36
+ - ".github/dependabot.yml"
20
37
  - ".github/workflows/main.yml"
21
38
  - ".gitignore"
22
39
  - ".rspec"
23
40
  - ".rubocop.yml"
24
- - CODE_OF_CONDUCT.md
41
+ - CHANGELOG.md
25
42
  - Gemfile
26
43
  - LICENSE.txt
27
44
  - README.md
@@ -30,11 +47,12 @@ files:
30
47
  - bin/setup
31
48
  - config/default.yml
32
49
  - lib/rubocop-greppable_rails.rb
33
- - lib/rubocop/cop/greppable_rails/dont_call_helper_in_controller.rb
34
- - lib/rubocop/cop/greppable_rails/dont_include_in_helper.rb
50
+ - lib/rubocop/cop/greppable_rails/no_helper_in_controller.rb
51
+ - lib/rubocop/cop/greppable_rails/no_include_in_helper.rb
35
52
  - lib/rubocop/cop/greppable_rails/use_inline_access_modifier.rb
36
53
  - lib/rubocop/cop/greppable_rails_cops.rb
37
54
  - lib/rubocop/greppable_rails.rb
55
+ - lib/rubocop/greppable_rails/plugin.rb
38
56
  - lib/rubocop/greppable_rails/version.rb
39
57
  - rubocop-greppable_rails.gemspec
40
58
  homepage: https://github.com/riseshia/rubocop-greppable_rails
@@ -43,8 +61,8 @@ licenses:
43
61
  metadata:
44
62
  homepage_uri: https://github.com/riseshia/rubocop-greppable_rails
45
63
  source_code_uri: https://github.com/riseshia/rubocop-greppable_rails
46
- changelog_uri: https://github.com/riseshia/rubocop-greppable_rails
47
- post_install_message:
64
+ changelog_uri: https://github.com/riseshia/rubocop-greppable_rails/blob/main/CHANGELOG.md
65
+ default_lint_roller_plugin: RuboCop::GreppableRails::Plugin
48
66
  rdoc_options: []
49
67
  require_paths:
50
68
  - lib
@@ -52,15 +70,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
52
70
  requirements:
53
71
  - - ">="
54
72
  - !ruby/object:Gem::Version
55
- version: 2.7.0
73
+ version: 3.2.0
56
74
  required_rubygems_version: !ruby/object:Gem::Requirement
57
75
  requirements:
58
76
  - - ">="
59
77
  - !ruby/object:Gem::Version
60
78
  version: '0'
61
79
  requirements: []
62
- rubygems_version: 3.2.3
63
- signing_key:
80
+ rubygems_version: 4.0.3
64
81
  specification_version: 4
65
- summary: rubocop/ReadableRails
82
+ summary: RuboCop cops for keeping Rails code greppable.
66
83
  test_files: []
data/CODE_OF_CONDUCT.md DELETED
@@ -1,84 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
-
7
- We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
-
9
- ## Our Standards
10
-
11
- Examples of behavior that contributes to a positive environment for our community include:
12
-
13
- * Demonstrating empathy and kindness toward other people
14
- * Being respectful of differing opinions, viewpoints, and experiences
15
- * Giving and gracefully accepting constructive feedback
16
- * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
- * Focusing on what is best not just for us as individuals, but for the overall community
18
-
19
- Examples of unacceptable behavior include:
20
-
21
- * The use of sexualized language or imagery, and sexual attention or
22
- advances of any kind
23
- * Trolling, insulting or derogatory comments, and personal or political attacks
24
- * Public or private harassment
25
- * Publishing others' private information, such as a physical or email
26
- address, without their explicit permission
27
- * Other conduct which could reasonably be considered inappropriate in a
28
- professional setting
29
-
30
- ## Enforcement Responsibilities
31
-
32
- Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
-
34
- Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
-
36
- ## Scope
37
-
38
- This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
-
40
- ## Enforcement
41
-
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at rise.shia@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
-
44
- All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
-
46
- ## Enforcement Guidelines
47
-
48
- Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
-
50
- ### 1. Correction
51
-
52
- **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
-
54
- **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
-
56
- ### 2. Warning
57
-
58
- **Community Impact**: A violation through a single incident or series of actions.
59
-
60
- **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
-
62
- ### 3. Temporary Ban
63
-
64
- **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
-
66
- **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
-
68
- ### 4. Permanent Ban
69
-
70
- **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
-
72
- **Consequence**: A permanent ban from any sort of public interaction within the community.
73
-
74
- ## Attribution
75
-
76
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
- available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
-
79
- Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
-
81
- [homepage]: https://www.contributor-covenant.org
82
-
83
- For answers to common questions about this code of conduct, see the FAQ at
84
- https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module GreppableRails
6
- # @example
7
- # # bad
8
- # class FooController
9
- # helper :bar
10
- # end
11
- class DontCallHelperInController < Base
12
- MSG = "Don't include helper via call helper in Controller."
13
-
14
- RESTRICT_ON_SEND = %i[helper].freeze
15
-
16
- def_node_matcher :helper_call?, <<~PATTERN
17
- (send nil? {:helper} (sym _))
18
- PATTERN
19
-
20
- def find_parent(node)
21
- parent_node = node.parent
22
- if parent_node.type == :begin
23
- parent_node.parent
24
- else
25
- parent_node
26
- end
27
- end
28
-
29
- def on_send(node)
30
- parent_node = find_parent(node)
31
- return unless parent_node.type == :class
32
-
33
- class_name = parent_node.children.first.children.last.to_s
34
- return unless class_name.end_with?("Controller")
35
-
36
- add_offense(node) if offense?(node)
37
- end
38
-
39
- private
40
-
41
- def offense?(node)
42
- return true if node.arguments.empty?
43
-
44
- node.arguments.first.type == :sym
45
- end
46
- end
47
- end
48
- end
49
- end
@@ -1,75 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RuboCop
4
- module Cop
5
- module GreppableRails
6
- # This cop looks for include Helper execution.
7
- # Including Helper, in most cases, makes:
8
- # - hard to find out some helper method is used or not.
9
- # - constant dependency more complex, which causes changing code how impact to be unpredictable.
10
- #
11
- # @example
12
- # # bad
13
- # # app/helpers/post_helper.rb
14
- # module PostHelper
15
- # def some_post_link(post)
16
- # # make some awesome link...
17
- # end
18
- # end
19
- #
20
- # # app/helpers/top_helper.rb
21
- # module TopHelper
22
- # include PostHelper
23
- #
24
- # def some_link(posts)
25
- # some_post_link(post)
26
- # end
27
- # end
28
- #
29
- # # good
30
- # # app/helpers/post_link_tag.rb
31
- # module PostLinkTag
32
- # module_function
33
- #
34
- # def some_post_link(post)
35
- # # make some awesome link...
36
- # end
37
- # end
38
- #
39
- # # app/helpers/top_helper.rb
40
- # module TopHelper
41
- # def some_link(posts)
42
- # PostLinkTag.some_post_link(post)
43
- # end
44
- # end
45
- #
46
- class DontIncludeInHelper < Base
47
- MSG = "Do not include in Helper."
48
- RESTRICT_ON_SEND = %i[include].freeze
49
-
50
- def_node_matcher :render_with_inline_option?, <<~PATTERN
51
- (send _ :include (const _ _))
52
- PATTERN
53
-
54
- def find_parent(node)
55
- parent_node = node.parent
56
- if parent_node.type == :begin
57
- parent_node.parent
58
- else
59
- parent_node
60
- end
61
- end
62
-
63
- def on_send(node)
64
- parent_node = find_parent(node)
65
- return unless parent_node.type == :module
66
-
67
- module_name = parent_node.children.first.children.last.to_s
68
- return unless module_name.end_with?("Helper")
69
-
70
- add_offense(node) if render_with_inline_option?(node)
71
- end
72
- end
73
- end
74
- end
75
- end