rubocop-i18n 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 900bad082ace7d17bf13e8a01691f33c021fb683f5bf4963b1a4f217d98720c8
4
- data.tar.gz: df4f70a869ae98441bb1d98b8b9365a8a06368ffeb6b63c16138291ff241fb32
3
+ metadata.gz: a8757409734d4423d1eadc150b14ab3ea6d9ba9a0063dc9dd47de719e22ba5f3
4
+ data.tar.gz: 52a3962588122fbc261b91ab8a55b038640f169349d93e7f8ccf8e44dd4ec5ab
5
5
  SHA512:
6
- metadata.gz: 666a5de6a09a035d64937dcdf1441faaef249ebc6df44572f37d858ffdf00f2509abc56581900fb839d857e2e4da2c7a9e71f0d20476ab67c8d83022670052b7
7
- data.tar.gz: 9c5cc9f02c4408c8f3a2667125b65bb1a6385bf7d885b38787521961646240d4684d81988592298009ec54660f3533f8722b8c1118809528f2d6641f0ac808b2
6
+ metadata.gz: aeb2ba4d3bd6cc24d9f88ad0c74e910d0a2b6ab20328d890538f6b60451b0c6e1c92641726b925a6720beddff082e766cbd7a6d30881ad1078d2004b6b077346
7
+ data.tar.gz: a61d551a0ee9bb628c10b3e57b2ab8efffb84dcae53939203b9257fb6a92e4c1470df0348654382bbf788b238461ff7ff8f437108cb568644db5dc333af3ad71
@@ -0,0 +1,21 @@
1
+ name: Test
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ rubocop:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ matrix:
10
+ ruby: [ '2.7.7' ]
11
+ steps:
12
+ - uses: actions/checkout@master
13
+ - name: Set up Ruby
14
+ uses: ruby/setup-ruby@v1
15
+ with:
16
+ ruby-version: ${{ matrix.ruby }}
17
+ bundler-cache: true
18
+ - name: Run rake default task
19
+ run: |
20
+ bundle install --jobs=3 --retry=3
21
+ bundle exec rake
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml CHANGED
@@ -1,9 +1,17 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
  require:
3
3
  - rubocop/cop/internal_affairs
4
+ - rubocop-rake
5
+ - rubocop-rspec
6
+ - rubocop-performance
4
7
 
5
8
  AllCops:
6
9
  TargetRubyVersion: 2.5
10
+ NewCops: enable
11
+
12
+ # rubocop-i18n does not have config/default.
13
+ InternalAffairs/UndefinedConfig:
14
+ Enabled: false
7
15
 
8
16
  Metrics/BlockLength:
9
17
  Exclude:
data/.rubocop_todo.yml CHANGED
@@ -1,28 +1,21 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2020-10-25 09:49:30 UTC using RuboCop version 1.0.0.
3
+ # on 2025-01-15 21:44:52 UTC using RuboCop version 1.70.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
9
  # Offense count: 1
10
- # Configuration parameters: Include.
11
- # Include: **/*.gemspec
12
- Gemspec/RequiredRubyVersion:
13
- Exclude:
14
- - 'rubocop-i18n.gemspec'
15
-
16
- # Offense count: 1
17
- # Cop supports --auto-correct.
10
+ # This cop supports unsafe autocorrection (--autocorrect-all).
18
11
  Lint/InterpolationCheck:
19
12
  Exclude:
20
- - 'spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb'
13
+ - 'spec/rubocop/cop/i18n/get_text/decorate_string_spec.rb'
21
14
 
22
- # Offense count: 2
23
- # Configuration parameters: IgnoredMethods.
15
+ # Offense count: 3
16
+ # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
24
17
  Metrics/AbcSize:
25
- Max: 29
18
+ Max: 24
26
19
 
27
20
  # Offense count: 1
28
21
  # Configuration parameters: CountComments, CountAsOne.
@@ -30,23 +23,49 @@ Metrics/ClassLength:
30
23
  Max: 108
31
24
 
32
25
  # Offense count: 5
33
- # Configuration parameters: IgnoredMethods.
26
+ # Configuration parameters: AllowedMethods, AllowedPatterns.
34
27
  Metrics/CyclomaticComplexity:
