rails-css_unused 0.1.0 → 0.2.0
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 +30 -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 +269 -117
- data/lib/rails/css_unused.rb +40 -36
- data/lib/rails-css_unused.rb +6 -3
- metadata +9 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6be69a5f6aa27dedb1aef9797167bf8b8abed066632fa8fee01fe7fefa54554c
|
|
4
|
+
data.tar.gz: c808dfa0ed3b70ad3a03ec158af1ef5d00a7bcf97ff899b6f4613853955c67fd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 62d8dff321fb2dddf72d618747b2e22511a438864b0372067c9c222442f1a39f30513a8922d014a663c4dde0955ca44614d3b9506476df78d41ef7a517ed88cb
|
|
7
|
+
data.tar.gz: 3e7e72d6cb22f7a6a1138162771cb3906e0b9a1399070131ab660b7a43286f4957faa15dd6d51b14a3981f36779264aa6da38a9ab04cbec1b8c889c189f30db8
|
data/CHANGELOG.md
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
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.0] - 2026-06-02
|
|
4
|
+
|
|
5
|
+
### 🔧 Fixed
|
|
6
|
+
- **Extension noise eliminated** — `.png`, `.css`, `.jpg`, `.js` etc. no longer appear as ghost classes
|
|
7
|
+
- **At-rule noise eliminated** — `@charset`, `@import`, `@keyframes` tokens no longer pollute the class list
|
|
8
|
+
- **`:not()` false positives fixed** — `.foo` inside `:not(.foo)` is no longer treated as a new definition
|
|
9
|
+
- **Double-scanning removed** — `ViewScanner` and `StylesheetScanner` were each instantiated twice in `print_summary`, wasting time and producing wrong counts
|
|
10
|
+
|
|
11
|
+
### ✨ Added
|
|
12
|
+
- **Source file attribution** — `show_source_files: true` shows which stylesheet each ghost comes from
|
|
13
|
+
- **CI mode** — `fail_on_unused: true` + `rake css_unused:ci` exits with code 1 on any ghost
|
|
14
|
+
- **`rake css_unused:report_verbose`** — shows ghost classes with source file inline
|
|
15
|
+
- **HAML & Slim support** — proper extraction of `.foo.bar` shorthand selectors
|
|
16
|
+
- **Slim template support** — `div.foo` class shorthand
|
|
17
|
+
- **Ruby component support** — scans ViewComponent `.rb` files for `class:` attributes
|
|
18
|
+
- **Stimulus / JS support** — `classList.add("foo")` calls detected as used classes
|
|
19
|
+
- **ERB dynamic class extraction** — `class="<%= cond ? 'a' : 'b' %>"` — static string parts extracted
|
|
20
|
+
- **`ignore_patterns`** — regex-based ignore list (e.g. `/\Ajs-/`, `/\Ais-/`)
|
|
21
|
+
- **`scan_javascript_for_classes`** — opt-in JS scanning for dynamically applied classes
|
|
22
|
+
- **`scan_ruby_components`** — opt-in scanning of `.rb` component files
|
|
23
|
+
- **Colour terminal output** — red/green/grey ANSI when outputting to a TTY
|
|
24
|
+
- **BEM double-underscore selectors** — `block__element--modifier` handled correctly
|
|
25
|
+
|
|
26
|
+
### 🗑️ Removed
|
|
27
|
+
- Confusing `stylesheet_scanner.rb` noise filter that used a hardcoded `%w[import media charset...]` list (replaced with proper context-aware skip logic)
|
|
28
|
+
|
|
29
|
+
## [0.1.0] - 2026-05-01
|
|
30
|
+
- Initial release
|
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 sghani001
|
|
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
|