glib-web 7.0.0.beta1 → 7.0.1.beta1

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.
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'English'
4
- require 'shellwords'
5
-
6
- module Glib
7
- module Test
8
- # Fast RuboCop guard for the subset-run workflow.
9
- #
10
- # Lives in glib-web's test helper so any project that includes
11
- # `Glib::TestHelpers` into `ActiveSupport::TestCase` picks it up. Minitest
12
- # runs all loaded test classes on every invocation, so this fires on every
13
- # `rails test` — but it lints ONLY the files you have changed in the
14
- # working tree (unstaged + staged + untracked). That keeps it fast and
15
- # fails the run the moment an edited file has an offense.
16
- #
17
- # Skip with `SKIP_CHANGED_RUBOCOP=1` during tight debug loops. Auto-skips
18
- # on CI because gem caches put thousands of vendored `.rb` files into the
19
- # working tree (the "working-tree diff == your edits" premise breaks).
20
- class ChangedFilesRubocop < ::ActiveSupport::TestCase
21
- # Extensions RuboCop targets by default (see its AllCops/Include). We
22
- # rely on `--force-exclusion` to honour the project's AllCops/Exclude.
23
- RUBOCOP_EXTENSIONS = %w[.rb .rake .jbuilder .gemspec].freeze
24
-
25
- def test_changed_files_are_rubocop_clean
26
- skip 'opted out via SKIP_CHANGED_RUBOCOP' if ENV['SKIP_CHANGED_RUBOCOP'] == '1'
27
- skip 'CI lints every file separately; this guard is for local working-tree edits' if ENV['CI']
28
-
29
- files = changed_ruby_files
30
- # IMPORTANT: never call rubocop with zero paths — it would lint the whole repo.
31
- skip 'no changed Ruby files in the working tree' if files.empty?
32
-
33
- output = `bundle exec rubocop --force-exclusion --format simple #{files.shelljoin} 2>&1`
34
-
35
- assert(
36
- $CHILD_STATUS.success?,
37
- 'RuboCop offenses in files you changed (fix them with `rubocop -a`):' \
38
- "\n\n#{output}"
39
- )
40
- end
41
-
42
- private
43
- def changed_ruby_files
44
- # `git status --porcelain` covers unstaged, staged, and untracked in
45
- # one spawn. Each line is `XY PATH` (or `XY ORIG -> PATH` for
46
- # renames); PATH starts at index 3. Deleted files are dropped by the
47
- # File.file? check below (no on-disk entry to lint).
48
- `git status --porcelain`
49
- .split("\n")
50
- .filter_map { |line| line[3..]&.split(' -> ')&.last }
51
- .select { |path| RUBOCOP_EXTENSIONS.include?(File.extname(path)) && File.file?(path) }
52
- end
53
- end
54
- end
55
- end