@herb-tools/formatter 0.8.3 → 0.8.4
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.
- package/dist/herb-format.js +97 -22
- package/dist/herb-format.js.map +1 -1
- package/dist/index.cjs +22 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +22 -5
- package/dist/index.esm.js.map +1 -1
- package/package.json +5 -5
- package/src/cli.ts +3 -2
- package/src/format-printer.ts +25 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@herb-tools/formatter",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4",
|
|
4
4
|
"description": "Auto-formatter for HTML+ERB templates with intelligent indentation, line wrapping, and ERB-aware pretty-printing.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://herb-tools.dev",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@herb-tools/config": "0.8.
|
|
39
|
-
"@herb-tools/core": "0.8.
|
|
40
|
-
"@herb-tools/printer": "0.8.
|
|
41
|
-
"@herb-tools/rewriter": "0.8.
|
|
38
|
+
"@herb-tools/config": "0.8.4",
|
|
39
|
+
"@herb-tools/core": "0.8.4",
|
|
40
|
+
"@herb-tools/printer": "0.8.4",
|
|
41
|
+
"@herb-tools/rewriter": "0.8.4"
|
|
42
42
|
},
|
|
43
43
|
"files": [
|
|
44
44
|
"package.json",
|
package/src/cli.ts
CHANGED
|
@@ -171,9 +171,10 @@ export class CLI {
|
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
const config = await Config.loadForCLI(configFile || startPath, version)
|
|
174
|
+
const hasConfigFile = Config.exists(config.projectPath)
|
|
174
175
|
const formatterConfig = config.formatter || {}
|
|
175
176
|
|
|
176
|
-
if (formatterConfig.enabled === false && !isForceMode) {
|
|
177
|
+
if (hasConfigFile && formatterConfig.enabled === false && !isForceMode) {
|
|
177
178
|
console.log("Formatter is disabled in .herb.yml configuration.")
|
|
178
179
|
console.log("To enable formatting, set formatter.enabled: true in .herb.yml")
|
|
179
180
|
console.log("Or use --force to format anyway.")
|
|
@@ -181,7 +182,7 @@ export class CLI {
|
|
|
181
182
|
process.exit(0)
|
|
182
183
|
}
|
|
183
184
|
|
|
184
|
-
if (isForceMode && formatterConfig.enabled === false) {
|
|
185
|
+
if (isForceMode && hasConfigFile && formatterConfig.enabled === false) {
|
|
185
186
|
console.error("⚠️ Forcing formatter run (disabled in .herb.yml)")
|
|
186
187
|
console.error()
|
|
187
188
|
}
|
package/src/format-printer.ts
CHANGED
|
@@ -709,13 +709,37 @@ export class FormatPrinter extends Printer {
|
|
|
709
709
|
* Render multiline attributes for a tag
|
|
710
710
|
*/
|
|
711
711
|
private renderMultilineAttributes(tagName: string, allChildren: Node[] = [], isSelfClosing: boolean = false,) {
|
|
712
|
-
|
|
712
|
+
const herbDisableComments = allChildren.filter(child =>
|
|
713
|
+
isNode(child, ERBContentNode) && isHerbDisableComment(child)
|
|
714
|
+
)
|
|
715
|
+
|
|
716
|
+
let openingLine = `<${tagName}`
|
|
717
|
+
|
|
718
|
+
if (herbDisableComments.length > 0) {
|
|
719
|
+
const commentLines = this.capture(() => {
|
|
720
|
+
herbDisableComments.forEach(comment => {
|
|
721
|
+
const wasInlineMode = this.inlineMode
|
|
722
|
+
this.inlineMode = true
|
|
723
|
+
this.lines.push(" ")
|
|
724
|
+
this.visit(comment)
|
|
725
|
+
this.inlineMode = wasInlineMode
|
|
726
|
+
})
|
|
727
|
+
})
|
|
728
|
+
|
|
729
|
+
openingLine += commentLines.join("")
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
this.pushWithIndent(openingLine)
|
|
713
733
|
|
|
714
734
|
this.withIndent(() => {
|
|
715
735
|
allChildren.forEach(child => {
|
|
716
736
|
if (isNode(child, HTMLAttributeNode)) {
|
|
717
737
|
this.pushWithIndent(this.renderAttribute(child))
|
|
718
738
|
} else if (!isNode(child, WhitespaceNode)) {
|
|
739
|
+
if (isNode(child, ERBContentNode) && isHerbDisableComment(child)) {
|
|
740
|
+
return
|
|
741
|
+
}
|
|
742
|
+
|
|
719
743
|
this.visit(child)
|
|
720
744
|
}
|
|
721
745
|
})
|