rubocop-i18n 3.0.0 → 3.2.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: 40440c74a9f3245bc18bc95f36f3fddc4512249611f680ba0a8a8ee3027411a0
4
+ data.tar.gz: f4c16aa614332d0f7938deaee0feedfc6d13bbca695f54a42147aa6911d5226b
5
5
  SHA512:
6
- metadata.gz: 666a5de6a09a035d64937dcdf1441faaef249ebc6df44572f37d858ffdf00f2509abc56581900fb839d857e2e4da2c7a9e71f0d20476ab67c8d83022670052b7
7
- data.tar.gz: 9c5cc9f02c4408c8f3a2667125b65bb1a6385bf7d885b38787521961646240d4684d81988592298009ec54660f3533f8722b8c1118809528f2d6641f0ac808b2
6
+ metadata.gz: 06b836f7100a74801a7d3f3c46e2df2a9d620fad44bc5279b92ec3e1748daa1d7b938cdbf496b00f4b8edd541c0d44e3c704720990ebf746f031fc8707b69d94
7
+ data.tar.gz: 0cc9e35e18192a913138a20f442e5f8bbb927aab67caa6a1b381df27e2b126792db86cd21e6842ce76dac165a526416aa27fca447b91d507eb5b722df2c735b4
@@ -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/.gitignore CHANGED
@@ -1,5 +1,6 @@
1
1
  *.gem
2
2
  *.rbc
3
+ .ruby-version
3
4
  /.config
4
5
  /coverage/
5
6
  /InstalledFiles
@@ -10,6 +11,7 @@
10
11
  /test/version_tmp/
11
12
  /tmp/
12
13
  /.idea/
14
+ Gemfile.lock
13
15
 
14
16
  # Used by dotenv library to load environment variables.
15
17
  # .env
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml CHANGED
@@ -1,9 +1,18 @@
1
1
  inherit_from: .rubocop_todo.yml
2
- require:
3
- - rubocop/cop/internal_affairs
2
+
3
+ plugins:
4
+ - rubocop-internal_affairs
5
+ - rubocop-rake
6
+ - rubocop-rspec
7
+ - rubocop-performance
4
8
 
5
9
  AllCops:
6
- TargetRubyVersion: 2.5
10
+ TargetRubyVersion: 2.7
11
+ NewCops: enable
12
+
13
+ # rubocop-i18n does not have config/default.
14
+ InternalAffairs/UndefinedConfig:
15
+ Enabled: false
7
16
 
8
17
  Metrics/BlockLength:
9
18
  Exclude:
data/.rubocop_todo.yml CHANGED
@@ -1,28 +1,29 @@
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-23 02:17:39 UTC using RuboCop version 1.71.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
- # Offense count: 1
10
- # Configuration parameters: Include.
11
- # Include: **/*.gemspec
12
- Gemspec/RequiredRubyVersion:
9
+ # Offense count: 4
10
+ InternalAffairs/OnSendWithoutOnCSend:
13
11
  Exclude:
14
- - 'rubocop-i18n.gemspec'
12
+ - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb'
13
+ - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_interpolation.rb'
14
+ - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb'
15
+ - 'lib/rubocop/cop/i18n/rails_i18n/decorate_string_formatting_using_interpolation.rb'
15
16
 
16
17
  # Offense count: 1
17
- # Cop supports --auto-correct.
18
+ # This cop supports unsafe autocorrection (--autocorrect-all).
18
19
  Lint/InterpolationCheck:
19
20
  Exclude:
20
- - 'spec/rubocop/cop/i18n/gettext/decorate_string_spec.rb'
21
+ - 'spec/rubocop/cop/i18n/get_text/decorate_string_spec.rb'
21
22
 
22
- # Offense count: 2
23
- # Configuration parameters: IgnoredMethods.
23
+ # Offense count: 3
24
+ # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
24
25
  Metrics/AbcSize:
25
- Max: 29
26
+ Max: 24
26
27
 
27
28
  # Offense count: 1
28
29
  # Configuration parameters: CountComments, CountAsOne.
@@ -30,23 +31,49 @@ Metrics/ClassLength:
30
31
  Max: 108
31
32
 
32
33
  # Offense count: 5
33
- # Configuration parameters: IgnoredMethods.
34
+ # Configuration parameters: AllowedMethods, AllowedPatterns.
34
35
  Metrics/CyclomaticComplexity:
35
36
  Max: 8
36
37
 
37
38
  # Offense count: 7
38
- # Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
39
+ # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
39
40
  Metrics/MethodLength:
40
41
  Max: 25
41
42
 
42
43
  # Offense count: 1
43
- # Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, Regex, IgnoreExecutableScripts, AllowedAcronyms.
44
+ # Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
45
+ # CheckDefinitionPathHierarchyRoots: lib, spec, test, src
44
46
  # 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
47
  Naming/FileName:
46
48
  Exclude:
49
+ - 'Rakefile.rb'
47
50
  - 'lib/rubocop-i18n.rb'
48
51
 
52
+ # Offense count: 47
53
+ # Configuration parameters: Prefixes, AllowedPatterns.
54
+ # Prefixes: when, with, without
55
+ RSpec/ContextWording:
56
+ Exclude:
57
+ - 'spec/rubocop/cop/i18n/get_text/decorate_function_message_spec.rb'
58
+ - 'spec/rubocop/cop/i18n/get_text/decorate_string_formatting_using_interpolation_spec.rb'
59
+ - 'spec/rubocop/cop/i18n/get_text/decorate_string_formatting_using_percent_spec.rb'
60
+ - 'spec/rubocop/cop/i18n/get_text/decorate_string_spec.rb'
61
+ - 'spec/rubocop/cop/i18n/rails_i18n/decorate_string_formatting_using_interpolation_spec.rb'
62
+ - 'spec/rubocop/cop/i18n/rails_i18n/decorate_string_spec.rb'
63
+
64
+ # Offense count: 7
65
+ # Configuration parameters: AssignmentOnly.
66
+ RSpec/InstanceVariable:
67
+ Exclude:
68
+ - 'spec/rubocop/cop/i18n/get_text/decorate_function_message_spec.rb'
69
+ - 'spec/shared_examples.rb'
70
+
71
+ # Offense count: 2
72
+ RSpec/MultipleExpectations:
73
+ Max: 3
74
+
49
75
  # Offense count: 2
76
+ # Configuration parameters: AllowedConstants.
50
77
  Style/Documentation:
51
78
  Exclude:
52
79
  - 'spec/**/*'
@@ -55,26 +82,29 @@ Style/Documentation:
55
82
  - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb'
56
83
 
57
84
  # Offense count: 12
58
- # Configuration parameters: MaxUnannotatedPlaceholdersAllowed.
85
+ # This cop supports safe autocorrection (--autocorrect).
86
+ # Configuration parameters: MaxUnannotatedPlaceholdersAllowed, AllowedMethods, AllowedPatterns.
59
87
  # SupportedStyles: annotated, template, unannotated
60
88
  Style/FormatStringToken:
61
89
  EnforcedStyle: template
62
90
 
63
91
  # Offense count: 2
64
- # Configuration parameters: MinBodyLength.
92
+ # This cop supports safe autocorrection (--autocorrect).
93
+ # Configuration parameters: MinBodyLength, AllowConsecutiveConditionals.
65
94
  Style/GuardClause:
66
95
  Exclude:
67
96
  - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb'
68
97
  - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb'
69
98
 
70
99
  # Offense count: 6
71
- # Cop supports --auto-correct.
100
+ # This cop supports safe autocorrection (--autocorrect).
72
101
  Style/IfUnlessModifier:
73
102
  Exclude:
74
103
  - 'lib/rubocop/cop/i18n/gettext/decorate_function_message.rb'
75
104
  - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb'
76
105
 
77
106
  # Offense count: 5
107
+ # This cop supports safe autocorrection (--autocorrect).
78
108
  # Configuration parameters: AllowModifier.
79
109
  Style/SoleNestedConditional:
80
110
  Exclude:
