Skip to content

Commit

Permalink
v5.0.0 (#42)
Browse files Browse the repository at this point in the history
* fix zeroturnaround#152,
Add + in scientific notation regex

* fix zeroturnaround#159, Add token override for SET datatype

* add common operators to Tokenizer, dedupe

* update missing operators

* use exhaustive list of monad operators

* fix .. operator for PlSQL

* fix handling for braces (zeroturnaround #155), add test for braces & backticks

* move all operator handling into formatOperator

* fix handling of backticks (zeroturnaround#139)

* update isToken

* fix zeroturnaround#123, add hex string type

* fix zeroturnaround#166, add negative lookahead for specialWordChar for reserved words

* fix zeroturnaround#162, add handling for prefix/suffix only specialWordChars

* Fix zeroturnaround#137, add @@ system variables

* add support for array and map accessors

* print help when no arguments passed

* convert cli tool to cladd

* rename bin file

* add ts export for module

* update cjs build with typescript

* add ts-loader for umd build

* update badges and GH Actions names

* Update issue templates

* add enhancement template

* add feature request title

* update package.json

* move index.html to static dir

* make parenOptions Partial type

* split into css and js files

* ♻️

* remove local script

* move options to left menu

* add new options to demo

* add icon

* add comments for token overrides

* fix prefixed operators

* add link to bug reports

* update TokenizerOptions.specialWordChars.any to Optional Type

* update CHANGELOG

* update README badges

* update README with vscode

* add CONTRIBUTING.md

* fix formatting for reservedDependentClauses

* update release-it json
  • Loading branch information
inferrinizzard authored Nov 25, 2021
1 parent 9d30c4b commit 63c05eb
Show file tree
Hide file tree
Showing 46 changed files with 1,638 additions and 1,856 deletions.
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"parserOptions": { "project": "./tsconfig.json", "ecmaVersion": 6, "sourceType": "module" },
"extends": ["airbnb-base", "airbnb-typescript/base", "plugin:import/typescript", "prettier"],
"plugins": ["@typescript-eslint", "prettier"],
"globals": {
"document": true,
"prettierSql": true
},
"rules": {
"class-methods-use-this": "off",
"curly": ["error", "all"],
Expand Down
25 changes: 25 additions & 0 deletions .github/ISSUE_TEMPLATE/formatting-bug-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
name: Formatting Bug Report
about: Raise an issue about the FORMATTING output
title: '[FORMATTING] Issue Title Here'
labels: bug
assignees: ''
---

**Describe the bug**
A clear and concise description of what the bug is.

**Expected Output**
Please provide a code snippet of the expected SQL output.

**Actual Output**
Please provide a code snippet of the SQL output produced by the tool.

**Usage**

- How are you calling / using the script? (Please provide a code snippet)
- What SQL language(s) does this apply to?
- What Node version? (If applicable)

**Additional context**
Add any other context about the problem here.
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE/new-feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: Suggest Improvement/Feature
about: Suggest new features or improvements to existing ones
title: 'Feature Request: Title Here'
labels: enhancement
assignees: ''
---

**Describe the Feature**
A clear and concise description of what the feature is.

**Why do you want this feature?**
Your reasoning behind suggesting this feature.

**Info**

- How would you be calling / using the script?
- What SQL language(s) does this apply to?
- What Node version? (If applicable)

**Additional context**
Add any other context about the feature here.
33 changes: 33 additions & 0 deletions .github/ISSUE_TEMPLATE/script-bug-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: Script Bug Report
about: Raise an issue with the SCRIPT that occurred during runtime
title: '[SCRIPT] Issue Title Here'
labels: bug
assignees: ''
---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Usage**

- How are you calling / using the script? (Please provide a code snippet)
- What SQL language(s) does this apply to?
- What Node version? (If applicable)

**Additional context**
Add any other context about the problem here.
2 changes: 1 addition & 1 deletion .github/workflows/coveralls.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Coveralls
name: coveralls

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/webpack.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: NodeJS with Webpack
name: webpack

on:
pull_request:
Expand Down
3 changes: 2 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"bracketSpacing": true,
"useTabs": true,
"tabWidth": 2,
"endOfLine": "auto"
"endOfLine": "auto",
"quoteProps": "consistent"
}
8 changes: 4 additions & 4 deletions .release-it.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"requireUpstream": true,
"requireCommits": false,
"addUntrackedFiles": false,
"commit": false,
"commit": true,
"commitMessage": "Release ${version}",
"tag": true,
"tagAnnotation": "${version}",
"push": true,
"pushArgs": ["--follow-tags"],
"pushRepo": ""
"pushArgs": ["--follow-tags"]
},
"npm": {
"publish": true,
Expand All @@ -28,7 +28,7 @@
"release": true,
"releaseName": "${version}",
"releaseNotes": "git log --pretty=format:\"* %s (%h)\" ${latestTag}...HEAD",
"preRelease": true,
"preRelease": false,
"draft": false,
"skipChecks": false,
"web": true
Expand Down
55 changes: 42 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,44 @@
# CHANGELOG

## NEXT [5.0.0] : 2021-11-03
## NEXT [5.0.0] : 2021-11-22

### Added

New Features:
Source:

- added support for ES6 module exports with TypeScript
- updated webpack with ts-loader for module types
- added tsc to babel commonjs build command
- added index.ts pass-through export

Other:

- added GH Actions for CI build
- added issue templates

### Updated

Source:

- updated demo page for all new options

Other:

- renamed library to `prettier-sql`

### Fixed

- fixed bugs related to operator tokens

### Removed

- removed Travis CI (replaced by GH Actions)

## [5.0.0-beta] : 2021-11-03

### Added

Source:

- added option `aliasAs` to toggle use of AS in column, table, query aliases
- modes: always (SELECT and table), select (SELECT only), never
Expand Down Expand Up @@ -45,22 +79,12 @@ Files Added:
- test/newline.js (tests for newline modes)
- test/parenthesis.js (tests for paren positions)

### Removed

Files Removed:

- tokenTypes.ts (token types moved to TokenType enum in token.ts)
- sqlFormatter.d.ts (converted to TypeScript)

### Updated

Major changes:
Source:

- converted repo to Typescript
- overhauled Keyword lists for all languages

Other:

- added default options for all configs
- updated CLI to use config file
- renamed Keyword categories to semantic Keyword types
Expand All @@ -70,3 +94,8 @@ Other:
- reservedWord → reservedKeyword
- added reservedFunctions
- updated Tokenizer class and token.ts to be more DRY

### Removed

- tokenTypes.ts (token types moved to TokenType enum in token.ts)
- sqlFormatter.d.ts (converted to TypeScript)
78 changes: 78 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
## Bugs

Please submit bugs and issues here: https://github.com/inferrinizzard/prettier-sql/issues \
There are issue templates available for FORMATTING or SCRIPT related bugs.

# Development

## Setup

This project uses `yarn` as its package manager, please download it here if you don't already have it:

- yarn: https://yarnpkg.com/getting-started

Once you have `yarn` installed, you can run `yarn` in the root directory to install all dependencies and devDependencies from package.json.

You're now ready to get started !

## Branch Guidelines

New branches: Please branch off of the `develop` branch.

### Naming

Please use one of the following prefixes: (ie. feature/new-feature)

- feature/ - development towards a new feature
- dev/ - misc development not tied to a key feature / refactoring
- issue/ - fix specifically for a issue #
- bug/ - misc bug fixes not tied to a public issue
- repo/ - meta dev related changes (ie. typescript, CI/CD, dependencies)

## Testing

Tests should be run before pushing commits to a remote branch, please do so with the `test` command in package.json \
It can be invoked via:

- `yarn test`
- `npm run test`
- `jest`

## New Tests

Please add new tests for any new features and bug fixes. \
Language-specific tests should be included in their respective Test files, tests that apply to all languages should be in `behavesLikeSqlFormatter.js`

# Contributors

## `prettier-sql`

- Sean Song <[email protected]>

## `sql-formatter`

- Adrien Pyke <[email protected]>
- Andrew
- Benjamin Bellamy
- bingou
- Damon Davison <[email protected]>
- Davut Can Abacigil <[email protected]>
- Erik Hirmo <[email protected]>
- George Leslie-Waksman <[email protected]>
- Ian Campbell <[email protected]>
- ivan baktsheev
- João Pimentel Ferreira
- Martin Nowak <[email protected]>
- Matheus Salmi <[email protected]>
- Matheus Teixeira <[email protected]>
- Nicolas Dermine <[email protected]>
- Offir Baron <[email protected]>
- Olexandr Sydorchuk <[email protected]>
- Rafael Pinto <[email protected]>
- Rahel Rjadnev-Meristo <[email protected]>
- Rene Saarsoo <[email protected]>
- Rodrigo Stuchi
- Sasha Aliashkevich <[email protected]>
- Sergei Egorov <[email protected]>
- Tyler Jones <[email protected]>
- Uku Pattak <[email protected]>
39 changes: 24 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# SQL Formatter [![NPM version](https://img.shields.io/npm/v/prettier-sql.svg)](https://npmjs.com/package/prettier-sql) ![Dev Build](https://github.com/github/docs/actions/workflows/webpack.yaml/badge.svg?event=push&branch=develop) ![Prod Build](https://github.com/github/docs/actions/workflows/webpack.yaml/badge.svg?event=push&branch=master) [![Coverage Status](https://coveralls.io/repos/github/inferrinizzard/prettier-sql/badge.svg?branch=master)](https://coveralls.io/github/inferrrinizzard/prettier-sql?branch=master)
<img src="static/prettier-sql-clean.svg" width="128"/>

# Prettier SQL [![NPM version](https://img.shields.io/npm/v/prettier-sql.svg)](https://npmjs.com/package/prettier-sql) ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/inferrinizzard/prettier-sql/coveralls/develop?label=Dev%20Build&logo=Github) ![GitHub Workflow Status (event)](https://img.shields.io/github/workflow/status/inferrinizzard/prettier-sql/webpack/master?event=push&label=Prod%20Build&logo=Github) ![Coveralls](https://img.shields.io/coveralls/github/inferrinizzard/prettier-sql?branch=master&label=Coverage&logo=coveralls&style=plastic)

## **Prettier SQL** is a JavaScript library for pretty-printing SQL queries.

**SQL Formatter** is a JavaScript library for pretty-printing SQL queries.
It started as a port of a [PHP Library][], but has since considerably diverged.

SQL formatter supports the following dialects:
Prettier SQL supports the following dialects:

- **sql** - [Standard SQL][]
- **mariadb** - [MariaDB][]
Expand All @@ -30,6 +33,7 @@ It does not support:
- [Usage as library](#usage-as-library)
- [Usage from command line](#usage-from-command-line)
- [Usage without NPM](#usage-without-npm)
- [Usage with VSCode](#usage-with-vscode)
- [Contributing](#contributing)

## Install
Expand All @@ -40,6 +44,12 @@ Get the latest version from NPM:
npm install prettier-sql
```

Also available with yarn:

```sh
yarn add prettier-sql
```

## Usage

### Usage as library
Expand Down Expand Up @@ -108,7 +118,7 @@ prettier-sql -h
usage: sqlfmt.js [-h] [-o OUTPUT] \
[-l {db2,mariadb,mysql,n1ql,plsql,postgresql,redshift,spark,sql,tsql}] [-c CONFIG] [--version] [FILE]
SQL Formatter
Prettier SQL
positional arguments:
FILE Input SQL file (defaults to stdin)
Expand All @@ -118,7 +128,7 @@ optional arguments:
-o, --output OUTPUT
File to write SQL output (defaults to stdout)
-l, --language {db2,mariadb,mysql,n1ql,plsql,postgresql,redshift,spark,sql,tsql}
SQL Formatter dialect (defaults to basic sql)
SQL dialect (defaults to standard sql)
-c, --config CONFIG
Path to config json file (will use default configs if unspecified)
--version show program's version number and exit
Expand All @@ -143,14 +153,14 @@ WHERE
The tool also accepts a JSON config file with the `--config` option that takes this form: \
All fields are optional and all fields that are not specified will be filled with their default values

```json
```ts
{
"indent": string,
"uppercase": boolean,
"keywordPosition": "standard" | "tenSpaceLeft" | "tenSpaceRight",
"newline": {
"mode": "always" | "itemCount" | "lineWidth" | "hybrid" | "never",
"itemCount":? number
"itemCount"?: number // only used if newline.mode is itemCount or hybrid
},
"breakBeforeBooleanOperator": boolean,
"aliasAs": "always" | "select" | "never",
Expand All @@ -170,21 +180,20 @@ All fields are optional and all fields that are not specified will be filled wit
### Usage without NPM

If you don't use a module bundler, clone the repository, run `npm install` and grab a file from `/dist` directory to use inside a `<script>` tag.
This makes SQL Formatter available as a global variable `window.sqlFormatter`.
This makes Prettier SQL available as a global variable `window.prettierSql`.

## Contributing
### Usage with VSCode

Make sure to run all checks:
Prettier SQL is also available as a VSCode extension here: \
https://marketplace.visualstudio.com/items?itemName=inferrinizzard.prettier-sql-vscode

```sh
npm run check
```
## Contributing

...and you're ready to poke us with a pull request.
Please see [CONTRIBUTING.md](CONTRIBUTING.md)

## License

[MIT](https://github.com/inferrinizzard/prettier-sql/blob/master/LICENSE)
[MIT](LICENSE)

[php library]: https://github.com/jdorn/sql-formatter
[standard sql]: https://en.wikipedia.org/wiki/SQL:2011
Expand Down
Loading

0 comments on commit 63c05eb

Please sign in to comment.