-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: init prettier shellscript plugin
- Loading branch information
Showing
10 changed files
with
115 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "prettier-plugin-sh", | ||
"version": "0.0.1", | ||
"description": "An opinionated shellscript formatter plugin for Prettier", | ||
"repository": "git@github.com/rx-ts/prettier.git", | ||
"homepage": "https://github.com/rx-ts/prettier/blob/master/packages/sh", | ||
"author": "JounQin <admin@1stg.me>", | ||
"license": "MPL-2.0", | ||
"main": "lib/cjs", | ||
"module": "lib", | ||
"es2015": "lib/es2015", | ||
"fesm5": "lib/esm", | ||
"jsdelivr": "lib/umd", | ||
"unpkg": "lib/umd", | ||
"types": "lib", | ||
"files": [ | ||
"lib", | ||
"typings.d.ts" | ||
], | ||
"keywords": [ | ||
"shellscript", | ||
"plugin", | ||
"prettier", | ||
"prettier-plugin" | ||
], | ||
"peerDependencies": { | ||
"prettier": "^1.18.2" | ||
}, | ||
"dependencies": { | ||
"mvdan-sh": "^0.4.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Doc, FastPath, Plugin } from 'prettier' | ||
// @ts-ignore | ||
const sh = require('mvdan-sh') | ||
|
||
const syntax = sh.syntax | ||
const parser = syntax.NewParser() | ||
const printer = syntax.NewPrinter() | ||
|
||
export default { | ||
name: 'prettier-plugin-sh', | ||
languages: [ | ||
{ | ||
name: 'ShellScript', | ||
parsers: ['sh-parse'], | ||
}, | ||
], | ||
parsers: { | ||
'sh-parse': { | ||
parse: (text: string) => parser.Parse(text, 'src'), | ||
astFormat: 'sh-parse', | ||
locStart: () => -1, | ||
locEnd: () => -1, | ||
hasPragma: () => false, | ||
}, | ||
}, | ||
printers: { | ||
'sh-parse': { | ||
print: (path: FastPath): Doc => printer.Print(path.getValue()), | ||
}, | ||
}, | ||
} as Plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`parsing a simple program 1`] = ` | ||
"echo 'foo' | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import prettier from 'prettier' | ||
import ShPlugin from 'prettier-plugin-sh' | ||
|
||
test('parsing a simple program', () => { | ||
const output = prettier.format(`echo 'foo'`, { | ||
// @ts-ignore | ||
parser: 'sh-parse', | ||
plugins: [ShPlugin], | ||
}) | ||
|
||
expect(output).toMatchSnapshot() | ||
}) | ||
|
||
test('fatal parse error', () => { | ||
expect(() => | ||
prettier.format(`echo )`, { | ||
filepath: 'broken.sh', | ||
// @ts-ignore | ||
parser: 'sh-parse', | ||
plugins: [ShPlugin], | ||
}), | ||
).toThrow() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "../../tsconfig.base", | ||
"compilerOptions": { | ||
"composite": true, | ||
"rootDir": "src", | ||
"outDir": "lib" | ||
}, | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module 'mvdan-sh' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters