rubocop-magic_numbers 0.7.1 → 0.8.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: 63602a8a62b0911504ec48643cfa23d0b72c53b79d6003e84ef480a154ba9172
4
- data.tar.gz: 5a7a342e4dce635c700f1670346128fedc15ecfb7fb0be189eba123b890bbb5f
3
+ metadata.gz: 33ad5620bc3e0d0bcdc88a4242ed8999f2bd4299ebf82fc30a20c43fff9d1de0
4
+ data.tar.gz: 5515602e5eba421afb2c103751bb4aac2d8b1131c036a16df17f015840e0f6cf
5
5
  SHA512:
6
- metadata.gz: 45909c1e736672257304a1e579b32409138a2cfb0b90b11ca904946aff491e48063610c1123ec5b73cf0c52d20ccdf4bff118e6ff3cfe4546236749a26b73eb9
7
- data.tar.gz: 8988333f7e772d6ecc8e4a22bdd3dc72f7b93f0a3d3270ee3f1242aaee9c30d8974f3f8bb1c298af3344ead8557263aaf5a47a14d530425c76e40c2bcdcf938d
6
+ metadata.gz: 80b5d7d6d78b076f149e6f5cdbf5c146fdfa882b3ef072e2d0d8fd1c31178b9e1c8858671020b4182d9b8978c1dcbfb2528020c7d62c8775d46a9dee9107b550
7
+ data.tar.gz: 541941e49caca325bcecce5bf0d15e3bc401a9804d3c371f062d4051688391140206da1bc3c660219c107ad020281701f3e6a617483cad201de52eba1035bd0e
data/README.md CHANGED
@@ -39,7 +39,17 @@ bundle install
39
39
 
40
40
  ## Usage
41
41
 
42
- After installing the gem, `rubocop` should automatically detect and raise offenses for magic numbers within your code.
42
+ Enable the plugin in your `.rubocop.yml`:
43
+
44
+ ```yaml
45
+ plugins:
46
+ - rubocop-magic_numbers
47
+ ```
48
+
49
+ `rubocop` will then detect and raise offenses for magic numbers within your code.
50
+
51
+ > [!NOTE]
52
+ > The plugin system requires RuboCop 1.72 or later. If you previously loaded this gem with `require: rubocop-magic_numbers`, move it to `plugins:` instead. See RuboCop's [plugin documentation](https://docs.rubocop.org/rubocop/latest/plugins.html) for details.
43
53
 
44
54
  The gem will detect offenses of the following sorts:
45
55
 
@@ -115,7 +125,7 @@ You can customize the behavior of the gem by adding configurations to a `.ruboco
115
125
  Here are some examples of configurations you can use:
116
126
 
117
127
  ```yaml
118
- require:
128
+ plugins:
119
129
  - rubocop-magic_numbers
120
130
 
121
131
  MagicNumbers/NoArgument:
@@ -0,0 +1,32 @@
1
+ MagicNumbers/NoArgument:
2
+ Description: 'Detects magic numbers used as method arguments.'
3
+ Enabled: true
4
+ ForbiddenNumerics: All
5
+ IgnoredMethods:
6
+ - '[]'
7
+ CheckArrays: true
8
+ CheckRanges: true
9
+ CheckHashes: false
10
+ PermittedValues: []
11
+
12
+ MagicNumbers/NoAssignment:
13
+ Description: 'Detects magic numbers assigned to variables or properties.'
14
+ Enabled: true
15
+ ForbiddenNumerics: All
16
+ AllowedAssignments:
17
+ - class_variables
18
+ - global_variables
19
+ PermittedValues: []
20
+
21
+ MagicNumbers/NoDefault:
22
+ Description: 'Detects magic numbers used as default argument values.'
23
+ Enabled: true
24
+ ForbiddenNumerics: All
25
+
26
+ MagicNumbers/NoReturn:
27
+ Description: 'Detects magic numbers returned from methods or procs.'
28
+ Enabled: true
29
+ ForbiddenNumerics: All
30
+ AllowedReturns:
31
+ - None
32
+ PermittedReturnValues: []
@@ -1,28 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rubocop'
4
- require 'rubocop/cop/cop'
5
- # rubocop:disable Lint/SuppressedException
6
- # This is only available in newer versions of the RuboCop gem
7
- begin
8
- require 'rubocop/cop/base'
9
- rescue LoadError
10
- end
11
- # rubocop:enable Lint/SuppressedException
12
4
 
13
5
  module RuboCop
14
6
  module Cop
15
- module MagicNumbers # rubocop:disable Style/Documentation
16
- def self.best_base_class
17
- if ::RuboCop::Cop.const_defined?('Base')
18
- ::RuboCop::Cop::Base
19
- else
20
- ::RuboCop::Cop::Cop
21
- end
22
- end
23
-
7
+ module MagicNumbers
24
8
  # Base class for all shared behaviour between these cops
25
- class Base < best_base_class
9
+ class Base < ::RuboCop::Cop::Base
26
10
  CONFIG_ALL = 'All'
27
11
  CONFIG_FLOAT = 'Float'
28
12
  CONFIG_INTEGER = 'Integer'
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'lint_roller'
4
+ require 'pathname'
5
+
6
+ module RuboCop
7
+ module MagicNumbers
8
+ # Integrates rubocop-magic_numbers with RuboCop's plugin system
9
+ # (https://docs.rubocop.org/rubocop/latest/plugins.html).
10
+ class Plugin < LintRoller::Plugin
11
+ def about
12
+ LintRoller::About.new(
13
+ name: 'rubocop-magic_numbers',
14
+ version: VERSION,
15
+ homepage: 'https://github.com/meetcleo/rubocop-magic_numbers',
16
+ description: 'A RuboCop plugin for detecting the use of magic numbers.'
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module MagicNumbers
5
- VERSION = '0.7.1'
5
+ VERSION = '0.8.0'
6
6
  end
7
7
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'rubocop/magic_numbers/version'
4
+ require 'rubocop/magic_numbers/plugin'
4
5
  require 'rubocop/cop/magic_numbers/base'
5
6
  require 'rubocop/cop/magic_numbers/no_argument'
6
7
  require 'rubocop/cop/magic_numbers/no_assignment'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-magic_numbers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Morrice
@@ -10,6 +10,20 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 1980-01-02 00:00:00.000000000 Z
12
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.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: parser
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -30,14 +44,14 @@ dependencies:
30
44
  requirements:
31
45
  - - ">="
32
46
  - !ruby/object:Gem::Version
33
- version: '0'
47
+ version: 1.72.1
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - ">="
39
53
  - !ruby/object:Gem::Version
40
- version: '0'
54
+ version: 1.72.1
41
55
  description: rubocop/magic_numbers implements a rubocop cop for detecting the use
42
56
  of bare numbers when linting
43
57
  email:
@@ -48,6 +62,7 @@ extensions: []
48
62
  extra_rdoc_files: []
49
63
  files:
50
64
  - README.md
65
+ - config/default.yml
51
66
  - lib/rubocop-magic_numbers.rb
52
67
  - lib/rubocop/cop/magic_numbers/base.rb
53
68
  - lib/rubocop/cop/magic_numbers/no_argument.rb
@@ -55,12 +70,14 @@ files:
55
70
  - lib/rubocop/cop/magic_numbers/no_default.rb
56
71
  - lib/rubocop/cop/magic_numbers/no_return.rb
57
72
  - lib/rubocop/magic_numbers.rb
73
+ - lib/rubocop/magic_numbers/plugin.rb
58
74
  - lib/rubocop/magic_numbers/version.rb
59
75
  homepage: https://github.com/Bodacious/rubocop-magic_numbers
60
76
  licenses:
61
77
  - MIT
62
78
  metadata:
63
79
  rubygems_mfa_required: 'true'
80
+ default_lint_roller_plugin: RuboCop::MagicNumbers::Plugin
64
81
  rdoc_options: []
65
82
  require_paths:
66
83
  - lib