@huggingface/prettier-plugin-vertical-align
Advanced tools
Comparing version 0.1.4 to 0.2.0
@@ -23,5 +23,5 @@ import prettier from "prettier"; | ||
// } | ||
if (node.type === "Program") { | ||
// console.log("node", inspect(node.body, { depth: 10 })); | ||
} | ||
// if (node.type === "Program") { | ||
// console.log("node", inspect(node.body, { depth: 10 })); | ||
// } | ||
if (node[keyLengthSymbol]) { | ||
@@ -48,2 +48,3 @@ const keyLength = node[keyLengthSymbol]; | ||
} | ||
case "PropertyDefinition": | ||
case "TSPropertySignature": | ||
@@ -66,4 +67,3 @@ node.typeAnnotation[typeAnnotationPrefix] = addedLength; | ||
const properties = nodeProperties(node).filter((node) => !isProperty(node) | ||
? | ||
node.loc.start.line === node.loc.end.line | ||
? node.loc.start.line === node.loc.end.line | ||
: node.key.loc.start.line === node[valueField(node)].loc.start.line); | ||
@@ -102,3 +102,6 @@ for (const prop of properties) { | ||
function isPropertyContainer(node) { | ||
return node.type === "ObjectExpression" || node.type === "TSInterfaceBody" || node.type === "TSTypeLiteral"; | ||
return (node.type === "ObjectExpression" || | ||
node.type === "TSInterfaceBody" || | ||
node.type === "TSTypeLiteral" || | ||
node.type === "ClassBody"); | ||
} | ||
@@ -109,3 +112,3 @@ function nodeProperties(node) { | ||
} | ||
if (node.type === "TSInterfaceBody") { | ||
if (node.type === "TSInterfaceBody" || node.type === "ClassBody") { | ||
return node.body; | ||
@@ -120,3 +123,6 @@ } | ||
// JS has ObjectProperty, TS has Property | ||
return node.type === "Property" || node.type === "TSPropertySignature" || node.type === "ObjectProperty"; | ||
return (node.type === "Property" || | ||
node.type === "TSPropertySignature" || | ||
node.type === "ObjectProperty" || | ||
node.type === "PropertyDefinition"); | ||
} | ||
@@ -127,3 +133,3 @@ function valueField(node) { | ||
} | ||
if (node.type === "TSPropertySignature") { | ||
if (node.type === "TSPropertySignature" || node.type === "PropertyDefinition") { | ||
return "typeAnnotation"; | ||
@@ -130,0 +136,0 @@ } |
{ | ||
"name": "@huggingface/prettier-plugin-vertical-align", | ||
"packageManager": "pnpm@9.11.0", | ||
"version": "0.1.4", | ||
"description": "", | ||
"scripts": { | ||
"test": "pnpm -w test", | ||
"build": "tsc -b", | ||
"prepublishOnly": "npm run build && npm run test" | ||
}, | ||
"type": "module", | ||
"main": "dist/index.js", | ||
"types": "src/index.ts", | ||
"files": [ | ||
"src", | ||
"dist", | ||
"tsconfig.json" | ||
], | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"prettier": "^3.3.3", | ||
"typescript": "^5.6.2", | ||
"@types/node": "^22.0.0" | ||
} | ||
} | ||
"name": "@huggingface/prettier-plugin-vertical-align", | ||
"version": "0.2.0", | ||
"description": "", | ||
"type": "module", | ||
"main": "dist/index.js", | ||
"types": "src/index.ts", | ||
"files": [ | ||
"src", | ||
"dist", | ||
"tsconfig.json" | ||
], | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"prettier": "^3.3.3", | ||
"typescript": "^5.6.2", | ||
"@types/node": "^22.0.0" | ||
}, | ||
"scripts": { | ||
"test": "pnpm -w test", | ||
"build": "tsc -b" | ||
} | ||
} |
@@ -33,5 +33,5 @@ import type { AstPath, Printer } from "prettier"; | ||
if (node.type === "Program") { | ||
// console.log("node", inspect(node.body, { depth: 10 })); | ||
} | ||
// if (node.type === "Program") { | ||
// console.log("node", inspect(node.body, { depth: 10 })); | ||
// } | ||
@@ -62,2 +62,3 @@ if (node[keyLengthSymbol]) { | ||
} | ||
case "PropertyDefinition": | ||
case "TSPropertySignature": | ||
@@ -84,4 +85,3 @@ node.typeAnnotation[typeAnnotationPrefix] = addedLength; | ||
!isProperty(node) | ||
? | ||
node.loc.start.line === node.loc.end.line | ||
? node.loc.start.line === node.loc.end.line | ||
: node.key.loc.start.line === node[valueField(node)].loc.start.line, | ||
@@ -131,3 +131,8 @@ ); | ||
function isPropertyContainer(node: AstPath["node"]) { | ||
return node.type === "ObjectExpression" || node.type === "TSInterfaceBody" || node.type === "TSTypeLiteral"; | ||
return ( | ||
node.type === "ObjectExpression" || | ||
node.type === "TSInterfaceBody" || | ||
node.type === "TSTypeLiteral" || | ||
node.type === "ClassBody" | ||
); | ||
} | ||
@@ -139,3 +144,3 @@ | ||
} | ||
if (node.type === "TSInterfaceBody") { | ||
if (node.type === "TSInterfaceBody" || node.type === "ClassBody") { | ||
return node.body; | ||
@@ -151,3 +156,8 @@ } | ||
// JS has ObjectProperty, TS has Property | ||
return node.type === "Property" || node.type === "TSPropertySignature" || node.type === "ObjectProperty"; | ||
return ( | ||
node.type === "Property" || | ||
node.type === "TSPropertySignature" || | ||
node.type === "ObjectProperty" || | ||
node.type === "PropertyDefinition" | ||
); | ||
} | ||
@@ -159,3 +169,3 @@ | ||
} | ||
if (node.type === "TSPropertySignature") { | ||
if (node.type === "TSPropertySignature" || node.type === "PropertyDefinition") { | ||
return "typeAnnotation"; | ||
@@ -162,0 +172,0 @@ } |
Sorry, the diff of this file is not supported yet
48360
965