@@ -83,9 +113,9 @@ Style/SoleNestedConditional:
83
113
  - 'lib/rubocop/cop/i18n/gettext/decorate_string_formatting_using_percent.rb'
84
114
  - 'lib/rubocop/cop/i18n/rails_i18n/decorate_string.rb'
85
115
 
86
- # Offense count: 50
87
- # Cop supports --auto-correct.
88
- # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
116
+ # Offense count: 47
117
+ # This cop supports safe autocorrection (--autocorrect).
118
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
89
119
  # URISchemes: http, https
90
120
  Layout/LineLength:
91
121
  Max: 174
data/CHANGELOG.md CHANGED
@@ -1,14 +1,24 @@
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.2.0](https://github.com/rubocop/rubocop-i18n/compare/v3.1.0...v3.2.0)
6
+
7
+ * Pluginfy rubocop-i18n (#65)
8
+
9
+ ### [3.1.0](https://github.com/rubocop/rubocop-i18n/compare/v3.0.0...v3.1.0)
10
+
11
+ * Transfer ownership of rubocop-i18n from puppetlabs org to rubocop org (#62)
12
+ * Suppress RuboCop warnings (#59)
13
+
14
+ ### [3.0.0](https://github.com/rubocop/rubocop-i18n/compare/v2.0.2...v3.0.0)
5
15
 
6
16
  * Update Rubocop version to 1.0! Thank you @mvz!
7
17
  * Cop namespace fixes, documentation updates, loading issues. Thank you again @mvz !
8
18
  * Gem maintainership has been passed to @highb. Thank you @binford2k and @lucywyman!
9
19
  * Update Ruby versions in gemspec, Travis, .ruby-version. Thank you @sfeuga!
10
20
 
11
- ### [2.0.2](https://github.com/puppetlabs/rubocop-i18n/compare/v2.0.1...v2.0.2)
21
+ ### [2.0.2](https://github.com/rubocop/rubocop-i18n/compare/v2.0.1...v2.0.2)
12
22
 
13
23
  * Add auto-correct for `DecorateString` (#40) Thanks @mvz!
14
24
  * 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
+ [![CI](https://github.com/rubocop/rubocop-i18n/actions/workflows/rubocop.yml/badge.svg)](https://github.com/rubocop/rubocop-i18n/actions/workflows/rubocop.yml)
4
4
 
5
5
  A set of cops for detecting strings that need i18n decoration in your project.
6
6
 
@@ -28,8 +28,9 @@ Or install it yourself as:
28
28
  ## Usage
29
29
 
30
30
  In your `rubocop.yml`:
31
- ```
32
- require:
31
+
32
+ ```yaml
33
+ plugins:
33
34
  - rubocop-i18n
34
35
  ...
35
36
  # You *must* choose GetText or Rails-i18n style checking
@@ -58,11 +59,14 @@ I18n/RailsI18n/DecorateString:
58
59
  Enabled: false
59
60
  ```
60
61
 
62
+ > [!NOTE]
63
+ > The plugin system is supported in RuboCop 1.72+. In earlier versions, use `require` instead of `plugins`.
64
+
61
65
  ## Cops
62
66
 
63
67
  ### I18n/GetText/DecorateString
64
68
 
65
- This cop is looks for strings that appear to be sentences but are not decorated.
69
+ This cop is looks for strings that appear to be sentences but are not decorated.
66
70
  Sentences are determined by the STRING_REGEXP.
67
71
 
68
72
  ##### Error message thrown
@@ -203,7 +207,7 @@ raise(someOtherFuntioncall(foo, "bar"))
203
207
 
204
208
  ##### Good
205
209
 
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).
210
+ 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
211
  Or ignore this raise or fail function following this [How to ignore rules in code](#How-to-ignore-rules-in-code) section.
208
212
 
209
213
  ### I18n/GetText/DecorateStringFormattingUsingInterpolation
@@ -331,5 +335,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
331
335
 
332
336
  ## Contributing
333
337
 
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
-
338
+ 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 [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)
@@ -31,16 +33,12 @@ module RuboCop
31
33
 
32
34
  parent = node.parent
33
35
  if parent.respond_to?(:type)
34
- return if parent.regexp_type? || parent.dstr_type?
36
+ return if parent.type?(:regexp, :dstr)
35
37
  end
36
38
 
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)
@@ -44,7 +44,7 @@ module RuboCop
44
44
  def contains_string_formatting_with_interpolation?(node)
45
45
  return node.any? { |n| contains_string_formatting_with_interpolation?(n) } if node.is_a?(Array)
46
46
 
47
- return string_contains_interpolation_format?(node.source) if node.respond_to?(:type) && (node.str_type? || node.dstr_type?)
47
+ return string_contains_interpolation_format?(node.source) if node.respond_to?(:type) && node.type?(:str, :dstr)
48
48
 
49
49
  return node.children.any? { |child| contains_string_formatting_with_interpolation?(child) } if node.respond_to?(:children)
50
50
 
@@ -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)
@@ -50,7 +50,7 @@ module RuboCop
50
50
  end
51
51
 
52
52
  if node.respond_to?(:type)
53
- if node.str_type? || node.dstr_type?
53
+ if node.type?(:str, :dstr)
54
54
  return string_contains_percent_format?(node.source)
55
55
  end
56
56
  end
@@ -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
@@ -90,7 +90,7 @@ module RuboCop
90
90
 
91
91
  parent = node.parent
92
92
  if parent.respond_to?(:type)
93
- return if parent.regexp_type? || parent.dstr_type?
93
+ return if parent.type?(:regexp, :dstr)
94
94
  end
95
95
 
96
96
  check_for_parent_decorator(node)
@@ -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
 
@@ -48,7 +48,7 @@ module RuboCop
48
48
  def contains_string_formatting_with_interpolation?(node)
49
49
  return node.any? { |n| contains_string_formatting_with_interpolation?(n) } if node.is_a?(Array)
50
50
 
51
- return string_contains_interpolation_format?(node.source) if node.respond_to?(:type) && (node.str_type? || node.dstr_type?)
51
+ return string_contains_interpolation_format?(node.source) if node.respond_to?(:type) && node.type?(:str, :dstr)
52
52
 
53
53
  return node.children.any? { |child| contains_string_formatting_with_interpolation?(child) } if node.respond_to?(:children)
54
54
 
@@ -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,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'lint_roller'
4
+
5
+ module RuboCop
6
+ module I18n
7
+ # A plugin that integrates rubocop-i18n with RuboCop's plugin system.
8
+ class Plugin < LintRoller::Plugin
9
+ def about
10
+ LintRoller::About.new(
11
+ name: 'rubocop-i18n',
12
+ version: Version::STRING,
13
+ homepage: 'https://github.com/rubocop/rubocop-i18n',
14
+ description: 'RuboCop rules for i18n.'
15
+ )
16
+ end
17
+
18
+ def supported?(context)
19
+ context.engine == :rubocop
20
+ end
21
+
22
+ def rules(_context)
23
+ LintRoller::Rules.new(
24
+ type: :path,
25
+ config_format: :rubocop,
26
+ value: Pathname.new(__dir__).join('../../../config/default.yml')
27
+ )
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ # RuboCop I18n project namespace
5
+ module I18n
6
+ end
7
+ end
data/lib/rubocop-i18n.rb CHANGED
@@ -1,3 +1,7 @@
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/plugin'
7
+ 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.2.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|
@@ -21,12 +20,13 @@ Gem::Specification.new do |spec|
21
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
21
  spec.require_paths = ['lib']
23
22
 
24
- spec.required_ruby_version = '>= 2.5.8'
23
+ spec.required_ruby_version = '>= 2.7.0'
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
+ 'default_lint_roller_plugin' => 'RuboCop::I18n::Plugin'
28
+ }
29
+
30
+ spec.add_dependency 'lint_roller', '~> 1.1'
31
+ spec.add_dependency 'rubocop', '~> 1.72.1'
32
32
  end
metadata CHANGED
@@ -1,122 +1,59 @@
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.2.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-02-19 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !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
16
+ name: lint_roller
32
17
  requirement: !ruby/object:Gem::Requirement
33
18
  requirements:
34
19
  - - "~>"
35
20
  - !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
21
+ version: '1.1'
22
+ type: :runtime
80
23
  prerelease: false
81
24
  version_requirements: !ruby/object:Gem::Requirement
82
25
  requirements:
83
26
  - - "~>"
84
27
  - !ruby/object:Gem::Version
85
- version: '3.0'
28
+ version: '1.1'
86
29
  - !ruby/object:Gem::Dependency
87
30
  name: rubocop
88
31
  requirement: !ruby/object:Gem::Requirement
89
32
  requirements:
90
33
  - - "~>"
91
34
  - !ruby/object:Gem::Version
92
- version: '1.0'
35
+ version: 1.72.1
93
36
  type: :runtime
94
37
  prerelease: false
95
38
  version_requirements: !ruby/object:Gem::Requirement
96
39
  requirements:
97
40
  - - "~>"
98
41
  - !ruby/object:Gem::Version
99
- version: '1.0'
42
+ version: 1.72.1
100
43
  description: RuboCop rules for detecting and autocorrecting undecorated strings for
101
44
  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
45
  executables: []
108
46
  extensions: []
109
47
  extra_rdoc_files: []
110
48
  files:
111
49
  - ".github/ISSUE_TEMPLATE/bug_report.md"
112
50
  - ".github/ISSUE_TEMPLATE/feature_request.md"
51
+ - ".github/workflows/rubocop.yml"
113
52
  - ".gitignore"
53
+ - ".rspec"
114
54
  - ".rubocop.yml"
115
55
  - ".rubocop_todo.yml"
116
- - ".ruby-version"
117
- - ".travis.yml"
118
56
  - CHANGELOG.md
119
- - CODEOWNERS
120
57
  - CODE_OF_CONDUCT.md
121
58
  - Gemfile
122
59
  - LICENSE
@@ -124,8 +61,8 @@ files:
124
61
  - Rakefile
125
62
  - bin/console
126
63
  - bin/setup
64
+ - config/default.yml
127
65
  - lib/rubocop-i18n.rb
128
- - lib/rubocop/cop/i18n.rb
129
66
  - lib/rubocop/cop/i18n/gettext.rb
130
67
  - lib/rubocop/cop/i18n/gettext/decorate_function_message.rb
131
68
  - lib/rubocop/cop/i18n/gettext/decorate_string.rb
@@ -134,12 +71,16 @@ files:
134
71
  - lib/rubocop/cop/i18n/rails_i18n.rb
135
72
  - lib/rubocop/cop/i18n/rails_i18n/decorate_string.rb
136
73
  - lib/rubocop/cop/i18n/rails_i18n/decorate_string_formatting_using_interpolation.rb
74
+ - lib/rubocop/cop/i18n_cops.rb
75
+ - lib/rubocop/i18n.rb
76
+ - lib/rubocop/i18n/plugin.rb
137
77
  - rubocop-i18n.gemspec
138
- homepage: https://github.com/puppetlabs/rubocop-i18n
78
+ homepage: https://github.com/rubocop/rubocop-i18n
139
79
  licenses:
140
80
  - Apache-2.0
141
- metadata: {}
142
- post_install_message:
81
+ metadata:
82
+ rubygems_mfa_required: 'true'
83
+ default_lint_roller_plugin: RuboCop::I18n::Plugin
143
84
  rdoc_options: []
144
85
  require_paths:
145
86
  - lib
@@ -147,15 +88,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
88
  requirements:
148
89
  - - ">="
149
90
  - !ruby/object:Gem::Version
150
- version: 2.5.8
91
+ version: 2.7.0
151
92
  required_rubygems_version: !ruby/object:Gem::Requirement
152
93
  requirements:
153
94
  - - ">="
154
95
  - !ruby/object:Gem::Version
155
96
  version: '0'
156
97
  requirements: []
157
- rubygems_version: 3.1.4
158
- signing_key:
98
+ rubygems_version: 3.6.2
159
99
  specification_version: 4
160
100
  summary: RuboCop rules for i18n
161
101
  test_files: []
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.7.2
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'