erblint-agent 0.1.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 +7 -0
- data/.claude/claude-on-edit.config.js +5 -0
- data/.claude/settings.json +16 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +141 -0
- data/Rakefile +12 -0
- data/config/default.yml +9 -0
- data/lib/erblint/agent/linters/agent/no_direct_emoji.rb +58 -0
- data/lib/erblint/agent/linters/agent/no_direct_svg_tag.rb +53 -0
- data/lib/erblint/agent/linters/agent/no_specific_classes.rb +82 -0
- data/lib/erblint/agent/linters/custom_helpers.rb +30 -0
- data/lib/erblint/agent/linters.rb +3 -0
- data/lib/erblint/agent/version.rb +7 -0
- data/lib/erblint/agent.rb +10 -0
- data/sig/erblint/agent.rbs +6 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dab7aae7630db6b927841603dd064ee18d5353b9fadee086a4520faf866e31a1
|
4
|
+
data.tar.gz: af9c3fd02b3539aa3a1ea10fc855e0fe3a6b2dd170f54de8677d5acb8e8f94e7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 70097e217e9e7d44594db1df35cb089da6c2b0a9a43df53e9fe3b7572de4af25010fb19a9f14ba17f43b00efa2a4c236610c00300501da4b699eea801415e9d2
|
7
|
+
data.tar.gz: f97609874644a3706500d5e8784fcf11c57f61732501618db0a1642a5850e8b6d5987075acbb129666837ce62bbcd9f07326da799492547d72b20dace75697a1
|
@@ -0,0 +1,16 @@
|
|
1
|
+
{
|
2
|
+
"hooks": {
|
3
|
+
"PostToolUse": [
|
4
|
+
{
|
5
|
+
"matcher": "(Write|Edit|MultiEdit)",
|
6
|
+
"hooks": [
|
7
|
+
{
|
8
|
+
"type": "command",
|
9
|
+
"command": "npx -y @aki77/claude-on-edit"
|
10
|
+
}
|
11
|
+
]
|
12
|
+
}
|
13
|
+
]
|
14
|
+
},
|
15
|
+
"$schema": "https://json.schemastore.org/claude-code-settings.json"
|
16
|
+
}
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 aki
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
# Erblint::Agent
|
2
|
+
|
3
|
+
Template style checking for Ruby projects aimed at AI agents.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
group :development do
|
11
|
+
gem 'erb_lint', require: false
|
12
|
+
gem 'erblint-agent', require: false
|
13
|
+
end
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
```bash
|
19
|
+
bundle install
|
20
|
+
```
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
### Configuration
|
25
|
+
|
26
|
+
Require the lint rules from this library. Currently, the only supported way is to add a new file in `.erb-linters/erblint_agent.rb` with the line:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'erblint/agent/linters'
|
30
|
+
```
|
31
|
+
|
32
|
+
Create or update your `.erb-lint.yml` configuration file:
|
33
|
+
|
34
|
+
```yaml
|
35
|
+
---
|
36
|
+
inherit_gem:
|
37
|
+
erblint-agent:
|
38
|
+
- config/default.yml
|
39
|
+
linters:
|
40
|
+
Agent::NoDirectSvgTag:
|
41
|
+
# message: "Custom error message" # Optional: customize the error message
|
42
|
+
|
43
|
+
Agent::NoDirectEmoji:
|
44
|
+
# message: "Custom error message" # Optional: customize the error message
|
45
|
+
|
46
|
+
Agent::NoSpecificClasses:
|
47
|
+
forbidden_classes:
|
48
|
+
"card": "Use 'CardComponent' instead"
|
49
|
+
```
|
50
|
+
|
51
|
+
### Running the Linters
|
52
|
+
|
53
|
+
Run erb-lint with:
|
54
|
+
|
55
|
+
```bash
|
56
|
+
bundle exec erb_lint --lint-all
|
57
|
+
```
|
58
|
+
|
59
|
+
Or check specific files:
|
60
|
+
|
61
|
+
```bash
|
62
|
+
bundle exec erb_lint app/views/**/*.erb
|
63
|
+
```
|
64
|
+
|
65
|
+
## Available Linters
|
66
|
+
|
67
|
+
### Agent::NoDirectSvgTag
|
68
|
+
|
69
|
+
Prohibits direct use of SVG tags. Recommends using Tailwind CSS Icons instead.
|
70
|
+
|
71
|
+
**Configuration:**
|
72
|
+
```yaml
|
73
|
+
Agent::NoDirectSvgTag:
|
74
|
+
enabled: true
|
75
|
+
message: "Custom error message" # Optional: override default message
|
76
|
+
```
|
77
|
+
|
78
|
+
**Bad:**
|
79
|
+
```erb
|
80
|
+
<svg>...</svg>
|
81
|
+
<svg class="icon" />
|
82
|
+
```
|
83
|
+
|
84
|
+
**Good:**
|
85
|
+
```erb
|
86
|
+
<span class="i-bi-people"></span>
|
87
|
+
```
|
88
|
+
|
89
|
+
### Agent::NoDirectEmoji
|
90
|
+
|
91
|
+
Prohibits direct use of Unicode emojis. Recommends using icon classes instead.
|
92
|
+
|
93
|
+
**Configuration:**
|
94
|
+
```yaml
|
95
|
+
Agent::NoDirectEmoji:
|
96
|
+
enabled: true
|
97
|
+
message: "Custom error message" # Optional: override default message
|
98
|
+
```
|
99
|
+
|
100
|
+
**Bad:**
|
101
|
+
```erb
|
102
|
+
<p>Welcome! 😊</p>
|
103
|
+
```
|
104
|
+
|
105
|
+
**Good:**
|
106
|
+
```erb
|
107
|
+
<p>Welcome! <span class="i-bi-emoji-smile"></span></p>
|
108
|
+
```
|
109
|
+
|
110
|
+
### Agent::NoSpecificClasses
|
111
|
+
|
112
|
+
Prohibits the use of specific class names defined in configuration.
|
113
|
+
|
114
|
+
**Configuration:**
|
115
|
+
```yaml
|
116
|
+
Agent::NoSpecificClasses:
|
117
|
+
enabled: true
|
118
|
+
forbidden_classes:
|
119
|
+
"btn-old": "Use 'btn' class instead"
|
120
|
+
"text-bold": "Use 'font-bold' instead"
|
121
|
+
```
|
122
|
+
|
123
|
+
**Bad:**
|
124
|
+
```erb
|
125
|
+
<button class="btn-old">Click</button>
|
126
|
+
<p class="text-bold">Important</p>
|
127
|
+
```
|
128
|
+
|
129
|
+
**Good:**
|
130
|
+
```erb
|
131
|
+
<button class="btn">Click</button>
|
132
|
+
<p class="font-bold">Important</p>
|
133
|
+
```
|
134
|
+
|
135
|
+
## License
|
136
|
+
|
137
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
138
|
+
|
139
|
+
## Code of Conduct
|
140
|
+
|
141
|
+
Everyone interacting in the Erblint::Agent project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/aki77/erblint-agent/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/config/default.yml
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "erb_lint"
|
4
|
+
require "erb_lint/linter"
|
5
|
+
require "erb_lint/linter_registry"
|
6
|
+
require "erb_lint/linter_config"
|
7
|
+
require_relative "../custom_helpers"
|
8
|
+
|
9
|
+
module ERBLint
|
10
|
+
module Linters
|
11
|
+
module Agent
|
12
|
+
# This class is a custom ERBLint linter that prohibits direct usage of emojis in ERB templates.
|
13
|
+
# Instead of writing emojis directly, it encourages the use of appropriate helpers or components.
|
14
|
+
# It detects violations and reports them as offenses within ERBLint.
|
15
|
+
class NoDirectEmoji < ERBLint::Linter
|
16
|
+
include ERBLint::Linters::Agent::CustomHelpers
|
17
|
+
include ERBLint::LinterRegistry
|
18
|
+
|
19
|
+
# Configuration schema for NoDirectEmoji linter
|
20
|
+
class ConfigSchema < ERBLint::LinterConfig
|
21
|
+
property :message, accepts: String, default: nil
|
22
|
+
end
|
23
|
+
|
24
|
+
self.config_schema = ConfigSchema
|
25
|
+
|
26
|
+
MESSAGE = "Direct emoji usage is prohibited. " \
|
27
|
+
"Use Tailwind CSS Icons (i-bi-* classes) instead. " \
|
28
|
+
"Example: <span class=\"i-bi-emoji-smile\"></span>"
|
29
|
+
|
30
|
+
EMOJI_REGEX = /[\u{1F300}-\u{1F9FF}]| # Miscellaneous emojis
|
31
|
+
[\u{2600}-\u{26FF}]| # Various symbols
|
32
|
+
[\u{2700}-\u{27BF}]| # Dingbats
|
33
|
+
[\u{1F000}-\u{1F02F}]| # Mahjong tiles
|
34
|
+
[\u{1FA70}-\u{1FAFF}]| # Extended emojis
|
35
|
+
[\u{2300}-\u{23FF}]/x # Technical symbols
|
36
|
+
|
37
|
+
def run(processed_source)
|
38
|
+
file_content = processed_source.file_content
|
39
|
+
|
40
|
+
scan_emoji_pattern(processed_source, file_content)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def scan_emoji_pattern(processed_source, file_content)
|
46
|
+
file_content.scan(EMOJI_REGEX) do |_match|
|
47
|
+
match_data = Regexp.last_match
|
48
|
+
|
49
|
+
add_offense(
|
50
|
+
processed_source.to_source_range(match_data.begin(0)...match_data.end(0)),
|
51
|
+
@config.message || MESSAGE
|
52
|
+
)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "erb_lint"
|
4
|
+
require "erb_lint/linter"
|
5
|
+
require "erb_lint/linter_registry"
|
6
|
+
require "erb_lint/linter_config"
|
7
|
+
require_relative "../custom_helpers"
|
8
|
+
|
9
|
+
module ERBLint
|
10
|
+
module Linters
|
11
|
+
module Agent
|
12
|
+
# Linter that prohibits direct usage of <svg> tags in ERB templates.
|
13
|
+
class NoDirectSvgTag < ERBLint::Linter
|
14
|
+
include ERBLint::Linters::Agent::CustomHelpers
|
15
|
+
include ERBLint::LinterRegistry
|
16
|
+
|
17
|
+
# Configuration schema for NoDirectSvgTag linter
|
18
|
+
class ConfigSchema < ERBLint::LinterConfig
|
19
|
+
property :message, accepts: String, default: nil
|
20
|
+
end
|
21
|
+
|
22
|
+
self.config_schema = ConfigSchema
|
23
|
+
|
24
|
+
MESSAGE = "Direct SVG tag usage is prohibited. " \
|
25
|
+
"Use Tailwind CSS Icons (i-bi-* classes) instead. " \
|
26
|
+
"Example: <span class=\"i-bi-people\"></span>"
|
27
|
+
|
28
|
+
SELF_CLOSING_SVG_REGEX = %r{<svg\b[^>]*/\s*>}mi
|
29
|
+
PAIRED_SVG_REGEX = %r{<svg\b[^>]*>.*?</svg\s*>}mi
|
30
|
+
|
31
|
+
def run(processed_source)
|
32
|
+
file_content = processed_source.file_content
|
33
|
+
|
34
|
+
scan_svg_pattern(processed_source, file_content, SELF_CLOSING_SVG_REGEX)
|
35
|
+
scan_svg_pattern(processed_source, file_content, PAIRED_SVG_REGEX)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def scan_svg_pattern(processed_source, file_content, regex)
|
41
|
+
file_content.scan(regex) do |_match|
|
42
|
+
match_data = Regexp.last_match
|
43
|
+
|
44
|
+
add_offense(
|
45
|
+
processed_source.to_source_range(match_data.begin(0)...match_data.end(0)),
|
46
|
+
@config.message || MESSAGE
|
47
|
+
)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "erb_lint"
|
4
|
+
require "erb_lint/linter"
|
5
|
+
require "erb_lint/linter_registry"
|
6
|
+
require "erb_lint/linter_config"
|
7
|
+
require_relative "../custom_helpers"
|
8
|
+
|
9
|
+
module ERBLint
|
10
|
+
module Linters
|
11
|
+
module Agent
|
12
|
+
# Linter that checks for forbidden CSS class names in ERB templates.
|
13
|
+
class NoSpecificClasses < ERBLint::Linter
|
14
|
+
include ERBLint::Linters::Agent::CustomHelpers
|
15
|
+
include ERBLint::LinterRegistry
|
16
|
+
|
17
|
+
class ConfigSchema < ERBLint::LinterConfig # rubocop:disable Style/Documentation
|
18
|
+
property :forbidden_classes, accepts: Hash, default: -> { {} }
|
19
|
+
end
|
20
|
+
|
21
|
+
self.config_schema = ConfigSchema
|
22
|
+
|
23
|
+
CLASS_ATTR_REGEX = /class\s*=\s*["']([^"']+)["']/i
|
24
|
+
ERB_CLASS_REGEX = /class\s*=\s*["']([^"']*<%[^>]*%>[^"']*)["']/i
|
25
|
+
DYNAMIC_CLASS_REGEX = /class:\s*["']([^"']+)["']/
|
26
|
+
|
27
|
+
def run(processed_source)
|
28
|
+
return if @config.forbidden_classes.empty?
|
29
|
+
|
30
|
+
file_content = processed_source.file_content
|
31
|
+
|
32
|
+
scan_class_attributes(processed_source, file_content, CLASS_ATTR_REGEX)
|
33
|
+
scan_class_attributes(processed_source, file_content, DYNAMIC_CLASS_REGEX)
|
34
|
+
scan_erb_class_attributes(processed_source, file_content)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def scan_class_attributes(processed_source, file_content, regex)
|
40
|
+
file_content.scan(regex) do |classes|
|
41
|
+
match_data = Regexp.last_match
|
42
|
+
class_list = classes[0]
|
43
|
+
|
44
|
+
next if class_list.include?("<%")
|
45
|
+
|
46
|
+
check_forbidden_classes(processed_source, class_list, match_data)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def scan_erb_class_attributes(processed_source, file_content)
|
51
|
+
file_content.scan(ERB_CLASS_REGEX) do |classes|
|
52
|
+
match_data = Regexp.last_match
|
53
|
+
class_list = classes[0]
|
54
|
+
|
55
|
+
static_parts = class_list.split(/<%[^>]*%>/)
|
56
|
+
static_parts.each do |part|
|
57
|
+
check_forbidden_classes(processed_source, part, match_data) unless part.strip.empty?
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def check_forbidden_classes(processed_source, class_list, match_data) # rubocop:disable Metrics/MethodLength
|
63
|
+
class_names = class_list.split(/\s+/)
|
64
|
+
|
65
|
+
class_names.each do |class_name|
|
66
|
+
class_name = class_name.strip
|
67
|
+
next if class_name.empty?
|
68
|
+
|
69
|
+
next unless @config.forbidden_classes.key?(class_name)
|
70
|
+
|
71
|
+
message = @config.forbidden_classes[class_name]
|
72
|
+
|
73
|
+
add_offense(
|
74
|
+
processed_source.to_source_range(match_data.begin(0)...match_data.end(0)),
|
75
|
+
"Class name '#{class_name}' is prohibited. #{message}"
|
76
|
+
)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ERBLint
|
4
|
+
module Linters
|
5
|
+
module Agent
|
6
|
+
# Provides custom helper methods for ERB linting agents.
|
7
|
+
module CustomHelpers
|
8
|
+
def generate_offense(klass, processed_source, tag, message = nil, replacement = nil)
|
9
|
+
message ||= klass::MESSAGE
|
10
|
+
offense = ["#{simple_class_name}:#{message}", tag.node.loc.source].join("\n")
|
11
|
+
add_offense(processed_source.to_source_range(tag.loc), offense, replacement)
|
12
|
+
end
|
13
|
+
|
14
|
+
def generate_offense_from_source_range(klass, source_range, message = nil, replacement = nil)
|
15
|
+
message ||= klass::MESSAGE
|
16
|
+
offense = ["#{simple_class_name}:#{message}", source_range.source].join("\n")
|
17
|
+
add_offense(source_range, offense, replacement)
|
18
|
+
end
|
19
|
+
|
20
|
+
def tags(processed_source)
|
21
|
+
processed_source.parser.nodes_with_type(:tag).map { |tag_node| BetterHtml::Tree::Tag.from_node(tag_node) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def simple_class_name
|
25
|
+
self.class.name.gsub("ERBLint::Linters::", "")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: erblint-agent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- aki77
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 2025-08-29 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: better_html
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '2.0'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '2.0'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: erb_lint
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.3.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.3.0
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: rake
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: rspec
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
type: :development
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: rubocop
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
type: :development
|
76
|
+
prerelease: false
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
description: A collection of ERB template linters designed for AI agent Ruby projects,
|
83
|
+
enforcing consistent style and best practices including SVG tag restrictions, emoji
|
84
|
+
usage controls, and class naming conventions
|
85
|
+
email:
|
86
|
+
- aki77@users.noreply.github.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".claude/claude-on-edit.config.js"
|
92
|
+
- ".claude/settings.json"
|
93
|
+
- ".rspec"
|
94
|
+
- ".rubocop.yml"
|
95
|
+
- CODE_OF_CONDUCT.md
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- config/default.yml
|
100
|
+
- lib/erblint/agent.rb
|
101
|
+
- lib/erblint/agent/linters.rb
|
102
|
+
- lib/erblint/agent/linters/agent/no_direct_emoji.rb
|
103
|
+
- lib/erblint/agent/linters/agent/no_direct_svg_tag.rb
|
104
|
+
- lib/erblint/agent/linters/agent/no_specific_classes.rb
|
105
|
+
- lib/erblint/agent/linters/custom_helpers.rb
|
106
|
+
- lib/erblint/agent/version.rb
|
107
|
+
- sig/erblint/agent.rbs
|
108
|
+
homepage: https://github.com/aki77/erblint-agent
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata:
|
112
|
+
homepage_uri: https://github.com/aki77/erblint-agent
|
113
|
+
source_code_uri: https://github.com/aki77/erblint-agent
|
114
|
+
changelog_uri: https://github.com/aki77/erblint-agent/releases
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 3.3.0
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubygems_version: 3.6.2
|
130
|
+
specification_version: 4
|
131
|
+
summary: Template style checking for Ruby projects aimed at AI agents
|
132
|
+
test_files: []
|