@herb-tools/linter 0.6.0 → 0.7.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.
Files changed (99) hide show
  1. package/README.md +60 -16
  2. package/dist/herb-lint.js +1684 -295
  3. package/dist/herb-lint.js.map +1 -1
  4. package/dist/index.cjs +1226 -158
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.js +1188 -160
  7. package/dist/index.js.map +1 -1
  8. package/dist/package.json +11 -4
  9. package/dist/src/cli/argument-parser.js +11 -6
  10. package/dist/src/cli/argument-parser.js.map +1 -1
  11. package/dist/src/cli/file-processor.js +5 -6
  12. package/dist/src/cli/file-processor.js.map +1 -1
  13. package/dist/src/cli/formatters/detailed-formatter.js +3 -5
  14. package/dist/src/cli/formatters/detailed-formatter.js.map +1 -1
  15. package/dist/src/cli/formatters/github-actions-formatter.js +55 -11
  16. package/dist/src/cli/formatters/github-actions-formatter.js.map +1 -1
  17. package/dist/src/cli/index.js +1 -0
  18. package/dist/src/cli/index.js.map +1 -1
  19. package/dist/src/cli/output-manager.js +23 -5
  20. package/dist/src/cli/output-manager.js.map +1 -1
  21. package/dist/src/cli/summary-reporter.js +2 -11
  22. package/dist/src/cli/summary-reporter.js.map +1 -1
  23. package/dist/src/cli.js +88 -4
  24. package/dist/src/cli.js.map +1 -1
  25. package/dist/src/default-rules.js +8 -4
  26. package/dist/src/default-rules.js.map +1 -1
  27. package/dist/src/linter.js.map +1 -1
  28. package/dist/src/rules/erb-prefer-image-tag-helper.js +50 -60
  29. package/dist/src/rules/erb-prefer-image-tag-helper.js.map +1 -1
  30. package/dist/src/rules/html-boolean-attributes-no-value.js +8 -8
  31. package/dist/src/rules/html-boolean-attributes-no-value.js.map +1 -1
  32. package/dist/src/rules/html-no-duplicate-ids.js +134 -9
  33. package/dist/src/rules/html-no-duplicate-ids.js.map +1 -1
  34. package/dist/src/rules/html-no-empty-attributes.js +56 -0
  35. package/dist/src/rules/html-no-empty-attributes.js.map +1 -0
  36. package/dist/src/rules/html-no-positive-tab-index.js +1 -1
  37. package/dist/src/rules/html-no-positive-tab-index.js.map +1 -1
  38. package/dist/src/rules/html-no-self-closing.js +12 -5
  39. package/dist/src/rules/html-no-self-closing.js.map +1 -1
  40. package/dist/src/rules/html-no-underscores-in-attribute-names.js +36 -0
  41. package/dist/src/rules/html-no-underscores-in-attribute-names.js.map +1 -0
  42. package/dist/src/rules/index.js +3 -0
  43. package/dist/src/rules/index.js.map +1 -1
  44. package/dist/src/rules/rule-utils.js +80 -7
  45. package/dist/src/rules/rule-utils.js.map +1 -1
  46. package/dist/src/rules/svg-tag-name-capitalization.js +2 -2
  47. package/dist/src/rules/svg-tag-name-capitalization.js.map +1 -1
  48. package/dist/tsconfig.tsbuildinfo +1 -1
  49. package/dist/types/cli/argument-parser.d.ts +2 -1
  50. package/dist/types/cli/file-processor.d.ts +6 -1
  51. package/dist/types/cli/formatters/github-actions-formatter.d.ts +6 -1
  52. package/dist/types/cli/index.d.ts +1 -0
  53. package/dist/types/cli/output-manager.d.ts +1 -0
  54. package/dist/types/cli.d.ts +20 -5
  55. package/dist/types/linter.d.ts +7 -7
  56. package/dist/types/rules/html-no-empty-attributes.d.ts +7 -0
  57. package/dist/types/rules/html-no-underscores-in-attribute-names.d.ts +7 -0
  58. package/dist/types/rules/index.d.ts +3 -0
  59. package/dist/types/rules/rule-utils.d.ts +46 -5
  60. package/dist/types/src/cli/argument-parser.d.ts +2 -1
  61. package/dist/types/src/cli/file-processor.d.ts +6 -1
  62. package/dist/types/src/cli/formatters/github-actions-formatter.d.ts +6 -1
  63. package/dist/types/src/cli/index.d.ts +1 -0
  64. package/dist/types/src/cli/output-manager.d.ts +1 -0
  65. package/dist/types/src/cli.d.ts +20 -5
  66. package/dist/types/src/linter.d.ts +7 -7
  67. package/dist/types/src/rules/html-no-empty-attributes.d.ts +7 -0
  68. package/dist/types/src/rules/html-no-underscores-in-attribute-names.d.ts +7 -0
  69. package/dist/types/src/rules/index.d.ts +3 -0
  70. package/dist/types/src/rules/rule-utils.d.ts +46 -5
  71. package/docs/rules/README.md +2 -0
  72. package/docs/rules/html-img-require-alt.md +0 -2
  73. package/docs/rules/html-no-empty-attributes.md +77 -0
  74. package/docs/rules/html-no-underscores-in-attribute-names.md +45 -0
  75. package/package.json +11 -4
  76. package/src/cli/argument-parser.ts +15 -7
  77. package/src/cli/file-processor.ts +11 -7
  78. package/src/cli/formatters/detailed-formatter.ts +5 -7
  79. package/src/cli/formatters/github-actions-formatter.ts +64 -11
  80. package/src/cli/index.ts +2 -0
  81. package/src/cli/output-manager.ts +27 -5
  82. package/src/cli/summary-reporter.ts +3 -11
  83. package/src/cli.ts +125 -20
  84. package/src/default-rules.ts +8 -4
  85. package/src/linter.ts +6 -6
  86. package/src/rules/erb-no-silent-tag-in-attribute-name.ts +1 -1
  87. package/src/rules/erb-prefer-image-tag-helper.ts +53 -71
  88. package/src/rules/erb-require-whitespace-inside-tags.ts +2 -2
  89. package/src/rules/html-attribute-double-quotes.ts +1 -1
  90. package/src/rules/html-boolean-attributes-no-value.ts +9 -11
  91. package/src/rules/html-no-duplicate-ids.ts +188 -14
  92. package/src/rules/html-no-empty-attributes.ts +75 -0
  93. package/src/rules/html-no-positive-tab-index.ts +1 -1
  94. package/src/rules/html-no-self-closing.ts +13 -8
  95. package/src/rules/html-no-underscores-in-attribute-names.ts +58 -0
  96. package/src/rules/html-tag-name-lowercase.ts +1 -1
  97. package/src/rules/index.ts +3 -0
  98. package/src/rules/rule-utils.ts +110 -9
  99. package/src/rules/svg-tag-name-capitalization.ts +2 -2
