standard-custom 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: 56e0ad2fc723b5eee60721c0055e0018cca4f821c2bc221d948af237477e37ff
4
+ data.tar.gz: bf33319f64c41836cf4f180e2be5813ee5204aaa534a4b5a1a17253771b0e2f1
5
+ SHA512:
6
+ metadata.gz: 176c874493500639accf836bb8f67f739e924e34160607c3c180f25c02dcbcca9303ed40b35d0c5abfe35c0d344b79c338819cfafc3aedee4db74e7d62da49e4
7
+ data.tar.gz: ede82211fde07bf36596c24b18e0d5e30958345f2664853586c8d5a29b21cc90ee5a90acbc10e28081151fc2634fd6827df480b039e44586212f1dd8ae43050f
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ruby_version: 2.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [1.0.0]
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+ gem "rake"
5
+ gem "minitest"
6
+ gem "standard"
7
+ gem "m"
8
+
9
+ group :test do
10
+ gem "rubocop", "~> 1.48.1"
11
+ end
12
+
13
+ gem "lint_roller", path: "../lint_roller"
data/Gemfile.lock ADDED
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: ../lint_roller
3
+ specs:
4
+ lint_roller (1.0.0)
5
+
6
+ PATH
7
+ remote: .
8
+ specs:
9
+ standard-custom (1.0.0)
10
+ lint_roller (~> 1.0)
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ ast (2.4.2)
16
+ json (2.6.3)
17
+ language_server-protocol (3.17.0.3)
18
+ m (1.6.1)
19
+ method_source (>= 0.6.7)
20
+ rake (>= 0.9.2.2)
21
+ method_source (1.0.0)
22
+ minitest (5.18.0)
23
+ parallel (1.22.1)
24
+ parser (3.2.2.0)
25
+ ast (~> 2.4.1)
26
+ rainbow (3.1.1)
27
+ rake (13.0.6)
28
+ regexp_parser (2.7.0)
29
+ rexml (3.2.5)
30
+ rubocop (1.48.1)
31
+ json (~> 2.3)
32
+ parallel (~> 1.10)
33
+ parser (>= 3.2.0.0)
34
+ rainbow (>= 2.2.2, < 4.0)
35
+ regexp_parser (>= 1.8, < 3.0)
36
+ rexml (>= 3.2.5, < 4.0)
37
+ rubocop-ast (>= 1.26.0, < 2.0)
38
+ ruby-progressbar (~> 1.7)
39
+ unicode-display_width (>= 2.4.0, < 3.0)
40
+ rubocop-ast (1.28.0)
41
+ parser (>= 3.2.1.0)
42
+ rubocop-performance (1.16.0)
43
+ rubocop (>= 1.7.0, < 2.0)
44
+ rubocop-ast (>= 0.4.0)
45
+ ruby-progressbar (1.13.0)
46
+ standard (1.26.0)
47
+ language_server-protocol (~> 3.17.0.2)
48
+ rubocop (~> 1.48.1)
49
+ rubocop-performance (~> 1.16.0)
50
+ unicode-display_width (2.4.2)
51
+
52
+ PLATFORMS
53
+ arm64-darwin-22
54
+
55
+ DEPENDENCIES
56
+ lint_roller!
57
+ m
58
+ minitest
59
+ rake
60
+ rubocop (~> 1.48.1)
61
+ standard
62
+ standard-custom!
63
+
64
+ BUNDLED WITH
65
+ 2.4.10
data/LICENSE.txt ADDED
@@ -0,0 +1,25 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Test Double, Inc.
4
+
5
+ Portions of these files Copyright (c) 2012-18 Bozhidar Batsov:
6
+ - lib/standard/cop/block_single_line_braces.rb
7
+ - test/cop_invoker.rb
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in
17
+ all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # standard-custom
2
+
3
+ This gem provides a [lint_roller](https://github.com/standardrb/lint_roller)
4
+ plugin configuration for the
5
+ [rubocop-custom](https://github.com/rubocop/rubocop-custom) ruleset.
6
+ It, along with
7
+ [standard-performance](https://github.com/standardrb/standard-performance), is
8
+ configured by default by the [Standard Ruby
9
+ gem](https://github.com/standardrb/standard)
10
+
11
+ In general, if you're using Standard, you won't need to install or configure
12
+ this gem manually, so there's not much to cover in this README!
13
+
14
+ ## Code of Conduct
15
+
16
+ This project follows Test Double's [code of
17
+ conduct](https://testdouble.com/code-of-conduct) for all community interactions,
18
+ including (but not limited to) one-on-one communications, public posts/comments,
19
+ code reviews, pull requests, and GitHub issues. If violations occur, Test Double
20
+ will take any action they deem appropriate for the infraction, up to and
21
+ including blocking a user from the organization's repositories.
22
+
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ require "standard/rake"
11
+
12
+ task default: %i[test standard:fix]
data/config/base.yml ADDED
@@ -0,0 +1,2 @@
1
+ Standard/BlockSingleLineBraces:
2
+ Enabled: true
@@ -0,0 +1,4 @@
1
+ inherit_from: ./base.yml
2
+
3
+ Custom/ConcurrentMonotonicTime:
4
+ Enabled: false
@@ -0,0 +1,96 @@
1
+ # Check for uses of braces around single line blocks, but allows either
2
+ # braces or do/end for multi-line blocks.
3
+ #
4
+ # @example
5
+ # # bad - single line block
6
+ # items.each do |item| item / 5 end
7
+ #
8
+ # # good - single line block
9
+ # items.each { |item| item / 5 }
10
+ #
11
+ module RuboCop::Cop
12
+ module Standard
13
+ class BlockSingleLineBraces < RuboCop::Cop::Base
14
+ extend RuboCop::Cop::AutoCorrector
15
+
16
+ def on_send(node)
17
+ return unless node.arguments?
18
+ return if node.parenthesized?
19
+ return if node.operator_method? || node.assignment_method?
20
+
21
+ node.arguments.each do |arg|
22
+ get_blocks(arg) do |block|
23
+ # If there are no parentheses around the arguments, then braces
24
+ # and do-end have different meaning due to how they bind, so we
25
+ # allow either.
26
+ ignore_node(block)
27
+ end
28
+ end
29
+ end
30
+
31
+ def on_block(node)
32
+ return if ignored_node?(node)
33
+ return if proper_block_style?(node)
34
+
35
+ message = message(node)
36
+ add_offense(node.loc.begin, message: message) do |corrector|
37
+ autocorrect(corrector, node)
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def get_blocks(node, &block)
44
+ case node.type
45
+ when :block
46
+ yield node
47
+ when :send
48
+ get_blocks(node.receiver, &block) if node.receiver
49
+ when :hash
50
+ # A hash which is passed as method argument may have no braces
51
+ # In that case, one of the K/V pairs could contain a block node
52
+ # which could change in meaning if do...end replaced {...}
53
+ return if node.braces?
54
+
55
+ node.each_child_node { |child| get_blocks(child, &block) }
56
+ when :pair
57
+ node.each_child_node { |child| get_blocks(child, &block) }
58
+ end
59
+ end
60
+
61
+ def proper_block_style?(node)
62
+ node.multiline? || node.braces?
63
+ end
64
+
65
+ def message(node)
66
+ "Prefer `{...}` over `do...end` for single-line blocks."
67
+ end
68
+
69
+ def autocorrect(corrector, node)
70
+ return if correction_would_break_code?(node)
71
+
72
+ replace_do_end_with_braces(corrector, node.loc)
73
+ end
74
+
75
+ def correction_would_break_code?(node)
76
+ return unless node.keywords?
77
+
78
+ node.send_node.arguments? && !node.send_node.parenthesized?
79
+ end
80
+
81
+ def replace_do_end_with_braces(corrector, loc)
82
+ b = loc.begin
83
+ e = loc.end
84
+
85
+ corrector.insert_after(b, " ") unless whitespace_after?(b, 2)
86
+
87
+ corrector.replace(b, "{")
88
+ corrector.replace(e, "}")
89
+ end
90
+
91
+ def whitespace_after?(range, length = 1)
92
+ /\s/.match?(range.source_buffer.source[range.begin_pos + length, 1])
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,30 @@
1
+ module Standard::Custom
2
+ class Plugin < LintRoller::Plugin
3
+ def initialize(config)
4
+ @config = config
5
+ end
6
+
7
+ def about
8
+ LintRoller::About.new(
9
+ name: "standard-custom",
10
+ version: VERSION,
11
+ homepage: "https://github.com/testdouble/standard-custom",
12
+ description: "Custom rules defined by the Standard Ruby project as part of the default ruleset"
13
+ )
14
+ end
15
+
16
+ def supported?(context)
17
+ true
18
+ end
19
+
20
+ def rules(context)
21
+ require_relative "../cop/block_single_line_braces"
22
+
23
+ LintRoller::Rules.new(
24
+ type: :path,
25
+ config_format: :rubocop,
26
+ value: Pathname.new(__dir__).join("../../../config/base.yml")
27
+ )
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ module Standard
2
+ module Custom
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ require "lint_roller"
2
+
3
+ require_relative "custom/version"
4
+ require_relative "custom/plugin"
5
+
6
+ module Standard
7
+ module Custom
8
+ end
9
+ end
@@ -0,0 +1 @@
1
+ require_relative "standard/custom"
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: standard-custom
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Justin Searls
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-04-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lint_roller
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ description:
28
+ email:
29
+ - searls@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".standard.yml"
35
+ - CHANGELOG.md
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - LICENSE.txt
39
+ - README.md
40
+ - Rakefile
41
+ - config/base.yml
42
+ - config/ruby-2.2.yml
43
+ - lib/standard-custom.rb
44
+ - lib/standard/cop/block_single_line_braces.rb
45
+ - lib/standard/custom.rb
46
+ - lib/standard/custom/plugin.rb
47
+ - lib/standard/custom/version.rb
48
+ homepage: https://github.com/standardrb/standard-custom
49
+ licenses:
50
+ - MIT
51
+ metadata:
52
+ homepage_uri: https://github.com/standardrb/standard-custom
53
+ source_code_uri: https://github.com/standardrb/standard-custom
54
+ changelog_uri: https://github.com/standardrb/standard-custom/blob/main/CHANGELOG.md
55
+ default_lint_roller_plugin: Standard::Custom::Plugin
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 2.6.0
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubygems_version: 3.4.10
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Plugin containing implementations of custom cops that are bundled as defaults
75
+ in Standard Ruby
76
+ test_files: []