rubocop-semantics 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: 30fa62f94179a0f55677ebc0b0cd6b9b891396306c9fabb7e65daf3d2fdc672d
4
+ data.tar.gz: 3c9fa227b9e108f21fe4feaa9a33d70e1826facb7b6f814f112a2ba766f7da4c
5
+ SHA512:
6
+ metadata.gz: 3e7c7a85f0165c52618f61ea6e8e40529c831b0b118c50a43a0fcd7c5ced8ff4efcd0c2b169f4b73c2102e6686237dc45e59a2bdc619864e5ce2785a1f94467d
7
+ data.tar.gz: 7bf18383844fb804ec55b9e8a5f61043c5cc83dc3c9f2f90cca09b30794872b79d7c92297b7f8b71c61c7e138b5f1b1356110ff3c97b7e388fa9795a2a9d5d70
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.idea/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+ NewCops: enable
4
+
5
+ Naming/FileName:
6
+ Exclude:
7
+ - lib/rubocop-semantics.rb
8
+
9
+ Style/StringLiterals:
10
+ Enabled: true
11
+ EnforcedStyle: double_quotes
12
+
13
+ Style/StringLiteralsInInterpolation:
14
+ Enabled: true
15
+ EnforcedStyle: double_quotes
16
+
17
+ Layout/LineLength:
18
+ Max: 120
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.5
5
+ - 2.6
6
+ - 2.7
7
+ - 3.0
8
+ - head
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # RuboCop Semantics
2
+
3
+ ## Notable changes
4
+
5
+ ### 1.0.0 (2021-08-06)
6
+
7
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in rubocop-semantics.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # RuboCop Semantics
2
+
3
+ Checks for meaningless variable names in Ruby code. An extension for [RuboCop](https://rubocop.org).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rubocop-semantics', require: false
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rubocop-semantics
20
+
21
+ ## Usage
22
+
23
+ ```yaml
24
+ # .rubocop.yml
25
+
26
+ require:
27
+ - rubocop-semantics
28
+ ```
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bin/setup` to install dependencies.
33
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
34
+
35
+ To install this gem onto your local machine, run `bundle exec rake install`.
36
+ To release a new version, update the version number in `version.rb`,
37
+ and then run `bundle exec rake release`,
38
+ which will create a git tag for the version,
39
+ push git commits and the created tag,
40
+ and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/vassilevsky/rubocop-semantics
45
+
46
+ To create a new cop in this extension, run:
47
+
48
+ bundle exec rake new_cop[Semantics/RuleName]
49
+
50
+ Please cover all logic with tests.
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rubocop/rake_task"
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: %i[spec rubocop]
9
+
10
+ require "rspec/core/rake_task"
11
+
12
+ RSpec::Core::RakeTask.new(:spec) do |spec|
13
+ spec.pattern = FileList["spec/**/*_spec.rb"]
14
+ end
15
+
16
+ desc "Generate a new cop with a template"
17
+ task :new_cop, [:cop] do |_task, args|
18
+ require "rubocop"
19
+
20
+ cop_name = args.fetch(:cop) do
21
+ warn "usage: bundle exec rake new_cop[Department/Name]"
22
+ exit!
23
+ end
24
+
25
+ github_user = `git config github.user`.chop
26
+ github_user = "your_id" if github_user.empty?
27
+
28
+ generator = RuboCop::Cop::Generator.new(cop_name, github_user)
29
+
30
+ generator.write_source
31
+ generator.write_spec
32
+ generator.inject_require(root_file_path: "lib/rubocop/cop/semantics_cops.rb")
33
+ generator.inject_config(config_file_path: "config/default.yml")
34
+
35
+ puts generator.todo
36
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "rubocop/semantics"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ Semantics/VariableName:
2
+ Description: 'Checks for meaningless variable names.'
3
+ Enabled: true
4
+ VersionAdded: '1.0.0'
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+
5
+ require_relative "rubocop/semantics"
6
+ require_relative "rubocop/semantics/version"
7
+ require_relative "rubocop/semantics/inject"
8
+
9
+ RuboCop::Semantics::Inject.defaults!
10
+
11
+ require_relative "rubocop/cop/semantics_cops"
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Semantics
6
+ # Checks for meaningless variable names.
7
+ # A good variable name describes its contents with nouns and adjectives.
8
+ #
9
+ # @example
10
+ #
11
+ # # bad
12
+ # data = {name: 'Elijah', age: 40}
13
+ #
14
+ # # good
15
+ # customer = {name: 'Elijah', age: 40}
16
+ #
17
+ class VariableName < Base
18
+ MEANINGLESS_NAMES = %i[
19
+
20
+ data
21
+ info
22
+ value
23
+
24
+ ].freeze
25
+
26
+ def on_lvasgn(node)
27
+ variable_name, = *node
28
+ return unless MEANINGLESS_NAMES.include?(variable_name)
29
+
30
+ add_offense(node.loc.name, message: "Use a more descriptive variable name.")
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "semantics/variable_name"
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "semantics/version"
4
+
5
+ module RuboCop
6
+ # Cops that check for meaningless and misleading names in code
7
+ module Semantics
8
+ class Error < StandardError; end
9
+
10
+ PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
11
+ CONFIG_DEFAULT = PROJECT_ROOT.join("config", "default.yml").freeze
12
+ CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
13
+
14
+ private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The original code is from https://github.com/rubocop-hq/rubocop-rspec/blob/master/lib/rubocop/rspec/inject.rb
4
+ # See https://github.com/rubocop-hq/rubocop-rspec/blob/master/MIT-LICENSE.md
5
+ module RuboCop
6
+ module Semantics
7
+ # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
8
+ # bit of our configuration.
9
+ module Inject
10
+ def self.defaults!
11
+ path = CONFIG_DEFAULT.to_s
12
+ hash = ConfigLoader.send(:load_yaml_configuration, path)
13
+ config = Config.new(hash, path).tap(&:make_excludes_absolute)
14
+ puts "configuration from #{path}" if ConfigLoader.debug?
15
+ config = ConfigLoader.merge_with_default(config, path)
16
+ ConfigLoader.instance_variable_set(:@default_configuration, config)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Semantics
5
+ VERSION = "1.0.0"
6
+ end
7
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/rubocop/semantics/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rubocop-semantics"
7
+ spec.version = RuboCop::Semantics::VERSION
8
+ spec.authors = ["i.vasilevskiy"]
9
+ spec.email = ["i.vasilevskiy@fun-box.ru"]
10
+
11
+ spec.summary = "Cops that check for meaningless and misleading names in code"
12
+ spec.homepage = "https://github.com/vassilevsky/rubocop-semantics"
13
+
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ spec.metadata["changelog_uri"] = "https://github.com/vassilevsky/rubocop-semantics/blob/master/CHANGELOG.md"
19
+
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
22
+ end
23
+
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_runtime_dependency "rubocop"
29
+
30
+ spec.add_development_dependency "rake"
31
+ spec.add_development_dependency "rspec"
32
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-semantics
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - i.vasilevskiy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-08-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - i.vasilevskiy@fun-box.ru
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".rubocop.yml"
65
+ - ".travis.yml"
66
+ - CHANGELOG.md
67
+ - Gemfile
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - config/default.yml
73
+ - lib/rubocop-semantics.rb
74
+ - lib/rubocop/cop/semantics/variable_name.rb
75
+ - lib/rubocop/cop/semantics_cops.rb
76
+ - lib/rubocop/semantics.rb
77
+ - lib/rubocop/semantics/inject.rb
78
+ - lib/rubocop/semantics/version.rb
79
+ - rubocop-semantics.gemspec
80
+ homepage: https://github.com/vassilevsky/rubocop-semantics
81
+ licenses: []
82
+ metadata:
83
+ homepage_uri: https://github.com/vassilevsky/rubocop-semantics
84
+ source_code_uri: https://github.com/vassilevsky/rubocop-semantics
85
+ changelog_uri: https://github.com/vassilevsky/rubocop-semantics/blob/master/CHANGELOG.md
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 2.5.0
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubygems_version: 3.1.4
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Cops that check for meaningless and misleading names in code
105
+ test_files: []