prettier-plugin-sh
Advanced tools
Comparing version
# Change Log | ||
## 0.9.1 | ||
### Patch Changes | ||
- [#157](https://github.com/rx-ts/prettier/pull/157) [`4ddbb0b`](https://github.com/rx-ts/prettier/commit/4ddbb0bf6a391efa061c1ba51a0d2ce8d90bf4f9) Thanks [@JounQin](https://github.com/JounQin)! - feat: upgrade sh-syntax, parse as AST | ||
## 0.9.0 | ||
@@ -4,0 +10,0 @@ |
@@ -1,5 +0,4 @@ | ||
import { ParserOptions, Plugin } from 'prettier'; | ||
import { ShOptions } from 'sh-syntax'; | ||
export declare type ShParserOptions = ParserOptions & ShOptions; | ||
declare const ShPlugin: Plugin; | ||
import { Plugin } from 'prettier'; | ||
import { Node } from 'sh-syntax'; | ||
declare const ShPlugin: Plugin<Node>; | ||
export default ShPlugin; |
@@ -9,3 +9,25 @@ import path from 'path'; | ||
const workerPath = path.resolve(_dirname, 'worker.js'); | ||
const printSync = createSyncFn(workerPath); | ||
const processorSync = createSyncFn(workerPath); | ||
const handleError = (fn) => { | ||
try { | ||
return fn(); | ||
} | ||
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 = { | ||
@@ -15,6 +37,20 @@ languages, | ||
sh: { | ||
parse: (_text, _parsers, options) => options, | ||
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, | ||
})), | ||
astFormat: 'sh', | ||
locStart: () => 0, | ||
locEnd: () => 0, | ||
locStart: (node) => node.Pos.Offset, | ||
locEnd: (node) => node.End.Offset, | ||
}, | ||
@@ -24,35 +60,18 @@ }, | ||
sh: { | ||
print: (_path, { originalText, filepath, useTabs, tabWidth, keepComments, stopAt, variant, indent, binaryNextLine, switchCaseIndent, spaceRedirects, keepPadding, minify, functionNextLine, }) => { | ||
try { | ||
return printSync(originalText, { | ||
filepath, | ||
useTabs, | ||
tabWidth, | ||
keepComments, | ||
stopAt, | ||
variant, | ||
indent, | ||
binaryNextLine, | ||
switchCaseIndent, | ||
spaceRedirects, | ||
keepPadding, | ||
minify, | ||
functionNextLine, | ||
}); | ||
} | ||
catch (err) { | ||
const error = err; | ||
if (typeof error === 'string') { | ||
throw new SyntaxError(error); | ||
} | ||
throw Object.assign(error, { | ||
loc: { | ||
start: { | ||
column: error.pos.col, | ||
line: error.pos.line, | ||
}, | ||
}, | ||
}); | ||
} | ||
}, | ||
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, | ||
})), | ||
}, | ||
@@ -59,0 +78,0 @@ }, |
@@ -1,4 +0,4 @@ | ||
import { print } from 'sh-syntax'; | ||
import { processor } from 'sh-syntax'; | ||
import { runAsWorker } from 'synckit'; | ||
runAsWorker(print); | ||
runAsWorker(processor); | ||
//# sourceMappingURL=worker.js.map |
{ | ||
"name": "prettier-plugin-sh", | ||
"version": "0.9.0", | ||
"version": "0.9.1", | ||
"type": "module", | ||
@@ -39,4 +39,4 @@ "description": "An opinionated `shellscript、Dockerfile、properties、gitignore、dotenv、hosts、jvmoptions...` formatter plugin for Prettier", | ||
"dependencies": { | ||
"sh-syntax": "^0.0.2", | ||
"synckit": "^0.6.1" | ||
"sh-syntax": "^0.1.2", | ||
"synckit": "^0.6.2" | ||
}, | ||
@@ -43,0 +43,0 @@ "publishConfig": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
49494
3.79%1187
4.49%+ Added
+ Added
- Removed
Updated
Updated