prettier-plugin-sh
Advanced tools
Comparing version 0.11.0 to 0.12.0
@@ -1,24 +0,14 @@ | ||
import { LangVariant, Node, Pos } from 'mvdan-sh'; | ||
import { ParserOptions, Plugin, RequiredOptions } from 'prettier'; | ||
export interface ShOptions extends RequiredOptions { | ||
keepComments: boolean; | ||
stopAt: string; | ||
variant: LangVariant; | ||
indent: number; | ||
binaryNextLine: boolean; | ||
switchCaseIndent: boolean; | ||
spaceRedirects: boolean; | ||
keepPadding: boolean; | ||
minify: boolean; | ||
functionNextLine: boolean; | ||
import { ParserOptions, Plugin } from 'prettier'; | ||
import { File, Node, ShOptions } from 'sh-syntax'; | ||
export interface Processor { | ||
(text: string, options?: ShOptions): File; | ||
(text: string, options?: ShOptions & { | ||
print: true; | ||
}): string; | ||
(ast: File, options?: ShOptions & { | ||
originalText: string; | ||
}): string; | ||
} | ||
export declare type ShParserOptions = ParserOptions<Node> & ShOptions; | ||
export interface IShParseError extends Error { | ||
Filename: string; | ||
Pos: Pos; | ||
Text: string; | ||
Incomplete: boolean; | ||
Error(): void; | ||
} | ||
declare const ShPlugin: Plugin<Node>; | ||
export default ShPlugin; |
@@ -1,4 +0,9 @@ | ||
import sh from 'mvdan-sh'; | ||
import path from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { createSyncFn } from 'synckit'; | ||
import { languages } from './languages.js'; | ||
const { syntax } = sh; | ||
const _dirname = typeof __dirname === 'undefined' | ||
? path.dirname(fileURLToPath(import.meta.url)) | ||
: __dirname; | ||
const processor = createSyncFn(path.resolve(_dirname, 'worker.js')); | ||
class ShParseError extends SyntaxError { | ||
@@ -10,4 +15,4 @@ constructor(err) { | ||
start: { | ||
column: err.Pos.Col(), | ||
line: err.Pos.Line(), | ||
column: err.Pos.Col, | ||
line: err.Pos.Line, | ||
}, | ||
@@ -22,11 +27,9 @@ }; | ||
parse: (text, _parsers, { filepath, keepComments = true, stopAt, variant }) => { | ||
const parserOptions = [syntax.KeepComments(keepComments)]; | ||
if (stopAt != null) { | ||
parserOptions.push(syntax.StopAt(stopAt)); | ||
} | ||
if (variant != null) { | ||
parserOptions.push(syntax.Variant(variant)); | ||
} | ||
try { | ||
return syntax.NewParser(...parserOptions).Parse(text, filepath); | ||
return processor(text, { | ||
filepath, | ||
keepComments, | ||
stopAt, | ||
variant, | ||
}); | ||
} | ||
@@ -38,4 +41,4 @@ catch (err) { | ||
astFormat: 'sh', | ||
locStart: node => node.Pos().Offset(), | ||
locEnd: node => node.End().Offset(), | ||
locStart: node => node.Pos.Offset, | ||
locEnd: node => node.End.Offset, | ||
}, | ||
@@ -45,5 +48,14 @@ }, | ||
sh: { | ||
print: (path, { useTabs, tabWidth, indent = useTabs ? 0 : tabWidth, binaryNextLine = true, switchCaseIndent = true, spaceRedirects = true, keepPadding, minify, functionNextLine, }) => syntax | ||
.NewPrinter(syntax.Indent(indent), syntax.BinaryNextLine(binaryNextLine), syntax.SwitchCaseIndent(switchCaseIndent), syntax.SpaceRedirects(spaceRedirects), syntax.KeepPadding(keepPadding), syntax.Minify(minify), syntax.FunctionNextLine(functionNextLine)) | ||
.Print(path.getValue()), | ||
print: (path, { originalText, useTabs, tabWidth, indent = useTabs ? 0 : tabWidth, binaryNextLine = true, switchCaseIndent = true, spaceRedirects = true, keepPadding, minify, functionNextLine, }) => processor(path.getNode(), { | ||
originalText, | ||
useTabs, | ||
tabWidth, | ||
indent, | ||
binaryNextLine, | ||
switchCaseIndent, | ||
spaceRedirects, | ||
keepPadding, | ||
minify, | ||
functionNextLine, | ||
}), | ||
}, | ||
@@ -50,0 +62,0 @@ }, |
{ | ||
"name": "prettier-plugin-sh", | ||
"version": "0.11.0", | ||
"version": "0.12.0", | ||
"type": "module", | ||
@@ -11,3 +11,3 @@ "description": "An opinionated `shellscript、Dockerfile、properties、gitignore、dotenv、hosts、jvmoptions...` formatter plugin for Prettier", | ||
"engines": { | ||
"node": ">=12.20" | ||
"node": "^12.20 || ^14.18.0 || >=16.0.0" | ||
}, | ||
@@ -40,3 +40,4 @@ "main": "./lib/index.cjs", | ||
"dependencies": { | ||
"mvdan-sh": "^0.10.1" | ||
"sh-syntax": "^0.3.2", | ||
"synckit": "^0.7.1" | ||
}, | ||
@@ -43,0 +44,0 @@ "publishConfig": { |
Sorry, the diff of this file is not supported yet
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
41839
13
1145
3
+ Addedsh-syntax@^0.3.2
+ Addedsynckit@^0.7.1
+ 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.6(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)
+ Addedsh-syntax@0.3.7(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)
+ Addedtslib@2.8.1(transitive)
+ Addeduntildify@4.0.0(transitive)
+ Addedwhich@2.0.2(transitive)
- Removedmvdan-sh@^0.10.1
- Removedmvdan-sh@0.10.1(transitive)