rubocop-elegant 0.0.1

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: a3a3c039c33e63e1f6f6060c046c611f6930788518f792b8b2207d10565466e0
4
+ data.tar.gz: 83efd07a973b2c71c4b1a33306874d0544d9717415b61861a49dc3a4c5415a2d
5
+ SHA512:
6
+ metadata.gz: 1cf1d9d1521ca0471c0a04c482049db3d1bd6f49eccbdb6effa53e1f316363879b56b95911ee11dbc31de05775f56698f6e2a01eacb9c2e01d565e829eb2829c
7
+ data.tar.gz: 003315aa360d8a7f92b6c1f401013c40f23d01d3f22be6781223d96bfc936ed31d95f70a4fe2517e8ad506880d103316182eed3e498ed14352cc7119dfc0ef14
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: Copyright (c) 2019-2026 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ source 'https://rubygems.org'
7
+ gemspec
8
+
9
+ gem 'minitest', '~>6.0', require: false
10
+ gem 'minitest-reporters', '~>1.7', require: false
11
+ gem 'rake', '~>13.2', require: false
12
+ gem 'rdoc', '7.1.0', require: false
13
+ gem 'rubocop', '~>1.74', require: false
14
+ gem 'rubocop-minitest', '~>0.38', require: false
15
+ gem 'rubocop-performance', '~>1.25', require: false
16
+ gem 'rubocop-rake', '~>0.7', require: false
17
+ gem 'simplecov', '~>0.22', require: false
18
+ gem 'simplecov-cobertura', '~>3.0', require: false
19
+ gem 'yard', '~>0.9', require: false
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019-2026 Yegor Bugayenko
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
13
+ in 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 NON-INFRINGEMENT. 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 THE
21
+ SOFTWARE.
data/LICENSES/MIT.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019-2026 Yegor Bugayenko
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
13
+ in 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 NON-INFRINGEMENT. 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # RuboCop Cop for Elegant Ruby Code
2
+
3
+ [![EO principles respected here](https://www.elegantobjects.org/badge.svg)](https://www.elegantobjects.org)
4
+ [![DevOps By Rultor.com](https://www.rultor.com/b/yegor256/rubocop-elegant)](https://www.rultor.com/p/yegor256/rubocop-elegant)
5
+ [![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
6
+
7
+ [![rake](https://github.com/yegor256/rubocop-elegant/actions/workflows/rake.yml/badge.svg)](https://github.com/yegor256/rubocop-elegant/actions/workflows/rake.yml)
8
+ [![Gem Version](https://badge.fury.io/rb/rubocop-elegant.svg)](https://badge.fury.io/rb/rubocop-elegant)
9
+ [![Yard Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://rubydoc.info/github/yegor256/rubocop-elegant/master/frames)
10
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/rubocop-elegant/blob/master/LICENSE.txt)
11
+ [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/rubocop-elegant.svg)](https://codecov.io/github/yegor256/rubocop-elegant?branch=master)
12
+ [![Hits-of-Code](https://hitsofcode.com/github/yegor256/rubocop-elegant)](https://hitsofcode.com/view/github/yegor256/rubocop-elegant)
13
+
14
+ First, install it:
15
+
16
+ ```bash
17
+ gem install rubocop-elegant
18
+ ```
19
+
20
+ Then, add it to your `.rubocop.yml`:
21
+
22
+ ```yaml
23
+ plugins:
24
+ - rubocop-elegant
25
+ ```
26
+
27
+ Should work.
28
+
29
+ ## How to contribute
30
+
31
+ Read
32
+ [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
33
+ Make sure your build is green before you contribute
34
+ your pull request. You will need to have
35
+ [Ruby](https://www.ruby-lang.org/en/) 2.3+ and
36
+ [Bundler](https://bundler.io/) installed. Then:
37
+
38
+ ```bash
39
+ bundle update
40
+ bundle exec rake
41
+ ```
42
+
43
+ If it's clean and you don't see any error messages, submit your pull request.
44
+
45
+ [rubocop-elegant]: https://www.rubydoc.info/github/yegor256/rubocop-elegant/master/rubocop-elegant
46
+ [fluent interface]: https://en.wikipedia.org/wiki/Fluent_interface
data/REUSE.toml ADDED
@@ -0,0 +1,36 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2025 Yegor Bugayenko
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ version = 1
5
+ [[annotations]]
6
+ path = [
7
+ ".DS_Store",
8
+ ".gitattributes",
9
+ ".gitignore",
10
+ ".pdd",
11
+ "**.json",
12
+ "**.md",
13
+ "**.png",
14
+ "**.svg",
15
+ "**.txt",
16
+ "**/.DS_Store",
17
+ "**/.gitignore",
18
+ "**/.pdd",
19
+ "**/*.csv",
20
+ "**/*.jpg",
21
+ "**/*.json",
22
+ "**/*.md",
23
+ "**/*.pdf",
24
+ "**/*.png",
25
+ "**/*.svg",
26
+ "**/*.txt",
27
+ "**/*.vm",
28
+ "**/CNAME",
29
+ "**/Gemfile.lock",
30
+ "Gemfile.lock",
31
+ "README.md",
32
+ "renovate.json",
33
+ ]
34
+ precedence = "override"
35
+ SPDX-FileCopyrightText = "Copyright (c) 2025 Yegor Bugayenko"
36
+ SPDX-License-Identifier = "MIT"
data/Rakefile ADDED
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: Copyright (c) 2019-2026 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ require 'rubygems'
7
+ require 'rake'
8
+ require 'rake/clean'
9
+
10
+ CLEAN.include('coverage')
11
+
12
+ def name
13
+ @name ||= File.basename(Dir['*.gemspec'].first, '.*')
14
+ end
15
+
16
+ def version
17
+ Gem::Specification.load(Dir['*.gemspec'].first).version
18
+ end
19
+
20
+ task default: %i[clean test rubocop yard]
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = false
27
+ end
28
+
29
+ require 'yard'
30
+ desc 'Build Yard documentation'
31
+ YARD::Rake::YardocTask.new do |t|
32
+ t.files = ['lib/**/*.rb']
33
+ t.options = ['--fail-on-warning']
34
+ end
35
+
36
+ require 'rubocop/rake_task'
37
+ RuboCop::RakeTask.new do |task|
38
+ task.fail_on_error = true
39
+ end
@@ -0,0 +1,10 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2019-2026 Yegor Bugayenko
2
+ # SPDX-License-Identifier: MIT
3
+ ---
4
+ Elegant:
5
+ Enabled: true
6
+ DocumentationBaseURL: https://github.com/yegor256/rubocop-elegant
7
+ Elegant/NoComments:
8
+ Description: 'Disallows comments in source code, except SPDX license comments'
9
+ Enabled: true
10
+ VersionAdded: '0.0.1'
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: Copyright (c) 2019-2026 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ module RuboCop
7
+ module Cop
8
+ module Elegant
9
+ class NoComments < Base
10
+ extend AutoCorrector
11
+
12
+ MSG = 'Comment is not allowed, unless it is SPDX, magic, or rubocop directive'
13
+
14
+ def on_new_investigation
15
+ processed_source.comments.each do |comment|
16
+ register(comment) unless allowed?(comment)
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def allowed?(comment)
23
+ spdx?(comment) || magic?(comment) || rubocop?(comment)
24
+ end
25
+
26
+ def spdx?(comment)
27
+ comment.text.match?(/^#\s*SPDX-/)
28
+ end
29
+
30
+ def magic?(comment)
31
+ comment.text.match?(/^#\s*(frozen_string_literal|encoding|coding|warn_indent):/)
32
+ end
33
+
34
+ def rubocop?(comment)
35
+ comment.text.match?(/^#\s*rubocop:(disable|enable|todo)\s/)
36
+ end
37
+
38
+ def register(comment)
39
+ add_offense(comment) do |corrector|
40
+ corrector.remove(removal_range(comment))
41
+ end
42
+ end
43
+
44
+ def removal_range(comment)
45
+ range = comment.source_range
46
+ line_start = range.source_line[0, range.column]
47
+ return range_with_line(range) if line_start.strip.empty?
48
+ range_with_prefix(range, line_start)
49
+ end
50
+
51
+ def range_with_line(range)
52
+ start_pos = range.begin_pos - range.column
53
+ end_pos = range.end_pos
54
+ end_pos += 1 if newline_after?(end_pos)
55
+ range.with(begin_pos: start_pos, end_pos: end_pos)
56
+ end
57
+
58
+ def range_with_prefix(range, prefix)
59
+ whitespace = prefix.match(/\s*$/)[0]
60
+ range.with(begin_pos: range.begin_pos - whitespace.length, end_pos: range.end_pos)
61
+ end
62
+
63
+ def newline_after?(pos)
64
+ processed_source.buffer.source[pos] == "\n"
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: Copyright (c) 2019-2026 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ require_relative 'elegant/no_comments'
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: Copyright (c) 2019-2026 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ require 'lint_roller'
7
+
8
+ module RuboCop
9
+ module Elegant
10
+ class Plugin < LintRoller::Plugin
11
+ def about
12
+ LintRoller::About.new(
13
+ name: 'rubocop-elegant',
14
+ version: VERSION,
15
+ homepage: 'https://github.com/yegor256/rubocop-elegant',
16
+ description: 'Set of custom RuboCop cops for elegant Ruby coding'
17
+ )
18
+ end
19
+
20
+ def supported?(context)
21
+ context.engine == :rubocop
22
+ end
23
+
24
+ def rules(_context)
25
+ LintRoller::Rules.new(
26
+ type: :path,
27
+ config_format: :rubocop,
28
+ value: Pathname.new(__dir__).join('../../../config/default.yml')
29
+ )
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: Copyright (c) 2019-2026 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ module RuboCop
7
+ module Elegant
8
+ VERSION = '0.0.1'
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: Copyright (c) 2019-2026 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ require 'rubocop'
7
+ require_relative 'rubocop/elegant/version'
8
+ require_relative 'rubocop/elegant/plugin'
9
+ require_relative 'rubocop/cop/elegant_cops'
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: Copyright (c) 2019-2026 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
5
+
6
+ require 'English'
7
+
8
+ Gem::Specification.new do |s|
9
+ s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
10
+ s.required_ruby_version = '>=2.2'
11
+ s.name = 'rubocop-elegant'
12
+ s.version = '0.0.1'
13
+ s.license = 'MIT'
14
+ s.summary = 'Set of custom RuboCop cops for elegant Ruby coding'
15
+ s.description =
16
+ 'Explain it here...'
17
+ s.authors = ['Yegor Bugayenko']
18
+ s.email = 'yegor256@gmail.com'
19
+ s.homepage = 'https://github.com/yegor256/rubocop-elegant'
20
+ s.files = `git ls-files | grep -v -E '^(test/|\\.|renovate)'`.split($RS)
21
+ s.rdoc_options = ['--charset=UTF-8']
22
+ s.extra_rdoc_files = ['README.md']
23
+ s.metadata['rubygems_mfa_required'] = 'true'
24
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-elegant
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yegor Bugayenko
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Explain it here...
13
+ email: yegor256@gmail.com
14
+ executables: []
15
+ extensions: []
16
+ extra_rdoc_files:
17
+ - README.md
18
+ files:
19
+ - Gemfile
20
+ - LICENSE.txt
21
+ - LICENSES/MIT.txt
22
+ - README.md
23
+ - REUSE.toml
24
+ - Rakefile
25
+ - config/default.yml
26
+ - lib/rubocop-elegant.rb
27
+ - lib/rubocop/cop/elegant/no_comments.rb
28
+ - lib/rubocop/cop/elegant_cops.rb
29
+ - lib/rubocop/elegant/plugin.rb
30
+ - lib/rubocop/elegant/version.rb
31
+ - rubocop-elegant.gemspec
32
+ homepage: https://github.com/yegor256/rubocop-elegant
33
+ licenses:
34
+ - MIT
35
+ metadata:
36
+ rubygems_mfa_required: 'true'
37
+ rdoc_options:
38
+ - "--charset=UTF-8"
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '2.2'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubygems_version: 3.6.9
53
+ specification_version: 4
54
+ summary: Set of custom RuboCop cops for elegant Ruby coding
55
+ test_files: []