rails-css_unused 0.1.0 → 0.2.1
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 +4 -4
- data/CHANGELOG.md +53 -24
- data/LICENSE.txt +21 -21
- data/README.md +132 -132
- data/lib/rails/css_unused/configuration.rb +97 -45
- data/lib/rails/css_unused/railtie.rb +25 -24
- data/lib/rails/css_unused/report.rb +111 -50
- data/lib/rails/css_unused/spinner.rb +80 -0
- data/lib/rails/css_unused/stylesheet_scanner.rb +149 -82
- data/lib/rails/css_unused/tasks.rake +32 -12
- data/lib/rails/css_unused/version.rb +7 -7
- data/lib/rails/css_unused/view_scanner.rb +324 -117
- data/lib/rails/css_unused.rb +40 -36
- data/lib/rails-css_unused.rb +6 -3
- metadata +10 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3e275861ec42e64ade413fc24f51105fcdfbc77691b3b8a421029523e96f8b59
|
|
4
|
+
data.tar.gz: 06da7233e0f634d4feeb02664b24f438537449a20ac2b28845866c60fb73514a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ec24c67fc3da46c54954d210c4ae1ffef696abba69a32b06c7e4a56d75c9f72c65f32ad0dfea9044248fd8ff31f9adb847381b2d527215668bac1ebcb66c5619
|
|
7
|
+
data.tar.gz: 0023736da3656117d62196f8509b04a1b27622726e10772ccad96690e8cd5210b21305ad2034720dffabba50fa3b9756df73c4abee628b8ce23f92dc46ac1be7
|
data/CHANGELOG.md
CHANGED
|
@@ -1,24 +1,53 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.2.1] - 2026-06-02
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- **Smart dynamic class variable detection** — the scanner now automatically
|
|
7
|
+
detects CSS class strings assigned to variables whose name ends in
|
|
8
|
+
`_class`, `_classes`, `_style`, or `_css` (e.g. `status_class = "foo-bar"`).
|
|
9
|
+
- **Hyphenated string literal detection** — any quoted string containing a
|
|
10
|
+
hyphen is now treated as a CSS class value. Since Ruby variable names
|
|
11
|
+
cannot contain hyphens, hyphenated quoted strings are unambiguously string
|
|
12
|
+
values, never identifiers. This eliminates false positives from patterns like:
|
|
13
|
+
```erb
|
|
14
|
+
<% status_class =
|
|
15
|
+
if exam.cancelled?
|
|
16
|
+
["Cancelled", "status-cancelled"]
|
|
17
|
+
elsif exam.approved?
|
|
18
|
+
["Approved", "status-approved"]
|
|
19
|
+
end %>
|
|
20
|
+
<span class="status-pill <%= status_class %>">
|
|
21
|
+
```
|
|
22
|
+
Classes like `status-cancelled`, `status-approved`, `status-requested`
|
|
23
|
+
are now correctly detected as used without needing `ignore_patterns`.
|
|
24
|
+
- Dynamic class var detection also runs in HAML, Slim, and Ruby component files.
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
- False positives for dynamically assigned CSS classes used via ERB interpolation
|
|
28
|
+
(e.g. `<%= status_class %>`, `<%= button_css %>`).
|
|
29
|
+
|
|
30
|
+
## [0.2.0] - 2026-05-31
|
|
31
|
+
|
|
32
|
+
### Added
|
|
33
|
+
- HAML and Slim template scanning
|
|
34
|
+
- ViewComponent and Phlex component support
|
|
35
|
+
- Stimulus controller JS class scanning (`classList.add`, `classList.toggle`)
|
|
36
|
+
- `scan_javascript_for_classes` config option
|
|
37
|
+
- `scan_ruby_components` config option
|
|
38
|
+
- `show_source_files` config option
|
|
39
|
+
- `fail_on_unused` config option for CI pipelines
|
|
40
|
+
- BEM class name support (`block__element--modifier`)
|
|
41
|
+
- ERB dynamic class attribute extraction (static parts from `class="<%= expr %>"`)
|
|
42
|
+
- `ignore_patterns` config for regex-based exclusions
|
|
43
|
+
- Spinner output during scanning
|
|
44
|
+
|
|
45
|
+
## [0.1.0] - 2026-05-15
|
|
46
|
+
|
|
47
|
+
### Added
|
|
48
|
+
- Initial release
|
|
49
|
+
- CSS/SCSS/SASS stylesheet scanning
|
|
50
|
+
- ERB view scanning (`class="..."`, `class: "..."`, `class: [...]`)
|
|
51
|
+
- Ghost class report with counts
|
|
52
|
+
- `ignore_classes` configuration
|
|
53
|
+
- `css_unused:report` rake task
|
data/LICENSE.txt
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Syed Ghani
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
|
@@ -1,132 +1,132 @@
|
|
|
1
|
-
# rails-css_unused
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
config.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
##
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
## License
|
|
131
|
-
|
|
132
|
-
|
|
1
|
+
# rails-css_unused
|
|
2
|
+
|
|
3
|
+
**Find unused CSS classes in your Rails app — zero runtime overhead, zero false positives from file extensions or at-rules.**
|
|
4
|
+
|
|
5
|
+
[](https://rubygems.org/gems/rails-css_unused)
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Why this gem?
|
|
10
|
+
|
|
11
|
+
| Feature | deadweight | rails-css_unused |
|
|
12
|
+
|---------|-----------|-----------------|
|
|
13
|
+
| Maintained | ❌ abandoned | ✅ |
|
|
14
|
+
| Rails 7+ | ❌ | ✅ |
|
|
15
|
+
| Static analysis (no server needed) | ❌ needs running server | ✅ |
|
|
16
|
+
| BEM selector support | ❌ | ✅ |
|
|
17
|
+
| HAML / Slim support | ❌ | ✅ |
|
|
18
|
+
| ViewComponent / Phlex support | ❌ | ✅ |
|
|
19
|
+
| Stimulus JS class detection | ❌ | ✅ |
|
|
20
|
+
| ERB dynamic class extraction | ❌ | ✅ |
|
|
21
|
+
| Source file attribution | ❌ | ✅ |
|
|
22
|
+
| CI exit code support | ❌ | ✅ |
|
|
23
|
+
| Regex ignore patterns | ❌ | ✅ |
|
|
24
|
+
| Extension false-positive protection | ❌ | ✅ |
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
# Gemfile
|
|
32
|
+
gem "rails-css_unused", group: :development
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
bundle install
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
# Standard report
|
|
45
|
+
bundle exec rake css_unused:report
|
|
46
|
+
|
|
47
|
+
# With source file for each ghost class
|
|
48
|
+
bundle exec rake css_unused:report_verbose
|
|
49
|
+
|
|
50
|
+
# CI — exits with code 1 if any ghost classes found
|
|
51
|
+
bundle exec rake css_unused:ci
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Programmatic usage
|
|
55
|
+
|
|
56
|
+
```ruby
|
|
57
|
+
# List ghost class names
|
|
58
|
+
Rails::CssUnused.ghost_classes # => ["old-btn", "legacy-card"]
|
|
59
|
+
|
|
60
|
+
# Full report to custom IO
|
|
61
|
+
Rails::CssUnused.report(output: File.open("report.txt", "w"))
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Configuration
|
|
67
|
+
|
|
68
|
+
Create `config/initializers/css_unused.rb`:
|
|
69
|
+
|
|
70
|
+
```ruby
|
|
71
|
+
Rails::CssUnused.configure do |config|
|
|
72
|
+
# Paths to scan (relative to Rails.root)
|
|
73
|
+
config.stylesheet_paths = %w[app/assets/stylesheets app/assets/builds]
|
|
74
|
+
config.view_paths = %w[app/views]
|
|
75
|
+
config.component_paths = %w[app/components]
|
|
76
|
+
config.javascript_paths = %w[app/javascript]
|
|
77
|
+
|
|
78
|
+
# Exact class names to never flag as ghost
|
|
79
|
+
config.ignore_classes = %w[
|
|
80
|
+
clearfix sr-only visually-hidden
|
|
81
|
+
active disabled selected
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
# Regex patterns — any matching class is ignored
|
|
85
|
+
config.ignore_patterns = [
|
|
86
|
+
/\Ajs-/, # JS hook classes (js-submit-btn)
|
|
87
|
+
/\Ais-/, # state classes (is-active, is-open)
|
|
88
|
+
/\Ahas-/, # state classes (has-error)
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
# Detect classes added via classList.add() in JS files
|
|
92
|
+
config.scan_javascript_for_classes = true
|
|
93
|
+
|
|
94
|
+
# Scan ViewComponent .rb files for class: attributes
|
|
95
|
+
config.scan_ruby_components = true
|
|
96
|
+
|
|
97
|
+
# Show which stylesheet each ghost class came from
|
|
98
|
+
config.show_source_files = false
|
|
99
|
+
|
|
100
|
+
# Exit with code 1 in CI when ghosts are found
|
|
101
|
+
config.fail_on_unused = false
|
|
102
|
+
end
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## What is a "ghost class"?
|
|
108
|
+
|
|
109
|
+
A ghost class is a CSS class that is:
|
|
110
|
+
- ✅ **Defined** in a `.css`, `.scss`, or `.sass` file
|
|
111
|
+
- ❌ **Never referenced** in any `.erb`, `.haml`, `.slim`, `.rb`, or `.js` file
|
|
112
|
+
|
|
113
|
+
Ghost classes add dead weight to your CSS bundle and confuse future developers.
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Reducing false positives
|
|
118
|
+
|
|
119
|
+
Some classes are legitimately hard to detect statically:
|
|
120
|
+
|
|
121
|
+
| Situation | Solution |
|
|
122
|
+
|-----------|----------|
|
|
123
|
+
| `class="status-#{record.state}"` | Add `ignore_patterns << /\Astatus-/` |
|
|
124
|
+
| JS-only classes (e.g. `js-modal-open`) | Add `ignore_patterns << /\Ajs-/` or enable `scan_javascript_for_classes` |
|
|
125
|
+
| Third-party component classes | Add prefix pattern to `ignore_patterns` |
|
|
126
|
+
| Turbo / Stimulus data-action targets | Add to `ignore_classes` |
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## License
|
|
131
|
+
|
|
132
|
+
MIT
|
|
@@ -1,45 +1,97 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Rails
|
|
4
|
-
module CssUnused
|
|
5
|
-
class Configuration
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rails
|
|
4
|
+
module CssUnused
|
|
5
|
+
class Configuration
|
|
6
|
+
# File extensions treated as view templates
|
|
7
|
+
VIEW_EXTENSIONS = %w[.erb .haml .slim].freeze
|
|
8
|
+
# Compound view extensions (e.g. foo.html.erb)
|
|
9
|
+
COMPOUND_VIEW_ENDINGS = %w[.html.erb .html.haml .html.slim].freeze
|
|
10
|
+
# CSS/preprocessor extensions to scan
|
|
11
|
+
CSS_EXTENSIONS = %w[.css .scss .sass].freeze
|
|
12
|
+
# Ruby component file extensions
|
|
13
|
+
COMPONENT_EXTENSIONS = %w[.rb].freeze
|
|
14
|
+
|
|
15
|
+
# ── Scan paths ────────────────────────────────────────────────────────
|
|
16
|
+
# Directories to search for view templates (relative to project root).
|
|
17
|
+
attr_accessor :view_paths
|
|
18
|
+
|
|
19
|
+
# Directories to search for ViewComponent / Phlex / etc. template files.
|
|
20
|
+
attr_accessor :component_paths
|
|
21
|
+
|
|
22
|
+
# Directories to search for stylesheets.
|
|
23
|
+
attr_accessor :stylesheet_paths
|
|
24
|
+
|
|
25
|
+
# Directories to search for JS files (e.g. Stimulus controllers that
|
|
26
|
+
# add classes dynamically — detected as allowlisted dynamic patterns).
|
|
27
|
+
attr_accessor :javascript_paths
|
|
28
|
+
|
|
29
|
+
# ── Ignore lists ─────────────────────────────────────────────────────
|
|
30
|
+
# Exact class names to always treat as "used" (never reported as ghost).
|
|
31
|
+
# Good for: utility classes, JS-hook classes, server-side rendered classes.
|
|
32
|
+
attr_accessor :ignore_classes
|
|
33
|
+
|
|
34
|
+
# Regex patterns — any CSS class name matching any pattern is ignored.
|
|
35
|
+
# Good for: third-party prefixes, state classes, BEM modifier variants.
|
|
36
|
+
# Example: [/\Ajs-/, /\Ais-/, /\Ahas-/]
|
|
37
|
+
attr_accessor :ignore_patterns
|
|
38
|
+
|
|
39
|
+
# ── Dynamic class detection ───────────────────────────────────────────
|
|
40
|
+
# When true, scan JS/Stimulus files for string literals that look like
|
|
41
|
+
# CSS class names and add them to the used-class set automatically.
|
|
42
|
+
attr_accessor :scan_javascript_for_classes
|
|
43
|
+
|
|
44
|
+
# When true, scan Ruby component files (.rb) for string literals that
|
|
45
|
+
# look like CSS classes passed to html attributes.
|
|
46
|
+
attr_accessor :scan_ruby_components
|
|
47
|
+
|
|
48
|
+
# ── Output ───────────────────────────────────────────────────────────
|
|
49
|
+
# When true, show which file each ghost class was defined in.
|
|
50
|
+
attr_accessor :show_source_files
|
|
51
|
+
|
|
52
|
+
# When true, exit with code 1 if any ghost classes are found.
|
|
53
|
+
# Useful for CI pipelines.
|
|
54
|
+
attr_accessor :fail_on_unused
|
|
55
|
+
|
|
56
|
+
def initialize
|
|
57
|
+
@view_paths = %w[app/views]
|
|
58
|
+
@component_paths = %w[app/components]
|
|
59
|
+
@stylesheet_paths = %w[app/assets/stylesheets app/assets/builds]
|
|
60
|
+
@javascript_paths = %w[app/javascript]
|
|
61
|
+
|
|
62
|
+
@ignore_classes = %w[
|
|
63
|
+
clearfix sr-only visually-hidden
|
|
64
|
+
active disabled selected current open closed
|
|
65
|
+
show hide hidden visible
|
|
66
|
+
fade collapse collapsing
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
@ignore_patterns = [
|
|
70
|
+
/\Ajs-/, # JS-hook classes
|
|
71
|
+
/\Ais-/, # state classes (is-active, is-open)
|
|
72
|
+
/\Ahas-/, # state classes (has-error)
|
|
73
|
+
/\Adata-/, # sometimes leaked into CSS scanners
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
@scan_javascript_for_classes = true
|
|
77
|
+
@scan_ruby_components = true
|
|
78
|
+
@show_source_files = false
|
|
79
|
+
@fail_on_unused = false
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
class << self
|
|
84
|
+
def configuration
|
|
85
|
+
@configuration ||= Configuration.new
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def configure
|
|
89
|
+
yield(configuration)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def reset_configuration!
|
|
93
|
+
@configuration = nil
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Rails
|
|
4
|
-
module CssUnused
|
|
5
|
-
class Railtie < Rails::Railtie
|
|
6
|
-
rake_tasks do
|
|
7
|
-
load File.expand_path("tasks.rake", __dir__)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rails
|
|
4
|
+
module CssUnused
|
|
5
|
+
class Railtie < Rails::Railtie
|
|
6
|
+
rake_tasks do
|
|
7
|
+
load File.expand_path("tasks.rake", __dir__)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# Support configuration via config/initializers/css_unused.rb:
|
|
11
|
+
#
|
|
12
|
+
# Rails::CssUnused.configure do |c|
|
|
13
|
+
# c.fail_on_unused = true
|
|
14
|
+
# c.show_source_files = true
|
|
15
|
+
# c.ignore_patterns << /\Ashopify-/
|
|
16
|
+
# c.scan_javascript_for_classes = true
|
|
17
|
+
# end
|
|
18
|
+
#
|
|
19
|
+
initializer "rails_css_unused.configuration" do
|
|
20
|
+
# Nothing auto-applied — users configure via Rails::CssUnused.configure.
|
|
21
|
+
# The Railtie merely makes rake tasks available.
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|