inclusive-code 0.1.3 → 0.1.4

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: b984b231154566e4f8d334aec467d8a8e6f985a8e3bd3faccc7251b8bb76222a
4
- data.tar.gz: 734179a39aa026ea3266a10709712552bc1ce7c8e7c0c43eee29e36bf5cd0f99
3
+ metadata.gz: f0e9a66b10fa6c3d82c8faa54ddacb5953682d660b3751567aec4af6e6a1d945
4
+ data.tar.gz: cdb7d1ec5ceaa41f4fa134c449a463251c59560a2d4ae6e8fe87d4e46b7acc6d
5
5
  SHA512:
6
- metadata.gz: dab29167526189675e57a227a1e0c74c12651fff08b5f6eb258ae44daf82ac564d85a8d0b7f3703514a943a2bab1b3a8f7322f276380c866f048a054dc592fe7
7
- data.tar.gz: 100acf863203a84c36a43c71252b8a10ca3f88f7eda70210b55ee6852ecd5a7a9d4a7e2a6e024e6691872a74c5e9c3edcda41939265f7729899d66a52750191d
6
+ metadata.gz: 87f0191b289b92d8b3241b05295d12b661fda42aa671519471b2bb494ed6ca3853d8b4a3aee662c8ba6828693fc50f4a219d60b8d6552069585571dacd99fd5d
7
+ data.tar.gz: 1782766b518b793d0e702a2977c499f672a4ea1bbfc5009f1efbb628e3458ac536469265b95e9b705cdf6fdf64ddccab27319ee2ce07572ebb98f8517254778a
data/README.md CHANGED
@@ -26,8 +26,11 @@ require:
26
26
  Flexport/InclusiveCode:
27
27
  Enabled: true
28
28
  GlobalConfigPath: 'app/constants/inclusive_code/inclusive_code_flagged_terms.yml' # or your path
29
+ DisableAutoCorrect: false
29
30
  ```
30
31
 
31
32
  You can run the cop on your entire codebase with `rubocop --only Flexport/InclusiveCode`.
32
33
 
33
34
  You can run the cop on a specific file with `rubocop --only Flexport/InclusiveCode file_path`.
35
+
36
+ If you want to add inline `rubocop:disable` or `rubocop:todo` comments on all offenses, set `DisableAutoCorrect: true` in your .rubocop.yml, and run `rubocop --only Flexport/InclusiveCode --auto-correct --disable-uncorrectable`.
@@ -61,19 +61,23 @@ module RuboCop
61
61
  :scan,
62
62
  scan_regex
63
63
  ).map { Regexp.last_match&.offset(0)&.first }
64
+
65
+ non_inclusive_words = line.scan /#{non_inclusive_word}/i
66
+
67
+ locations = locations.zip(non_inclusive_words).to_h
64
68
  next if locations.blank?
65
69
 
66
- locations.each do |location|
70
+ locations.each do |location, word|
67
71
  range = source_range(
68
72
  processed_source.buffer,
69
73
  line_number + 1,
70
74
  location,
71
- non_inclusive_word.length
75
+ word.length
72
76
  )
73
77
  add_offense(
74
78
  range,
75
79
  location: range,
76
- message: create_message(non_inclusive_word),
80
+ message: create_message(word),
77
81
  severity: SEVERITY
78
82
  )
79
83
  end
@@ -99,11 +103,10 @@ module RuboCop
99
103
  return if cop_config['DisableAutoCorrect']
100
104
 
101
105
  word_to_correct = arg_pair.source
102
- word_to_correct_downcase = word_to_correct.downcase
103
- return unless @non_inclusive_words_alternatives_hash.key?(word_to_correct_downcase)
104
- return if @non_inclusive_words_alternatives_hash[word_to_correct_downcase]['suggestions'].blank?
106
+ correction = correction_for_word(word_to_correct)
107
+ return if correction['suggestions'].blank?
105
108
 
106
- corrected = @non_inclusive_words_alternatives_hash[word_to_correct_downcase]['suggestions'][0]
109
+ corrected = correction['suggestions'][0]
107
110
 
108
111
  # Only respects case if it is capitalized or uniform (all upper or all lower)
109
112
  to_upcase = word_to_correct == word_to_correct.upcase
@@ -128,11 +131,19 @@ module RuboCop
128
131
  (allowed + snake_case + pascal_case).join('|')
129
132
  end
130
133
 
134
+ def correction_for_word(word_to_correct)
135
+ _, correction = @non_inclusive_words_alternatives_hash.detect {|correction_key, _| Regexp.new(correction_key, Regexp::IGNORECASE).match? word_to_correct.downcase }
136
+
137
+ correction || {}
138
+ end
139
+
131
140
  def create_message(non_inclusive_word)
141
+ correction = correction_for_word(non_inclusive_word)
142
+
132
143
  format(
133
144
  MSG,
134
145
  non_inclusive_word: non_inclusive_word,
135
- suggestions: @non_inclusive_words_alternatives_hash[non_inclusive_word]['suggestions'].join(', ')
146
+ suggestions: correction.fetch('suggestions') {[]}.join(', ')
136
147
  )
137
148
  end
138
149
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module InclusiveCode
5
- VERSION = '0.1.3'
5
+ VERSION = '0.1.4'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inclusive-code
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flexport Engineering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-06 00:00:00.000000000 Z
11
+ date: 2021-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -52,7 +52,7 @@ files:
52
52
  - lib/rubocop/inclusive_code.rb
53
53
  - lib/rubocop/inclusive_code/inject.rb
54
54
  - lib/rubocop/inclusive_code/version.rb
55
- homepage: https://github.com/flexport/inclusive-code
55
+ homepage: https://github.com/flexport/rubocop-flexport
56
56
  licenses:
57
57
  - MIT
58
58
  metadata: {}