package/README.md CHANGED
@@ -122,10 +122,15 @@ npx @herb-tools/linter template.html.erb --json
122
122
  # or
123
123
  npx @herb-tools/linter template.html.erb --format json
124
124
 
125
- # Use GitHub Actions output format
125
+ # Use GitHub Actions output format with detailed preview (default)
126
+ # (This is enabled automatically when the GITHUB_ACTIONS environment variable is set)
126
127
  npx @herb-tools/linter template.html.erb --github
127
- # or
128
- npx @herb-tools/linter template.html.erb --format github
128
+
129
+ # Combine GitHub Actions output with simple format
130
+ npx @herb-tools/linter template.html.erb --format=simple --github
131
+
132
+ # Combine GitHub Actions output with detailed format (explicit)
133
+ npx @herb-tools/linter template.html.erb --format=detailed --github
129
134
  ```
130
135
 
131
136
  **Display Options:**
@@ -144,6 +149,12 @@ npx @herb-tools/linter template.html.erb --no-wrap-lines
144
149
 
145
150
  # Enable line truncation (mutually exclusive with line wrapping)
146
151
  npx @herb-tools/linter template.html.erb --truncate-lines --no-wrap-lines
152
+
153
+ # Combine GitHub Actions annotations with different formats
154
+ npx @herb-tools/linter template.html.erb --format=simple --github
155
+
156
+ # Disable GitHub Actions annotations (even in GitHub Actions environment)
157
+ npx @herb-tools/linter template.html.erb --no-github
147
158
  ```
148
159
 
149
160
  **Help and Version:**
@@ -157,21 +168,53 @@ npx @herb-tools/linter --version
157
168
 
158
169
  #### GitHub Actions Output Format
159
170
 
160
- The linter supports GitHub Actions annotation format with the `--github` flag, which outputs errors and warnings in a format that GitHub Actions can parse to create inline annotations in pull requests:
171
+ The linter supports GitHub Actions annotation format with the `--github` flag, which can be combined with `--format=simple` or `--format=detailed`. The `--github` flag adds GitHub Actions annotations that GitHub can parse to create inline annotations in pull requests, while also showing the regular format output for local debugging.
172
+
173
+ ::: tip Tip: Running in GitHub Actions
174
+ When the `GITHUB_ACTIONS` environment variable is set (as in GitHub Actions), GitHub Actions annotations are enabled by default. You can disable them with `--no-github` if needed.
175
+ :::
161
176
 