35
28
  Max: 8
36
29
 
37
30
  # Offense count: 7
38
- # Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
31
+ # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
39
32
  Metrics/MethodLength:
40
33
  Max: 25
41
34
 
42
35
  # Offense count: 1
43
- # Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, Regex, IgnoreExecutableScripts, AllowedAcronyms.
36
+ # Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
37
+ # CheckDefinitionPathHierarchyRoots: lib, spec, test, src
44
38
  # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
45
39
  Naming/FileName:
46
40
  Exclude:
41
+ - 'Rakefile.rb'
47
42
  - 'lib/rubocop-i18n.rb'
48
43
 
44
+ # Offense count: 47
45
+ # Configuration parameters: Prefixes, AllowedPatterns.
46
+ # Prefixes: when, with, without
47
+ RSpec/ContextWording:
48
+ Exclude:
49
+ - 'spec/rubocop/cop/i18n/get_text/decorate_function_message_spec.rb'
50
+ - 'spec/rubocop/cop/i18n/get_text/decorate_string_formatting_using_interpolation_spec.rb'
51
+ - 'spec/rubocop/cop/i18n/get_text/decorate_string_formatting_using_percent_spec.rb'
52
+ - 'spec/rubocop/cop/i18n/get_text/decorate_string_spec.rb'
53
+ - 'spec/rubocop/cop/i18n/rails_i18n/decorate_string_formatting_using_interpolation_spec.rb'
54
+ - 'spec/rubocop/cop/i18n/rails_i18n/decorate_string_spec.rb'
55
+
56
+ # Offense count: 7
57
+ # Configuration parameters: AssignmentOnly.
58
+ RSpec/InstanceVariable:
59
+ Exclude:
60
+ - 'spec/rubocop/cop/i18n/get_text/decorate_function_message_spec.rb'
61
+ - 'spec/shared_examples.rb'
62
+
63
+ # Offense count: 2
64
+ RSpec/MultipleExpectations:
65
+ Max: 3
66
+
49
67
  # Offense count: 2
68
+ # Configuration parameters: AllowedConstants.
50
69
  Style/Documentation:
51
70
  Exclude:
52
71
  - 'spec/**/*'
@@ -55,26 +74,29 @@ Style/Documentation:
55
74
  - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb'
56
75
 
57
76
  # Offense count: 12
58
- # Configuration parameters: MaxUnannotatedPlaceholdersAllowed.
77
+ # This cop supports safe autocorrection (--autocorrect).
78
+ # Configuration parameters: MaxUnannotatedPlaceholdersAllowed, AllowedMethods, AllowedPatterns.
59
79
  # SupportedStyles: annotated, template, unannotated
60
80
  Style/FormatStringToken:
61
81
  EnforcedStyle: template
62
82
 
63
83
  # Offense count: 2
64
- # Configuration parameters: MinBodyLength.
84
+ # This cop supports safe autocorrection (--autocorrect).
85
+ # Configuration parameters: MinBodyLength, AllowConsecutiveConditionals.
65
86
  Style/GuardClause:
66
87
  Exclude:
67
88
  - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb'
68
89
  - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb'
69
90
 
70
91
  # Offense count: 6
71
- # Cop supports --auto-correct.
92
+ # This cop supports safe autocorrection (--autocorrect).
72
93
  Style/IfUnlessModifier:
73
94
  Exclude:
74
95
  - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb'
75
96
  - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb'
76
97
 
77
98
  # Offense count: 5
99
+ # This cop supports safe autocorrection (--autocorrect).
78
100
  # Configuration parameters: AllowModifier.
79
101
  Style/SoleNestedConditional:
80
102
  Exclude:
@@ -83,9 +105,9 @@ Style/SoleNestedConditional:
83
105
  - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb'
84
106
  - 'lib/rubocop/cop/i18n/rails_i18n/decorate_string.rb'
85
107
 
86
- # Offense count: 50
87
- # Cop supports --auto-correct.
88
- # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
108
+ # Offense count: 47
109
+ # This cop supports safe autocorrection (--autocorrect).
110
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
89
111
  # URISchemes: http, https
