Prettier Plugin for PostgreSQL 使用教程

Prettier Plugin for PostgreSQL 使用教程

prettier-plugin-pg[WIP] Plugin for prettier to support formatting of PostgreSQL-flavour SQL, including function bodies in SQL, pgSQL, PLV8, plpython, etc.项目地址:https://gitcode.com/gh_mirrors/pr/prettier-plugin-pg

1. 项目目录结构及介绍

prettier-plugin-pg/
├── scripts/
├── src/
├── tests/
├── tests_config/
├── typings/
├── .eslintignore
├── .eslintrc.js
├── .gitignore
├── .prettierrc.js
├── LICENSE
├── README.md
├── jest.eslint.config.js
├── jest.test.config.js
├── package.json
├── tsconfig.json
└── yarn.lock

目录结构介绍

  • scripts/: 存放项目的脚本文件。
  • src/: 存放项目的主要源代码。
  • tests/: 存放项目的测试代码。
  • tests_config/: 存放测试配置文件。
  • typings/: 存放TypeScript类型定义文件。
  • .eslintignore: ESLint忽略文件配置。
  • .eslintrc.js: ESLint配置文件。
  • .gitignore: Git忽略文件配置。
  • .prettierrc.js: Prettier配置文件。
  • LICENSE: 项目许可证文件。
  • README.md: 项目说明文档。
  • jest.eslint.config.js: Jest ESLint配置文件。
  • jest.test.config.js: Jest测试配置文件。
  • package.json: 项目依赖和脚本配置文件。
  • tsconfig.json: TypeScript配置文件。
  • yarn.lock: Yarn锁定文件,用于确保依赖版本一致性。

2. 项目启动文件介绍

项目的主要启动文件是 src/ 目录下的文件。具体来说,项目的核心逻辑和功能实现都在这个目录中。

主要文件

  • src/index.ts: 项目的入口文件,负责初始化和配置Prettier插件。
  • src/parser.ts: 负责解析PostgreSQL SQL语句。
  • src/printer.ts: 负责格式化解析后的SQL语句。

3. 项目配置文件介绍

.prettierrc.js

这是Prettier的配置文件,用于定义代码格式化的规则。例如:

module.exports = {
  printWidth: 80,
  tabWidth: 2,
  useTabs: false,
  semi: true,
  singleQuote: true,
  trailingComma: 'es5',
  bracketSpacing: true,
  arrowParens: 'always',
};

tsconfig.json

这是TypeScript的配置文件,用于定义TypeScript编译器的选项。例如:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}

package.json

这是项目的依赖和脚本配置文件。例如:

{
  "name": "prettier-plugin-pg",
  "version": "1.0.0",
  "scripts": {
    "build": "tsc",
    "test": "jest"
  },
  "dependencies": {
    "prettier": "^2.0.0"
  },
  "devDependencies": {
    "@types/jest": "^26.0.0",
    "jest": "^26.0.0",
    "typescript": "^4.0.0"
  }
}

通过以上配置文件,可以确保项目在开发和测试过程中的一致性和规范性。

prettier-plugin-pg[WIP] Plugin for prettier to support formatting of PostgreSQL-flavour SQL, including function bodies in SQL, pgSQL, PLV8, plpython, etc.项目地址:https://gitcode.com/gh_mirrors/pr/prettier-plugin-pg

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

赖欣昱

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值