Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prettier-plugin-astro

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prettier-plugin-astro - npm Package Compare versions

Comparing version 0.1.0-next.4 to 0.1.0-next.5

12

CHANGELOG.md
# 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 @@

113

dist/index.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc