prettier-plugin-astro
Advanced tools
Comparing version 0.1.0-next.4 to 0.1.0-next.5
# prettier-plugin-astro | ||
## 0.1.0-next.5 | ||
### Patch Changes | ||
- a7a6b14: Fix: format indented sass | ||
- ce5b38a: Refactor tests for better watch mode | ||
- 08ec9f1: Fix: prevent duplicate text | ||
- c5a7a7f: Update dependencies | ||
- 8a8b3e9: Update @astrojs/compiler and fix for spread in expression | ||
- f5fcc1b: Disable vitest multi-threading | ||
- da0fe36: Add new line after comments | ||
## 0.1.0-next.4 | ||
@@ -4,0 +16,0 @@ |
@@ -107,3 +107,3 @@ 'use strict'; | ||
function isNodeWithChildren(node) { | ||
return node && Array.isArray(node.children); | ||
return node && 'children' in node && Array.isArray(node.children); | ||
} | ||
@@ -190,39 +190,28 @@ function isInlineElement(path, opts, node) { | ||
function manualDedent(input) { | ||
let result = ''; | ||
for (let i = 0; i < input.length; i++) { | ||
result += input[i] | ||
.replace(/\\\n[ \t]*/g, '') | ||
.replace(/\\`/g, '`'); | ||
if (i < (arguments.length <= 1 ? 0 : arguments.length - 1)) { | ||
result += arguments.length <= i + 1 ? undefined : arguments[i + 1]; | ||
let minTabSize = Infinity; | ||
let result = input; | ||
result = result.replace(/\r\n/g, '\n'); | ||
let char = ''; | ||
for (const line of result.split('\n')) { | ||
if (!line) | ||
continue; | ||
if (line[0] && /^[^\s]/.test(line[0])) { | ||
minTabSize = 0; | ||
break; | ||
} | ||
} | ||
const lines = result.split('\n'); | ||
let mindent = null; | ||
lines.forEach(function (l) { | ||
const m = l.match(/^(\s+)\S+/); | ||
if (m) { | ||
const indent = m[1].length; | ||
if (!mindent) { | ||
mindent = indent; | ||
} | ||
else { | ||
mindent = Math.min(mindent, indent); | ||
} | ||
const match = line.match(/^(\s+)\S+/); | ||
if (match) { | ||
if (match[1] && !char) | ||
char = match[1][0]; | ||
if (match[1].length < minTabSize) | ||
minTabSize = match[1].length; | ||
} | ||
}); | ||
if (mindent !== null) { | ||
(function () { | ||
const m = mindent; | ||
result = lines | ||
.map(function (l) { | ||
return l[0] === ' ' ? l.slice(m) : l; | ||
}) | ||
.join('\n'); | ||
})(); | ||
} | ||
if (minTabSize > 0 && Number.isFinite(minTabSize)) { | ||
result = result.replace(new RegExp(`^${new Array(minTabSize + 1).join(char)}`, 'gm'), ''); | ||
} | ||
return { | ||
result: result | ||
.trim() | ||
.replace(/\\n/g, '\n'), | ||
tabSize: minTabSize === Infinity ? 0 : minTabSize, | ||
char, | ||
result, | ||
}; | ||
@@ -262,2 +251,46 @@ } | ||
} | ||
function removeDuplicates(root) { | ||
root.children = root.children.filter((node, i, rootChildren) => { | ||
if (node.type !== 'text') | ||
return true; | ||
return (i === | ||
rootChildren.findIndex((t) => { | ||
if (t.position && node.position) { | ||
return (node.type === 'text' && | ||
t.position.start.offset === node.position.start.offset && | ||
t.position.start.line === node.position.start.line && | ||
t.position.start.column === node.position.start.column); | ||
} | ||
})); | ||
}); | ||
} | ||
function isTagLikeNode(node) { | ||
return (node.type === 'element' || | ||
node.type === 'component' || | ||
node.type === 'custom-element' || | ||
node.type === 'fragment'); | ||
} | ||
function getSiblings(path) { | ||
const parent = path.getParentNode(); | ||
if (!parent) | ||
return []; | ||
return getChildren(parent); | ||
} | ||
function getNextNode(path) { | ||
var _a, _b, _c, _d; | ||
const node = path.getNode(); | ||
if (node) { | ||
const siblings = getSiblings(path); | ||
if (((_a = node.position) === null || _a === void 0 ? void 0 : _a.start) === ((_b = siblings[siblings.length - 1].position) === null || _b === void 0 ? void 0 : _b.start)) | ||
return null; | ||
for (let i = 0; i < siblings.length; i++) { | ||
const sibling = siblings[i]; | ||
if (((_c = sibling.position) === null || _c === void 0 ? void 0 : _c.start) === ((_d = node.position) === null || _d === void 0 ? void 0 : _d.start) && | ||
i !== siblings.length - 1) { | ||
return siblings[i + 1]; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
@@ -278,2 +311,3 @@ const { builders: { breakParent, dedent, fill, group, hardline, indent, join, line, literalline, softline, }, utils: { removeLines, stripTrailingHardline }, } = _doc__default["default"]; | ||
case 'root': { | ||
removeDuplicates(node); | ||
return [stripTrailingHardline(path.map(print, 'children')), hardline]; | ||
@@ -450,3 +484,8 @@ } | ||
case 'comment': | ||
return ['<!--', getUnencodedText(node), '-->']; | ||
const nextNode = getNextNode(path); | ||
let trailingLine = ''; | ||
if (nextNode && isTagLikeNode(nextNode)) { | ||
trailingLine = hardline; | ||
} | ||
return ['<!--', getUnencodedText(node), '-->', trailingLine]; | ||
default: { | ||
@@ -529,3 +568,3 @@ throw new Error(`Unhandled node type "${node.type}"!`); | ||
if (node.type === 'element' && node.name === 'script') { | ||
const scriptContent = node.children[0].value; | ||
const scriptContent = printRaw(node); | ||
let formatttedScript = textToDoc(scriptContent, { | ||
@@ -551,3 +590,3 @@ ...opts, | ||
if (node.type === 'element' && node.name === 'style') { | ||
const styleTagContent = node.children[0].value.trim(); | ||
const styleTagContent = printRaw(node); | ||
const supportedStyleLangValues = ['css', 'scss', 'sass']; | ||
@@ -554,0 +593,0 @@ let parserLang = 'css'; |
{ | ||
"name": "prettier-plugin-astro", | ||
"version": "0.1.0-next.4", | ||
"version": "0.1.0-next.5", | ||
"type": "commonjs", | ||
@@ -34,3 +34,4 @@ "description": "A Prettier Plugin for formatting Astro files", | ||
"test": "vitest run", | ||
"test:w": "vitest", | ||
"test:w": "vitest -w", | ||
"test:ui": "vitest --ui", | ||
"release": "yarn build && changeset publish", | ||
@@ -42,26 +43,26 @@ "lint": "eslint .", | ||
"dependencies": { | ||
"@astrojs/compiler": "^0.13.1", | ||
"prettier": "^2.4.1", | ||
"@astrojs/compiler": "^0.15.2", | ||
"prettier": "^2.6.2", | ||
"sass-formatter": "^0.7.2", | ||
"synckit": "^0.6.2" | ||
"synckit": "^0.7.0" | ||
}, | ||
"devDependencies": { | ||
"@changesets/cli": "^2.16.0", | ||
"@rollup/plugin-commonjs": "^21.0.0", | ||
"@rollup/plugin-commonjs": "^21.0.3", | ||
"@rollup/plugin-node-resolve": "^13.0.5", | ||
"@types/prettier": "^2.4.1", | ||
"@typescript-eslint/eslint-plugin": "^5.16.0", | ||
"@typescript-eslint/parser": "^5.16.0", | ||
"@vitest/ui": "^0.7.7", | ||
"eslint": "^8.0.0", | ||
"@typescript-eslint/eslint-plugin": "^5.18.0", | ||
"@typescript-eslint/parser": "^5.18.0", | ||
"@vitest/ui": "^0.9.2", | ||
"eslint": "^8.12.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"eslint-plugin-prettier-doc": "^1.0.1", | ||
"rollup": "^2.58.0", | ||
"rollup": "^2.70.1", | ||
"rollup-plugin-typescript": "^1.0.1", | ||
"ts-node": "^10.2.1", | ||
"ts-node": "^10.7.0", | ||
"tslib": "^2.3.1", | ||
"typescript": "^4.4.3", | ||
"vitest": "^0.7.7" | ||
"typescript": "^4.6.3", | ||
"vitest": "^0.9.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
114885
739
+ Added@astrojs/compiler@0.15.2(transitive)
+ Added@nodelib/fs.scandir@2.1.5(transitive)
+ Added@nodelib/fs.stat@2.0.5(transitive)
+ Added@nodelib/fs.walk@1.2.8(transitive)
+ Added@pkgr/utils@2.4.2(transitive)
+ Addedbig-integer@1.6.52(transitive)
+ Addedbplist-parser@0.2.0(transitive)
+ Addedbraces@3.0.3(transitive)
+ Addedbundle-name@3.0.0(transitive)
+ Addedcross-spawn@7.0.5(transitive)
+ Addeddefault-browser@4.0.0(transitive)
+ Addeddefault-browser-id@3.0.0(transitive)
+ Addeddefine-lazy-prop@3.0.0(transitive)
+ Addedexeca@5.1.17.2.0(transitive)
+ Addedfast-glob@3.3.2(transitive)
+ Addedfastq@1.17.1(transitive)
+ Addedfill-range@7.1.1(transitive)
+ Addedget-stream@6.0.1(transitive)
+ Addedglob-parent@5.1.2(transitive)
+ Addedhuman-signals@2.1.04.3.1(transitive)
+ Addedis-docker@2.2.13.0.0(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-glob@4.0.3(transitive)
+ Addedis-inside-container@1.0.0(transitive)
+ Addedis-number@7.0.0(transitive)
+ Addedis-stream@2.0.13.0.0(transitive)
+ Addedis-wsl@2.2.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedmerge-stream@2.0.0(transitive)
+ Addedmerge2@1.4.1(transitive)
+ Addedmicromatch@4.0.8(transitive)
+ Addedmimic-fn@2.1.04.0.0(transitive)
+ Addednpm-run-path@4.0.15.3.0(transitive)
+ Addedonetime@5.1.26.0.0(transitive)
+ Addedopen@9.1.0(transitive)
+ Addedpath-key@3.1.14.0.0(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedqueue-microtask@1.2.3(transitive)
+ Addedreusify@1.0.4(transitive)
+ Addedrun-applescript@5.0.0(transitive)
+ Addedrun-parallel@1.2.0(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedstrip-final-newline@2.0.03.0.0(transitive)
+ Addedsynckit@0.7.3(transitive)
+ Addedtitleize@3.0.0(transitive)
+ Addedto-regex-range@5.0.1(transitive)
+ Addeduntildify@4.0.0(transitive)
+ Addedwhich@2.0.2(transitive)
- Removed@astrojs/compiler@0.13.2(transitive)
- Removedsynckit@0.6.2(transitive)
Updated@astrojs/compiler@^0.15.2
Updatedprettier@^2.6.2
Updatedsynckit@^0.7.0