162
177
  ```bash
163
- npx @herb-tools/linter "**/*.html.erb" --github
178
+ # GitHub Actions annotations + detailed format (default)
179
+ npx @herb-tools/linter --github
180
+
181
+ # GitHub Actions annotations + simple format (minimal local output)
182
+ npx @herb-tools/linter --format=simple --github
183
+ ```
184
+
185
+ **Example: `--github` (GitHub annotations + detailed format)**
164
186
  ```
187
+ ::error file=template.html.erb,line=3,col=3,title=html-img-require-alt • @herb-tools/linter@0.7.0::Missing required `alt` attribute on `<img>` tag [html-img-require-alt]%0A%0A%0Atemplate.html.erb:3:3%0A%0A 1 │ <div>%0A 2 │ <span>Test content</span>%0A → 3 │ <img src="test.jpg">%0A │ ~~~%0A 4 │ </div>%0A
188
+
189
+ [error] Missing required `alt` attribute on `<img>` tag [html-img-require-alt]
190
+
191
+ template.html.erb:3:3
165
192
 
166
- Example output:
193
+ 1 │ <div>
194
+ 2 │ <span>Test content</span>
195
+ → 3 │ <img src="test.jpg">
196
+ │ ~~~
197
+ 4 │ </div>
167
198
  ```
168
- ::error file=template.html.erb,line=5,col=5::File must end with trailing newline [erb-requires-trailing-newline]
169
- ::warning file=template.html.erb,line=3,col=10::Consider using semantic HTML tags [html-semantic-tags]
199
+
200
+ **Example: `--format=simple --github` (GitHub annotations + simple format)**
170
201
  ```
202
+ ::error file=template.html.erb,line=3,col=3,title=html-img-require-alt • @herb-tools/linter@0.7.0::Missing required `alt` attribute on `<img>` tag [html-img-require-alt]%0A%0A%0Atemplate.html.erb:3:3%0A%0A 1 │ <div>%0A 2 │ <span>Test content</span>%0A → 3 │ <img src="test.jpg">%0A │ ~~~%0A 4 │ </div>%0A
171
203
 
172
- This format is ideal for CI/CD workflows in GitHub Actions:
204
+ template.html.erb:
205
+ 3:3 ✗ Missing required `alt` attribute on `<img>` tag [html-img-require-alt]
206
+ ```
173
207
 
174
- ```yaml [.github/workflows/herb-lint.yml]
208
+ The GitHub Actions annotations include:
209
+ - **Embedded plain-text code previews** (with `%0A` for newlines) that GitHub renders in PR comments
210
+ - **`title` property** showing the rule code and linter version for better traceability
211
+ - **Full error context** for debugging directly in GitHub's UI
212
+
213
+ The regular format output provides colorful syntax highlighting for local terminal debugging.
214
+
215
+ This approach is ideal for CI/CD workflows as it provides both GitHub integration and local debugging:
216
+
217
+ ```yaml [.github/workflows/herb.yml]
175
218
  name: Herb Lint
176
219
  on: [push, pull_request]
177
220
 
@@ -180,8 +223,9 @@ jobs:
180
223
  runs-on: ubuntu-latest
181
224
  steps:
182
225
  - uses: actions/checkout@v4
183
- - uses: actions/setup-node@v4
184
- - run: npx @herb-tools/linter "**/*.html.erb" --github
226
+
227
+ - name: Run Herb Linter
228
+ run: npx @herb-tools/linter
185
229
  ```
186
230
 
187
231
  #### JSON Output Format
@@ -232,11 +276,11 @@ npx @herb-tools/linter template.html.erb --json
232
276
 
233
277
  JSON output fields:
234
278
  - `offenses`: Array of linting offenses with location and severity
235
- - `summary`: Statistics about the linting run (null on errors)
236
- - `timing`: Timing information with ISO timestamp (null with `--no-timing`)
279
+ - `summary`: Statistics about the linting run (`null` on errors)
280
+ - `timing`: Timing information with ISO timestamp (`null` with `--no-timing`)
237
281
  - `completed`: Whether the linter ran successfully on files
238
- - `clean`: Whether there were no offenses (null when `completed=false`)
239
- - `message`: Error or informational message (null on success)
282
+ - `clean`: Whether there were no offenses (`null` when `completed=false`)
283
+ - `message`: Error or informational message (`null` on success)
240
284
 
241
285
  ### Language Server Integration
242
286