erblint-agent 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dab7aae7630db6b927841603dd064ee18d5353b9fadee086a4520faf866e31a1
4
- data.tar.gz: af9c3fd02b3539aa3a1ea10fc855e0fe3a6b2dd170f54de8677d5acb8e8f94e7
3
+ metadata.gz: 505dda0e7e1058b2761febf76b63ce61cfb7cde94cfc1813668db8940a5d4cf0
4
+ data.tar.gz: 07e5c14c07ed1dc3de33aa2e0fa115c02be48c4520702c0c319e49d49cc9e765
5
5
  SHA512:
6
- metadata.gz: 70097e217e9e7d44594db1df35cb089da6c2b0a9a43df53e9fe3b7572de4af25010fb19a9f14ba17f43b00efa2a4c236610c00300501da4b699eea801415e9d2
7
- data.tar.gz: f97609874644a3706500d5e8784fcf11c57f61732501618db0a1642a5850e8b6d5987075acbb129666837ce62bbcd9f07326da799492547d72b20dace75697a1
6
+ metadata.gz: 91f0cf7065d397483d00955f6496305c451af46680d55250f497ca58db0cd64d59305e533c1361247ba5b2c6df71f50ec466667c3d66d9701cd74102defd0914
7
+ data.tar.gz: '059cc04d90445570be6d964bde7549c9104c62914d4d07d2a92ab73cf4fe740a61ee68d5a26900ba674d15951edb495eb13a85677236962d9654b0f63c7946aa'
@@ -1,5 +1,5 @@
1
1
  export default {
2
- "lib/**/*.rb": [
2
+ "{lib,spec}/**/*.rb": [
3
3
  "bundle exec rubocop -a"
4
4
  ],
5
5
  };
data/README.md CHANGED
@@ -46,6 +46,10 @@ linters:
46
46
  Agent::NoSpecificClasses:
47
47
  forbidden_classes:
48
48
  "card": "Use 'CardComponent' instead"
49
+
50
+ Agent::NoSpecificAttributes:
51
+ forbidden_attributes:
52
+ "onclick": "Use event listeners instead"
49
53
  ```
50
54
 
51
55
  ### Running the Linters
@@ -132,6 +136,31 @@ Agent::NoSpecificClasses:
132
136
  <p class="font-bold">Important</p>
133
137
  ```
134
138
 
139
+ ### Agent::NoSpecificAttributes
140
+
141
+ Prohibits the use of specific HTML attributes defined in configuration.
142
+
143
+ **Configuration:**
144
+ ```yaml
145
+ Agent::NoSpecificAttributes:
146
+ enabled: true
147
+ forbidden_attributes:
148
+ "data-testid": "Use 'data-test-selector' attribute instead"
149
+ "onclick": "Use event listeners instead"
150
+ ```
151
+
152
+ **Bad:**
153
+ ```erb
154
+ <button data-testid="submit-btn">Submit</button>
155
+ <div onclick="handleClick()">Click me</div>
156
+ ```
157
+
158
+ **Good:**
159
+ ```erb
160
+ <button data-test-selector="submit-btn">Submit</button>
161
+ <div data-action="click->controller#handleClick">Click me</div>
162
+ ```
163
+
135
164
  ## License
136
165
 
137
166
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/config/default.yml CHANGED
@@ -7,3 +7,6 @@ linters:
7
7
 
8
8
  Agent::NoSpecificClasses:
9
9
  enabled: true
10
+
11
+ Agent::NoSpecificAttributes:
12
+ enabled: true
@@ -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 checks for forbidden HTML attributes in ERB templates.
13
+ class NoSpecificAttributes < 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_attributes, accepts: Hash, default: -> { {} }
19
+ end
20
+
21
+ self.config_schema = ConfigSchema
22
+
23
+ ATTR_REGEX = /(\w+(?:-\w+)*)\s*=\s*["']/
24
+
25
+ def run(processed_source)
26
+ return if @config.forbidden_attributes.empty?
27
+
28
+ file_content = processed_source.file_content
29
+
30
+ scan_attributes(processed_source, file_content)
31
+ end
32
+
33
+ private
34
+
35
+ def scan_attributes(processed_source, file_content)
36
+ file_content.scan(ATTR_REGEX) do |attr_name|
37
+ match_data = Regexp.last_match
38
+ attribute_name = attr_name[0]
39
+
40
+ next unless @config.forbidden_attributes.key?(attribute_name)
41
+
42
+ message = @config.forbidden_attributes[attribute_name]
43
+
44
+ add_offense(
45
+ processed_source.to_source_range(match_data.begin(0)...match_data.end(0)),
46
+ "Attribute '#{attribute_name}' is prohibited. #{message}"
47
+ )
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Erblint
4
4
  module Agent
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erblint-agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - aki77
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-08-29 00:00:00.000000000 Z
10
+ date: 2025-09-30 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: better_html
@@ -101,6 +101,7 @@ files:
101
101
  - lib/erblint/agent/linters.rb
102
102
  - lib/erblint/agent/linters/agent/no_direct_emoji.rb
103
103
  - lib/erblint/agent/linters/agent/no_direct_svg_tag.rb
104
+ - lib/erblint/agent/linters/agent/no_specific_attributes.rb
104
105
  - lib/erblint/agent/linters/agent/no_specific_classes.rb
105
106
  - lib/erblint/agent/linters/custom_helpers.rb
106
107
  - lib/erblint/agent/version.rb