prettier-plugin-sh
Advanced tools
Comparing version 0.10.2 to 0.11.0
@@ -1,4 +0,24 @@ | ||
import { Plugin } from 'prettier'; | ||
import { Node } from 'sh-syntax'; | ||
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; | ||
} | ||
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,33 +0,16 @@ | ||
import path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import { createSyncFn } from 'synckit'; | ||
import sh from 'mvdan-sh'; | ||
import { languages } from './languages.js'; | ||
const isInModule = typeof __dirname === 'undefined'; | ||
const _dirname = isInModule | ||
? path.dirname(fileURLToPath(import.meta.url)) | ||
: __dirname; | ||
const workerPath = path.resolve(_dirname, `../worker.${isInModule ? 'mjs' : 'cjs'}`); | ||
const processorSync = createSyncFn(workerPath); | ||
const handleError = (fn) => { | ||
try { | ||
return fn(); | ||
const { syntax } = sh; | ||
class ShParseError extends SyntaxError { | ||
constructor(err) { | ||
super(err.Text); | ||
this.cause = err; | ||
this.loc = { | ||
start: { | ||
column: err.Pos.Col(), | ||
line: err.Pos.Line(), | ||
}, | ||
}; | ||
} | ||
catch (err) { | ||
const error = err; | ||
if (typeof error === 'string') { | ||
throw new SyntaxError(error); | ||
} | ||
if ('Pos' in error) { | ||
throw Object.assign(error, { | ||
loc: { | ||
start: { | ||
column: error.Pos.Col, | ||
line: error.Pos.Line, | ||
}, | ||
}, | ||
}); | ||
} | ||
throw error; | ||
} | ||
}; | ||
} | ||
const ShPlugin = { | ||
@@ -37,20 +20,20 @@ languages, | ||
sh: { | ||
parse: (text, _parsers, { filepath, useTabs, tabWidth, keepComments, stopAt, variant, indent, binaryNextLine, switchCaseIndent, spaceRedirects, keepPadding, minify, functionNextLine, }) => handleError(() => processorSync(text, { | ||
filepath, | ||
useTabs, | ||
tabWidth, | ||
keepComments, | ||
stopAt, | ||
variant, | ||
indent, | ||
binaryNextLine, | ||
switchCaseIndent, | ||
spaceRedirects, | ||
keepPadding, | ||
minify, | ||
functionNextLine, | ||
})), | ||
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); | ||
} | ||
catch (err) { | ||
throw new ShParseError(err); | ||
} | ||
}, | ||
astFormat: 'sh', | ||
locStart: (node) => node.Pos.Offset, | ||
locEnd: (node) => node.End.Offset, | ||
locStart: node => node.Pos().Offset(), | ||
locEnd: node => node.End().Offset(), | ||
}, | ||
@@ -60,18 +43,5 @@ }, | ||
sh: { | ||
print: (path, { originalText, filepath, useTabs, tabWidth, keepComments, stopAt, variant, indent, binaryNextLine, switchCaseIndent, spaceRedirects, keepPadding, minify, functionNextLine, }) => handleError(() => processorSync(path.getValue(), { | ||
filepath, | ||
originalText, | ||
useTabs, | ||
tabWidth, | ||
keepComments, | ||
stopAt, | ||
variant, | ||
indent, | ||
binaryNextLine, | ||
switchCaseIndent, | ||
spaceRedirects, | ||
keepPadding, | ||
minify, | ||
functionNextLine, | ||
})), | ||
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()), | ||
}, | ||
@@ -78,0 +48,0 @@ }, |
{ | ||
"name": "prettier-plugin-sh", | ||
"version": "0.10.2", | ||
"version": "0.11.0", | ||
"type": "module", | ||
@@ -22,5 +22,3 @@ "description": "An opinionated `shellscript、Dockerfile、properties、gitignore、dotenv、hosts、jvmoptions...` formatter plugin for Prettier", | ||
"files": [ | ||
"lib", | ||
"worker.cjs", | ||
"worker.mjs" | ||
"lib" | ||
], | ||
@@ -42,4 +40,3 @@ "keywords": [ | ||
"dependencies": { | ||
"sh-syntax": "^0.1.4", | ||
"synckit": "^0.7.0" | ||
"mvdan-sh": "^0.10.1" | ||
}, | ||
@@ -46,0 +43,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
2
41708
10
1126
+ Addedmvdan-sh@^0.10.1
+ Addedmvdan-sh@0.10.1(transitive)
- Removedsh-syntax@^0.1.4
- Removedsynckit@^0.7.0
- Removed@nodelib/fs.scandir@2.1.5(transitive)
- Removed@nodelib/fs.stat@2.0.5(transitive)
- Removed@nodelib/fs.walk@1.2.8(transitive)
- Removed@pkgr/utils@2.4.2(transitive)
- Removedbig-integer@1.6.52(transitive)
- Removedbplist-parser@0.2.0(transitive)
- Removedbraces@3.0.3(transitive)
- Removedbundle-name@3.0.0(transitive)
- Removedcross-spawn@7.0.6(transitive)
- Removeddefault-browser@4.0.0(transitive)
- Removeddefault-browser-id@3.0.0(transitive)
- Removeddefine-lazy-prop@3.0.0(transitive)
- Removedexeca@5.1.17.2.0(transitive)
- Removedfast-glob@3.3.2(transitive)
- Removedfastq@1.17.1(transitive)
- Removedfill-range@7.1.1(transitive)
- Removedget-stream@6.0.1(transitive)
- Removedglob-parent@5.1.2(transitive)
- Removedhuman-signals@2.1.04.3.1(transitive)
- Removedis-docker@2.2.13.0.0(transitive)
- Removedis-extglob@2.1.1(transitive)
- Removedis-glob@4.0.3(transitive)
- Removedis-inside-container@1.0.0(transitive)
- Removedis-number@7.0.0(transitive)
- Removedis-stream@2.0.13.0.0(transitive)
- Removedis-wsl@2.2.0(transitive)
- Removedisexe@2.0.0(transitive)
- Removedmerge-stream@2.0.0(transitive)
- Removedmerge2@1.4.1(transitive)
- Removedmicromatch@4.0.8(transitive)
- Removedmimic-fn@2.1.04.0.0(transitive)
- Removednanoid@3.3.8(transitive)
- Removednpm-run-path@4.0.15.3.0(transitive)
- Removedonetime@5.1.26.0.0(transitive)
- Removedopen@9.1.0(transitive)
- Removedpath-key@3.1.14.0.0(transitive)
- Removedpicocolors@1.1.1(transitive)
- Removedpicomatch@2.3.1(transitive)
- Removedqueue-microtask@1.2.3(transitive)
- Removedreusify@1.0.4(transitive)
- Removedrun-applescript@5.0.0(transitive)
- Removedrun-parallel@1.2.0(transitive)
- Removedsh-syntax@0.1.4(transitive)
- Removedshebang-command@2.0.0(transitive)
- Removedshebang-regex@3.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedstrip-final-newline@2.0.03.0.0(transitive)
- Removedsynckit@0.7.3(transitive)
- Removedtitleize@3.0.0(transitive)
- Removedto-regex-range@5.0.1(transitive)
- Removedtslib@2.8.1(transitive)
- Removeduntildify@4.0.0(transitive)
- Removedwhich@2.0.2(transitive)