Skip to content

Commit 17ec885

Browse files
initial commit: working prettier plugin with ruff formatting integration for python sections
1 parent fc83ab3 commit 17ec885

32 files changed

Lines changed: 3908 additions & 0 deletions

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules/
2+
dist/
3+
.DS_Store
4+
coverage/
5+
*.log
6+
.pnpm-debug.log

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"trailingComma": "es5",
5+
"printWidth": 100,
6+
"tabWidth": 2
7+
}

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# prettier-plugin-pywire
2+
3+
Prettier plugin for PyWire (.wire) files.
4+
5+
<!-- SUPPORT_MESSAGE_TEMPLATE_START -->
6+
## ❤️ Support pywire
7+
8+
If pywire is helping you build, consider supporting the project. Donations cover documentation hosting, CI/CD runners, and the caffeine required for development.
9+
10+
[![GitHub Sponsor](https://img.shields.io/badge/Sponsor-pywire-ea4aaa?style=for-the-badge&logo=github-sponsors)](https://github.com/sponsors/pywire)
11+
[![Ko-Fi](https://img.shields.io/badge/Ko--fi-reecelikesramen-ff5e5b?style=for-the-badge&logo=ko-fi)](https://ko-fi.com/reecelikesramen)
12+
13+
### Why sponsor?
14+
* 🚀 Faster development of the core framework.
15+
* 📖 Better docs and community examples.
16+
* 🔧 Integration research.
17+
<!-- SUPPORT_MESSAGE_TEMPLATE_END -->

build.mjs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { build } from 'esbuild'
2+
import { existsSync, mkdirSync } from 'node:fs'
3+
import { dirname } from 'node:path'
4+
import { fileURLToPath } from 'node:url'
5+
6+
const distDir = fileURLToPath(new URL('./dist', import.meta.url))
7+
if (!existsSync(distDir)) {
8+
mkdirSync(distDir, { recursive: true })
9+
}
10+
11+
const isWatch = process.argv.includes('--watch')
12+
13+
const commonOptions = {
14+
entryPoints: ['src/index.ts'],
15+
bundle: true,
16+
platform: 'node',
17+
sourcemap: true,
18+
target: 'node18',
19+
external: ['prettier'],
20+
}
21+
22+
// Build ESM version
23+
await build({
24+
...commonOptions,
25+
format: 'esm',
26+
outfile: fileURLToPath(new URL('./dist/index.js', import.meta.url)),
27+
})
28+
29+
// Build CJS version for VS Code extension compatibility
30+
// Inject import.meta.url polyfill for WASM loaders that use it
31+
const importMetaUrlShim = `
32+
var import_meta_url = typeof document === 'undefined'
33+
? require('url').pathToFileURL(__filename).href
34+
: (document.currentScript && document.currentScript.src || new URL('index.cjs', document.baseURI).href);
35+
`
36+
await build({
37+
...commonOptions,
38+
format: 'cjs',
39+
outfile: fileURLToPath(new URL('./dist/index.cjs', import.meta.url)),
40+
banner: { js: importMetaUrlShim },
41+
define: {
42+
'import.meta.url': 'import_meta_url',
43+
},
44+
})
45+
46+
console.log('Build complete: ESM and CJS')

eslint.config.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import js from '@eslint/js'
2+
import tseslint from '@typescript-eslint/eslint-plugin'
3+
import tsParser from '@typescript-eslint/parser'
4+
import globals from 'globals'
5+
6+
export default [
7+
{
8+
ignores: ['dist/**', 'node_modules/**', 'tests/fixtures/**'],
9+
},
10+
{
11+
languageOptions: {
12+
globals: {
13+
...globals.node,
14+
},
15+
ecmaVersion: 'latest',
16+
sourceType: 'module',
17+
},
18+
},
19+
js.configs.recommended,
20+
{
21+
files: ['**/*.ts'],
22+
plugins: {
23+
'@typescript-eslint': tseslint,
24+
},
25+
languageOptions: {
26+
parser: tsParser,
27+
},
28+
rules: {
29+
...tseslint.configs.recommended.rules,
30+
'@typescript-eslint/no-unused-vars': [
31+
'error',
32+
{ argsIgnorePattern: '^_', destructuredArrayIgnorePattern: '^_' },
33+
],
34+
'@typescript-eslint/no-explicit-any': 'warn',
35+
},
36+
},
37+
]

package.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "prettier-plugin-pywire",
3+
"version": "0.1.0",
4+
"description": "Prettier plugin for PyWire (.wire) files",
5+
"type": "module",
6+
"main": "dist/index.cjs",
7+
"module": "dist/index.js",
8+
"exports": {
9+
".": {
10+
"import": "./dist/index.js",
11+
"require": "./dist/index.cjs"
12+
}
13+
},
14+
"files": [
15+
"dist",
16+
"LICENSE"
17+
],
18+
"scripts": {
19+
"build": "node build.mjs && tsc -p tsconfig.json --emitDeclarationOnly",
20+
"build:dev": "node build.mjs --watch",
21+
"test": "vitest run",
22+
"test:watch": "vitest",
23+
"test:coverage": "vitest run --coverage",
24+
"lint": "eslint .",
25+
"lint:fix": "eslint . --fix",
26+
"format": "prettier --write .",
27+
"format:check": "prettier --check .",
28+
"typecheck": "tsc -p tsconfig.json --noEmit",
29+
"check": "pnpm format:check && pnpm lint && pnpm typecheck && pnpm test"
30+
},
31+
"dependencies": {
32+
"@iarna/toml": "^2.2.5",
33+
"@wasm-fmt/ruff_fmt": "^0.9.0",
34+
"cosmiconfig": "^9.0.0"
35+
},
36+
"peerDependencies": {
37+
"prettier": "^3.0.0"
38+
},
39+
"devDependencies": {
40+
"@eslint/js": "^9.35.0",
41+
"@types/node": "^20.11.0",
42+
"@typescript-eslint/eslint-plugin": "^8.43.0",
43+
"@typescript-eslint/parser": "^8.43.0",
44+
"@vitest/coverage-v8": "^4.0.17",
45+
"esbuild": "^0.20.0",
46+
"eslint": "^9.35.0",
47+
"globals": "^16.4.0",
48+
"prettier": "^3.6.2",
49+
"typescript": "^5.3.3",
50+
"vitest": "^4.0.17"
51+
}
52+
}

0 commit comments

Comments
 (0)