90
112
  Layout/LineLength:
91
113
  Max: 174
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.2
1
+ 3.4.1
data/CHANGELOG.md CHANGED
@@ -1,14 +1,20 @@
1
1
  # Change Log
2
2
 
3
- ### [master (Unreleased)](https://github.com/puppetlabs/rubocop-i18n/compare/v3.0.0...master)
4
- ### [3.0.0](https://github.com/puppetlabs/rubocop-i18n/compare/v2.0.2...v3.0.0)
3
+ ### [master (Unreleased)](https://github.com/rubocop/rubocop-i18n/compare/v3.1.0...master)
4
+
5
+ ### [3.1.0](https://github.com/rubocop/rubocop-i18n/compare/v3.0.0...v3.1.0)
6
+
7
+ * Transfer ownership of rubocop-i18n from puppetlabs org to rubocop org (#62)
8
+ * Suppress RuboCop warnings (#59)
9
+
10
+ ### [3.0.0](https://github.com/rubocop/rubocop-i18n/compare/v2.0.2...v3.0.0)
5
11
 
6
12
  * Update Rubocop version to 1.0! Thank you @mvz!
7
13
  * Cop namespace fixes, documentation updates, loading issues. Thank you again @mvz !
8
14
  * Gem maintainership has been passed to @highb. Thank you @binford2k and @lucywyman!
9
15
  * Update Ruby versions in gemspec, Travis, .ruby-version. Thank you @sfeuga!
10
16
 
11
- ### [2.0.2](https://github.com/puppetlabs/rubocop-i18n/compare/v2.0.1...v2.0.2)
17
+ ### [2.0.2](https://github.com/rubocop/rubocop-i18n/compare/v2.0.1...v2.0.2)
12
18
 
13
19
  * Add auto-correct for `DecorateString` (#40) Thanks @mvz!
14
20
  * Update rake and bundler requirements to be more permissive of newer versions (#43)
data/CODE_OF_CONDUCT.md CHANGED
@@ -1,74 +1,14 @@
1
- # Contributor Covenant Code of Conduct
1
+ # The RuboCop Community Code of Conduct
2
2
 
3
- ## Our Pledge
3
+ **Note:** We have picked the following code of conduct based on [Ruby's own code of conduct](https://www.ruby-lang.org/en/conduct/).
4
4
 
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
5
+ This document provides a few simple community guidelines for a safe, respectful,
6
+ productive, and collaborative place for any person who is willing to contribute
7
+ to the RuboCop community. It applies to all "collaborative spaces", which are
8
+ defined as community communications channels (such as mailing lists, submitted
9
+ patches, commit comments, etc.).
11
10
 
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at brandon.high@puppet.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
11
+ * Participants will be tolerant of opposing views.
12
+ * Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
13
+ * When interpreting the words and actions of others, participants should always assume good intentions.
14
+ * Behavior which can be reasonably considered harassment will not be tolerated.
data/Gemfile CHANGED
@@ -4,3 +4,12 @@ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in rubocop-i18n.gemspec
6
6
  gemspec
7
+
8
+ gem 'bundler', '>= 1.17.3'
9
+ gem 'pry', '~> 0.13.1'
10
+ gem 'rake', '>= 12.3.3'
11
+ gem 'rb-readline', '~> 0.5.5'
12
+ gem 'rspec', '~> 3.0'
13
+ gem 'rubocop-performance'
14
+ gem 'rubocop-rake'
15
+ gem 'rubocop-rspec'
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Rubocop::I18n
2
2
 
3
- [![Build Status](https://travis-ci.org/puppetlabs/rubocop-i18n.svg?branch=master)](https://travis-ci.org/puppetlabs/rubocop-i18n)
3
+ [![Build Status](https://travis-ci.com/puppetlabs/rubocop-i18n.svg?branch=master)](https://travis-ci.com/puppetlabs/rubocop-i18n)
4
4
 
5
5
  A set of cops for detecting strings that need i18n decoration in your project.
6
6
 
@@ -62,7 +62,7 @@ I18n/RailsI18n/DecorateString:
62
62
 
63
63
  ### I18n/GetText/DecorateString
64
64
 
65
- This cop is looks for strings that appear to be sentences but are not decorated.
65
+ This cop is looks for strings that appear to be sentences but are not decorated.
66
66
  Sentences are determined by the STRING_REGEXP.
67
67
 
68
68
  ##### Error message thrown
@@ -203,7 +203,7 @@ raise(someOtherFuntioncall(foo, "bar"))
203
203
 
204
204
  ##### Good
205
205
 
206
- In this raise or fail function, the message does not contain any decoration at all and the message is not a simple string. It may make sense to convert the message to a simple string. eg [Simple decoration of a message](#Simple-decoration-of-a-message).
206
+ In this raise or fail function, the message does not contain any decoration at all and the message is not a simple string. It may make sense to convert the message to a simple string. eg [Simple decoration of a message](#Simple-decoration-of-a-message).
207
207
  Or ignore this raise or fail function following this [How to ignore rules in code](#How-to-ignore-rules-in-code) section.
208
208
 
209
209
  ### I18n/GetText/DecorateStringFormattingUsingInterpolation
@@ -331,5 +331,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
331
331
 
332
332
  ## Contributing
333
333
 
334
- Bug reports and pull requests are welcome on GitHub at https://github.com/puppetlabs/rubocop-i18n. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
335
-
334
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rubocop/rubocop-i18n. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [The RuboCop Community Code of Conduct](CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -9,6 +9,7 @@ task default: :test
9
9
 
10
10
  task test: %i[rubocop spec]
11
11
 
12
+ desc 'Run RuboCop'
12
13
  task :rubocop do
13
14
  sh 'rubocop -P'
14
15
  end
@@ -0,0 +1,25 @@
1
+ ---
2
+ I18n:
3
+ Enabled: true
4
+
5
+ I18n/GetText:
6
+ Enabled: false
7
+
8
+ I18n/GetText/DecorateString:
9
+ Enabled: true
10
+ AutoCorrect: false
11
+
12
+ I18n/GetText/DecorateFunctionMessage:
13
+ Enabled: true
14
+
15
+ I18n/GetText/DecorateStringFormattingUsingInterpolation:
16
+ Enabled: true
17
+
18
+ I18n/GetText/DecorateStringFormattingUsingPercent:
19
+ Enabled: true
20
+
21
+ I18n/RailsI18n:
22
+ Enabled: false
23
+
24
+ I18n/RailsI18n/DecorateString:
25
+ Enabled: true
@@ -4,7 +4,9 @@ module RuboCop
4
4
  module Cop
5
5
  module I18n
6
6
  module GetText
7
- class DecorateFunctionMessage < Cop
7
+ class DecorateFunctionMessage < Base
8
+ extend AutoCorrector
9
+
8
10
  def on_send(node)
9
11
  method_name = node.loc.selector.source
10
12
  return unless GetText.supported_method?(method_name)
@@ -22,14 +24,6 @@ module RuboCop
22
24
  end
23
25
  end
24
26
 
25
- def autocorrect(node)
26
- if node.str_type?
27
- single_string_correct(node)
28
- elsif interpolation_offense?(node)
29
- # interpolation_correct(node)
30
- end
31
- end
32
-
33
27
  private
34
28
 
35
29
  def already_decorated?(node, parent = nil)
@@ -65,7 +59,17 @@ module RuboCop
65
59
  error_message << 'message should be decorated. ' if error == :no_decoration
66
60
  end
67
61
  error_message = error_message.join('\n')
68
- add_offense(message_section, message: error_message)
62
+ add_offense(message_section, message: error_message) do |corrector|
63
+ autocorrect(corrector, message_section)
64
+ end
65
+ end
66
+
67
+ def autocorrect(corrector, node)
68
+ if node.str_type?
69
+ single_string_correct(corrector, node)
70
+ elsif interpolation_offense?(node)
71
+ # interpolation_correct(node)
72
+ end
69
73
  end
70
74
 
71
75
  def how_bad_is_it(message_section)
@@ -106,11 +110,8 @@ module RuboCop
106
110
  node.children.any? { |child| interpolation_offense?(child, parent) }
107
111
  end
108
112
 
109
- def single_string_correct(node)
110
- lambda { |corrector|
111
- corrector.insert_before(node.source_range, '_(')
112
- corrector.insert_after(node.source_range, ')')
113
- }
113
+ def single_string_correct(corrector, node)
114
+ corrector.wrap(node.source_range, '_(', ')')
114
115
  end
115
116
 
116
117
  def interpolation_correct(node)
@@ -136,16 +137,16 @@ module RuboCop
136
137
  if interpolated_values_string.empty?
137
138
  interpolated_values_string << '{ '
138
139
  end
139
- interpolated_values_string << "#{hash_key}: #{value.loc.expression.source}, "
140
+ interpolated_values_string << "#{hash_key}: #{value.source}, "
140
141
 
141
142
  # Replace interpolation with format string
142
- corrector.replace(child.loc.expression, "%{#{hash_key}}")
143
+ corrector.replace(child, "%{#{hash_key}}")
143
144
  end
144
145
  unless interpolated_values_string.empty?
145
146
  interpolated_values_string << '}'
146
147
  end
147
- corrector.insert_before(node.source_range, '_(')
148
- corrector.insert_after(node.source_range, ") % #{interpolated_values_string}")
148
+ corrector.insert_before(node, '_(')
149
+ corrector.insert_after(node, ") % #{interpolated_values_string}")
149
150
  }
150
151
  end
151
152
  end
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module I18n
6
6
  module GetText
7
- # This cop is looks for strings that appear to be sentences but are not decorated.
7
+ # Looks for strings that appear to be sentences but are not decorated.
8
8
  # Sentences are determined by the STRING_REGEXP. (Upper case character, at least one space,
9
9
  # and sentence punctuation at the end)
10
10
  #
@@ -19,7 +19,9 @@ module RuboCop
19
19
  # # good
20
20
  #
21
21
  # _("Result is good.")
22
- class DecorateString < Cop
22
+ class DecorateString < Base
23
+ extend AutoCorrector
24
+
23
25
  STRING_REGEXP = /^\s*[[:upper:]][[:alpha:]]*[[:blank:]]+.*[.!?]$/.freeze
24
26
 
25
27
  def on_dstr(node)
@@ -37,10 +39,6 @@ module RuboCop
37
39
  check_for_parent_decorator(node)
38
40
  end
39
41
 
40
- def autocorrect(node)
41
- single_string_correct(node) if node.str_type?
42
- end
43
-
44
42
  private
45
43
 
46
44
  def sentence?(node)
@@ -70,14 +68,13 @@ module RuboCop
70
68
  elsif parent.respond_to?(:method_name) && parent.method?(:[])
71
69
  return
72
70
  end
73
- add_offense(node, message: 'decorator is missing around sentence')
71
+ add_offense(node, message: 'decorator is missing around sentence') do |corrector|
72
+ single_string_correct(corrector, node) if node.str_type?
73
+ end
74
74
  end
75
75
 
76
- def single_string_correct(node)
77
- lambda { |corrector|
78
- corrector.insert_before(node.source_range, '_(')
79
- corrector.insert_after(node.source_range, ')')
80
- }
76
+ def single_string_correct(corrector, node)
77
+ corrector.wrap(node.source_range, '_(', ')')
81
78
  end
82
79
  end
83
80
  end
@@ -22,7 +22,7 @@ module RuboCop
22
22
  #
23
23
  # _("result is %{detail}" % {detail: message})
24
24
  #
25
- class DecorateStringFormattingUsingInterpolation < Cop
25
+ class DecorateStringFormattingUsingInterpolation < Base
26
26
  def on_send(node)
27
27
  decorator_name = node.loc.selector.source
28
28
  return unless GetText.supported_decorator?(decorator_name)
@@ -23,7 +23,7 @@ module RuboCop
23
23
  #
24
24
  # _("result is %{detail}" % {detail: message})
25
25
  #
26
- class DecorateStringFormattingUsingPercent < Cop
26
+ class DecorateStringFormattingUsingPercent < Base
27
27
  SUPPORTED_FORMATS = %w[b B d i o u x X e E f g G a A c p s].freeze
28
28
 
29
29
  def on_send(node)
@@ -4,7 +4,7 @@ module RuboCop
4
4
  module Cop
5
5
  module I18n
6
6
  module RailsI18n
7
- # This cop is looks for strings that appear to be sentences but are not decorated.
7
+ # Looks for strings that appear to be sentences but are not decorated.
8
8
  # Sentences are determined by the SENTENCE_REGEXP. (Upper case character, at least one space,
9
9
  # and sentence punctuation at the end)
10
10
  #
@@ -70,7 +70,7 @@ module RuboCop
70
70
  # "Any other string is fine now"
71
71
  # t("only_this_text")
72
72
  #
73
- class DecorateString < Cop
73
+ class DecorateString < Base
74
74
  SENTENCE_REGEXP = /^\s*[[:upper:]][[:alpha:]]*[[:blank:]]+.*[.!?]$/.freeze
75
75
  FRAGMENTED_SENTENCE_REGEXP = /^\s*([[:upper:]][[:alpha:]]*[[:blank:]]+.*)|([[:alpha:]]*[[:blank:]]+.*[.!?])$/.freeze
76
76
  FRAGMENT_REGEXP = /^\s*[[:alpha:]]*[[:blank:]]+.*$/.freeze
@@ -122,7 +122,7 @@ module RuboCop
122
122
  when 'sentence' then SENTENCE_REGEXP
123
123
  when 'fragmented_sentence' then FRAGMENTED_SENTENCE_REGEXP
124
124
  when 'fragment' then FRAGMENT_REGEXP
125
- else
125
+ else # rubocop:disable Lint/DuplicateBranch
126
126
  SENTENCE_REGEXP
127
127
  end
128
128
  end
@@ -20,7 +20,7 @@ module RuboCop
20
20
  #
21
21
  # t("status.accepted")
22
22
  #
23
- class DecorateStringFormattingUsingInterpolation < Cop
23
+ class DecorateStringFormattingUsingInterpolation < Base
24
24
  def on_send(node)
25
25
  return unless node&.loc&.selector
26
26
 
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'i18n/gettext'
4
+ require_relative 'i18n/gettext/decorate_string'
5
+ require_relative 'i18n/gettext/decorate_function_message'
6
+ require_relative 'i18n/gettext/decorate_string_formatting_using_interpolation'
7
+ require_relative 'i18n/gettext/decorate_string_formatting_using_percent'
8
+
9
+ require_relative 'i18n/rails_i18n'
10
+ require_relative 'i18n/rails_i18n/decorate_string'
11
+ require_relative 'i18n/rails_i18n/decorate_string_formatting_using_interpolation'
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module I18n
5
+ # Because RuboCop doesn't yet support plugins, we have to monkey patch in a
6
+ # bit of our configuration.
7
+ module Inject
8
+ def self.defaults!
9
+ path = CONFIG_DEFAULT.to_s
10
+ hash = ConfigLoader.send(:load_yaml_configuration, path)
11
+ config = RuboCop::Config.new(hash, path)
12
+ puts "configuration from #{path}" if ConfigLoader.debug?
13
+ config = ConfigLoader.merge_with_default(config, path)
14
+ ConfigLoader.instance_variable_set(:@default_configuration, config)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ # RuboCop I18n project namespace
5
+ module I18n
6
+ PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
7
+ CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
8
+
9
+ private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
10
+ end
11
+ end
data/lib/rubocop-i18n.rb CHANGED
@@ -1,3 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rubocop/cop/i18n'
3
+ require 'rubocop'
4
+
5
+ require_relative 'rubocop/i18n'
6
+ require_relative 'rubocop/i18n/inject'
7
+
8
+ RuboCop::I18n::Inject.defaults!
9
+
10
+ require_relative 'rubocop/cop/i18n_cops'
data/rubocop-i18n.gemspec CHANGED
@@ -5,13 +5,12 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'rubocop-i18n'
8
- spec.version = '3.0.0'
8
+ spec.version = '3.1.0'
9
9
  spec.authors = ['Puppet', 'Brandon High', 'TP Honey', 'Helen Campbell']
10
- spec.email = ['team-modules@puppet.com', 'brandon.high@puppet.com', 'tp@puppet.com', 'helen@puppet.com']
11
10
 
12
11
  spec.summary = 'RuboCop rules for i18n'
13
12
  spec.description = 'RuboCop rules for detecting and autocorrecting undecorated strings for i18n (gettext and rails-i18n)'
14
- spec.homepage = 'https://github.com/puppetlabs/rubocop-i18n'
13
+ spec.homepage = 'https://github.com/rubocop/rubocop-i18n'
15
14
  spec.license = 'Apache-2.0'
16
15
 
17
16
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
@@ -23,10 +22,9 @@ Gem::Specification.new do |spec|
23
22
 
24
23
  spec.required_ruby_version = '>= 2.5.8'
25
24
 
26
- spec.add_development_dependency 'bundler', '>= 1.17.3'
27
- spec.add_development_dependency 'pry', '~> 0.13.1'
28
- spec.add_development_dependency 'rake', '>= 12.3.3'
29
- spec.add_development_dependency 'rb-readline', '~> 0.5.5'
30
- spec.add_development_dependency 'rspec', '~> 3.0'
31
- spec.add_runtime_dependency 'rubocop', '~> 1.0'
25
+ spec.metadata = {
26
+ 'rubygems_mfa_required' => 'true'
27
+ }
28
+
29
+ spec.add_dependency 'rubocop', '~> 1.0'
32
30
  end
metadata CHANGED
@@ -1,88 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  - Brandon High
9
9
  - TP Honey
10
10
  - Helen Campbell
11
- autorequire:
12
11
  bindir: exe
13
12
  cert_chain: []
14
- date: 2020-12-14 00:00:00.000000000 Z
13
+ date: 2025-01-21 00:00:00.000000000 Z
15
14
  dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: bundler
18
- requirement: !ruby/object:Gem::Requirement
19
- requirements:
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 1.17.3
23
- type: :development
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: 1.17.3
30
- - !ruby/object:Gem::Dependency
31
- name: pry
32
- requirement: !ruby/object:Gem::Requirement
33
- requirements:
34
- - - "~>"
35
- - !ruby/object:Gem::Version
36
- version: 0.13.1
37
- type: :development
38
- prerelease: false
39
- version_requirements: !ruby/object:Gem::Requirement
40
- requirements:
41
- - - "~>"
42
- - !ruby/object:Gem::Version
43
- version: 0.13.1
44
- - !ruby/object:Gem::Dependency
45
- name: rake
46
- requirement: !ruby/object:Gem::Requirement
47
- requirements:
48
- - - ">="
49
- - !ruby/object:Gem::Version
50
- version: 12.3.3
51
- type: :development
52
- prerelease: false
53
- version_requirements: !ruby/object:Gem::Requirement
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- version: 12.3.3
58
- - !ruby/object:Gem::Dependency
59
- name: rb-readline
60
- requirement: !ruby/object:Gem::Requirement
61
- requirements:
62
- - - "~>"
63
- - !ruby/object:Gem::Version
64
- version: 0.5.5
65
- type: :development
66
- prerelease: false
67
- version_requirements: !ruby/object:Gem::Requirement
68
- requirements:
69
- - - "~>"
70
- - !ruby/object:Gem::Version
71
- version: 0.5.5
72
- - !ruby/object:Gem::Dependency
73
- name: rspec
74
- requirement: !ruby/object:Gem::Requirement
75
- requirements:
76
- - - "~>"
77
- - !ruby/object:Gem::Version
78
- version: '3.0'
79
- type: :development
80
- prerelease: false
81
- version_requirements: !ruby/object:Gem::Requirement
82
- requirements:
83
- - - "~>"
84
- - !ruby/object:Gem::Version
85
- version: '3.0'
86
15
  - !ruby/object:Gem::Dependency
87
16
  name: rubocop
88
17
  requirement: !ruby/object:Gem::Requirement
@@ -99,24 +28,19 @@ dependencies:
99
28
  version: '1.0'
100
29
  description: RuboCop rules for detecting and autocorrecting undecorated strings for
101
30
  i18n (gettext and rails-i18n)
102
- email:
103
- - team-modules@puppet.com
104
- - brandon.high@puppet.com
105
- - tp@puppet.com
106
- - helen@puppet.com
107
31
  executables: []
108
32
  extensions: []
109
33
  extra_rdoc_files: []
110
34
  files:
111
35
  - ".github/ISSUE_TEMPLATE/bug_report.md"
112
36
  - ".github/ISSUE_TEMPLATE/feature_request.md"
37
+ - ".github/workflows/rubocop.yml"
113
38
  - ".gitignore"
39
+ - ".rspec"
114
40
  - ".rubocop.yml"
115
41
  - ".rubocop_todo.yml"
116
42
  - ".ruby-version"
117
- - ".travis.yml"
118
43
  - CHANGELOG.md
119
- - CODEOWNERS
120
44
  - CODE_OF_CONDUCT.md
121
45
  - Gemfile
122
46
  - LICENSE
@@ -124,8 +48,8 @@ files:
124
48
  - Rakefile
125
49
  - bin/console
126
50
  - bin/setup
51
+ - config/default.yml
127
52
  - lib/rubocop-i18n.rb
128
- - lib/rubocop/cop/i18n.rb
129
53
  - lib/rubocop/cop/i18n/gettext.rb
130
54
  - lib/rubocop/cop/i18n/gettext/decorate_function_message.rb
131
55
  - lib/rubocop/cop/i18n/gettext/decorate_string.rb
@@ -134,12 +58,15 @@ files:
134
58
  - lib/rubocop/cop/i18n/rails_i18n.rb
135
59
  - lib/rubocop/cop/i18n/rails_i18n/decorate_string.rb
136
60
  - lib/rubocop/cop/i18n/rails_i18n/decorate_string_formatting_using_interpolation.rb
61
+ - lib/rubocop/cop/i18n_cops.rb
62
+ - lib/rubocop/i18n.rb
63
+ - lib/rubocop/i18n/inject.rb
137
64
  - rubocop-i18n.gemspec
138
- homepage: https://github.com/puppetlabs/rubocop-i18n
65
+ homepage: https://github.com/rubocop/rubocop-i18n
139
66
  licenses:
140
67
  - Apache-2.0
141
- metadata: {}
142
- post_install_message:
68
+ metadata:
69
+ rubygems_mfa_required: 'true'
143
70
  rdoc_options: []
144
71
  require_paths:
145
72
  - lib
@@ -154,8 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
81
  - !ruby/object:Gem::Version
155
82
  version: '0'
156
83
  requirements: []
157
- rubygems_version: 3.1.4
158
- signing_key:
84
+ rubygems_version: 3.6.2
159
85
  specification_version: 4
160
86
  summary: RuboCop rules for i18n
161
87
  test_files: []
data/.travis.yml DELETED
@@ -1,12 +0,0 @@
1
- ---
2
- os: linux
3
- dist: xenial
4
- language: ruby
5
- rvm:
6
- - 2.5.8
7
- - 2.6.6
8
- - 2.7.2
9
- jobs:
10
- fast_finish: true
11
- notifications:
12
- email: true
data/CODEOWNERS DELETED
@@ -1,5 +0,0 @@
1
- # These owners will be the default owners for everything in
2
- # the repo. Unless a later match takes precedence,
3
- # @global-owner1 and @global-owner2 will be requested for
4
- # review when someone opens a pull request.
5
- * @highb @puppetlabs/open-source-stewards
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rubocop'
4
- require 'rubocop/cop/i18n/gettext'
5
- require 'rubocop/cop/i18n/gettext/decorate_string'
6
- require 'rubocop/cop/i18n/gettext/decorate_function_message'
7
- require 'rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation'
8
- require 'rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent'
9
-
10
- require 'rubocop/cop/i18n/rails_i18n'
11
- require 'rubocop/cop/i18n/rails_i18n/decorate_string'
12
- require 'rubocop/cop/i18n/rails_i18n/decorate_string_formatting_using_interpolation'