quiet_quality 1.3.1 → 1.4.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: 7049c44ac27b14f8f599dfcb080dcd7d6aadceed0cee69f0d9f460ccb23bd66c
4
- data.tar.gz: 6ec55838027c9bd81659109807e27e50199b5c54e1e17d04b2b0727819851d89
3
+ metadata.gz: 81e7296beb4ced635f0e6e0d1b5521adb6481b3ca4d027e86e76ad1ee8682643
4
+ data.tar.gz: 27dfab991d21f98536860a0fdbeed31faa1ea5b65a2af0941e0cc286fe6dcbc1
5
5
  SHA512:
6
- metadata.gz: 1cac5b2196f3409ab37252830b115cf7ec54b0cc21e2e5a25062cb4cd79615f7378a6ac4bd2d4fd39a0c1ff6882948fa2e6e1f7029dd88b1b9989fb8910aa0b6
7
- data.tar.gz: e48380c23c35946e11c011bb1bdb694f6731d93828fa06a4d725a9d9a9c347e3f8ee5a8687904593905da9be74c5d8903b09f72c815f2dbdcb5fdedcc5f8e69f
6
+ metadata.gz: b84bb256a178326bc76143952098db02723fcfa792ed6e86f9b6b63a0c602d87eb270d81d93e34742c2026abd7fd2118964b3a039eb8e3968863a8d1e5fe1697
7
+ data.tar.gz: 76fc65f2ce473f91a8cb98bc32c62e98ecc154aef519ab8d9e908f7def8330306b76ee2c54ed99a57bfba4b5997065b6d953747756b9a0b83e9e557c96de1d23
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## Release 1.4.0
4
+
5
+ * Support specifying `excludes` per-tool, so that certain files won't be passed
6
+ to those tools on the command-line (#107 resolves #106)
7
+
3
8
  ## Release 1.3.1
4
9
 
5
10
  * Fix a bug around the logging of nil commands when runners are skipped (#104
data/README.md CHANGED
@@ -156,14 +156,14 @@ And then each tool can have an entry, within which `changed_files` and
156
156
  `filter_messages` can be specified - the tool-specific settings override the
157
157
  global ones.
158
158
 
159
- The tools have one additional setting that is not available at a global level:
160
- `file_filter`. This is a string that will be turned into a _ruby regex_, and
161
- used to limit what file paths are passed to the tool. For example, if you are
162
- working in a rails engine `engines/foo/`, and you touch one of the rspec tests
163
- there, you would not want `qq` in the root of the repository to run
164
- `rspec engines/foo/spec/foo/thing_spec.rb` - that probably won't work, as your
165
- engine will have its own test setup code and Gemfile. This setting is mostly
166
- intended to be used like this:
159
+ The tools have two additional settings that are not available at a global level:
160
+ `file_filter` and `excludes`. `file_filter` is a string that will be turned into
161
+ a _ruby regex_, and used to limit what file paths are passed to the tool. For
162
+ example, if you are working in a rails engine `engines/foo/`, and you touch one
163
+ of the rspec tests there, you would not want `qq` in the root of the repository
164
+ to run `rspec engines/foo/spec/foo/thing_spec.rb` - that probably won't work, as
165
+ your engine will have its own test setup code and Gemfile. This setting is
166
+ mostly intended to be used like this:
167
167
 
168
168
  ```yaml
169
169
  rspec:
@@ -172,6 +172,15 @@ rspec:
172
172
  file_filter: "^spec/"
173
173
  ```
174
174
 
175
+ `excludes` are more specific in meaning - this is an _array_ of regexes, and any
176
+ file that matches any of these regexes will _not_ be passed to the tool as an
177
+ explicit command line argument. This is generally because tools like rubocop
178
+ have internal systems for excluding files, but if you pass a filename on the
179
+ cli, those systems are ignored. That means that if you have changes to a
180
+ generated file like `db/schema.rb`, and that file doesn't meet your rubocop (or
181
+ standardrb) rules, you'll get _told_ unless you exclude it at the quiet-quality
182
+ level as well.
183
+
175
184
  ### CLI Options
176
185
 
177
186
  To specify which _tools_ to run (and if any are specified, the `default_tools`
@@ -0,0 +1,52 @@
1
+ module QuietQuality
2
+ module Config
3
+ class FileFilter
4
+ # * regex is a regex string
5
+ # * excludes is an array of regex strings OR a single regex string
6
+ def initialize(regex: nil, excludes: nil)
7
+ @regex_string = regex
8
+ @excludes_strings = excludes
9
+ end
10
+
11
+ def regex
12
+ return nil if @regex_string.nil?
13
+ @_regex ||= Regexp.new(@regex_string)
14
+ end
15
+
16
+ def excludes
17
+ return @_excludes if defined?(@_excludes)
18
+
19
+ @_excludes =
20
+ if @excludes_strings.nil?
21
+ nil
22
+ elsif @excludes_strings.is_a?(String)
23
+ [Regexp.new(@excludes_strings)]
24
+ else
25
+ @excludes_strings.map { |xs| Regexp.new(xs) }
26
+ end
27
+ end
28
+
29
+ # The filter _overall_ matches if:
30
+ # (a) the regex either matches or is not supplied AND
31
+ # (b) either none of the excludes match or none are supplied
32
+ def match?(s)
33
+ regex_match?(s) && !excludes_match?(s)
34
+ end
35
+
36
+ private
37
+
38
+ # The regex is an allow-match - if it's not supplied, treat everything as matching.
39
+ def regex_match?(s)
40
+ return true if regex.nil?
41
+ regex.match?(s)
42
+ end
43
+
44
+ # The excludes are a list of deny-matches - if they're not supplied, treat _nothing_
45
+ # as matching.
46
+ def excludes_match?(s)
47
+ return false if excludes.nil? || excludes.empty?
48
+ excludes.any? { |exclude| exclude.match?(s) }
49
+ end
50
+ end
51
+ end
52
+ end
@@ -64,7 +64,7 @@ module QuietQuality
64
64
  read_tool_option(opts, tool_name, :unfiltered, :filter_messages, as: :reversed_boolean)
65
65
  read_tool_option(opts, tool_name, :changed_files, :limit_targets, as: :boolean)
66
66
  read_tool_option(opts, tool_name, :all_files, :limit_targets, as: :reversed_boolean)
67
- read_tool_option(opts, tool_name, :file_filter, :file_filter, as: :string)
67
+ read_file_filter(opts, tool_name)
68
68
  end
69
69
 
70
70
  def invalid!(message)
@@ -97,6 +97,15 @@ module QuietQuality
97
97
  opts.set_tool_option(tool, into, coerced_value)
98
98
  end
99
99
 
100
+ def read_file_filter(opts, tool)
101
+ parsed_regex = data.dig(tool.to_sym, :file_filter)
102
+ parsed_excludes = data.dig(tool.to_sym, :excludes)
103
+ if parsed_regex || parsed_excludes
104
+ filter = Config::FileFilter.new(regex: parsed_regex, excludes: parsed_excludes)
105
+ opts.set_tool_option(tool, :file_filter, filter)
106
+ end
107
+ end
108
+
100
109
  def validate_value(name, value, as:, from: nil)
101
110
  case as
102
111
  when :boolean then validate_boolean(name, value)
@@ -8,8 +8,9 @@ module QuietQuality
8
8
  @file_filter = file_filter
9
9
  end
10
10
 
11
+ attr_accessor :file_filter
11
12
  attr_reader :tool_name
12
- attr_writer :limit_targets, :filter_messages, :file_filter
13
+ attr_writer :limit_targets, :filter_messages
13
14
 
14
15
  def limit_targets?
15
16
  @limit_targets
@@ -31,17 +32,13 @@ module QuietQuality
31
32
  tool_namespace::Parser
32
33
  end
33
34
 
34
- def file_filter
35
- return nil if @file_filter.nil?
36
- Regexp.new(@file_filter)
37
- end
38
-
39
35
  def to_h
40
36
  {
41
37
  tool_name: tool_name,
42
38
  limit_targets: limit_targets?,
43
39
  filter_messages: filter_messages?,
44
- file_filter: file_filter&.to_s
40
+ file_filter: file_filter&.regex&.to_s,
41
+ excludes: file_filter&.excludes&.map(&:to_s)
45
42
  }
46
43
  end
47
44
  end
@@ -1,3 +1,3 @@
1
1
  module QuietQuality
2
- VERSION = "1.3.1"
2
+ VERSION = "1.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quiet_quality
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Mueller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-14 00:00:00.000000000 Z
11
+ date: 2023-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -203,6 +203,7 @@ files:
203
203
  - lib/quiet_quality/colorize.rb
204
204
  - lib/quiet_quality/config.rb
205
205
  - lib/quiet_quality/config/builder.rb
206
+ - lib/quiet_quality/config/file_filter.rb
206
207
  - lib/quiet_quality/config/finder.rb
207
208
  - lib/quiet_quality/config/options.rb
208
209
  - lib/quiet_quality/config/parsed_options.rb
@@ -266,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
266
267
  - !ruby/object:Gem::Version
267
268
  version: '0'
268
269
  requirements: []
269
- rubygems_version: 3.3.7
270
+ rubygems_version: 3.4.10
270
271
  signing_key:
271
272
  specification_version: 4
272
273
  summary: A system for comparing quality tool outputs against the forward diffs