Skip to content

Commit

Permalink
prettier, eslint, and package upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
gwax committed Jul 6, 2020
1 parent e695f66 commit dc3b6c4
Show file tree
Hide file tree
Showing 27 changed files with 12,934 additions and 6,969 deletions.
13 changes: 2 additions & 11 deletions .babelrc
@@ -1,13 +1,4 @@
{
"presets": [
["es2015", {"loose": true}]
],
"plugins": [
"add-module-exports",
"transform-class-properties",
"transform-function-bind",
"transform-object-rest-spread",
"transform-es3-member-expression-literals",
"transform-es3-property-literals"
]
"presets": ["@babel/preset-env"],
"plugins": ["@babel/plugin-proposal-class-properties", "add-module-exports"]
}
4 changes: 0 additions & 4 deletions .editorconfig
Expand Up @@ -6,8 +6,4 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 4

[{package.json,.travis.yml}]
indent_style = space
indent_size = 2
21 changes: 17 additions & 4 deletions .eslintrc
@@ -1,6 +1,19 @@
{
"extends": "zt/base",
"env": {
"jest": true
}
"extends": ["airbnb-base", "prettier"],
"plugins": ["prettier"],
"rules": {
"prettier/prettier": ["error"],
"import/no-useless-path-segments": "warn",
"func-names": "warn",
"no-useless-concat": "warn",
"class-methods-use-this": "warn",
"no-param-reassign": "warn",
"prefer-template": "warn",
"no-plusplus": "warn",
"no-else-return": "warn",
"consistent-return": "warn"
},
"env": {
"jest": true
}
}
4 changes: 4 additions & 0 deletions .prettierignore
@@ -0,0 +1,4 @@
/coverage
/dist
/lib
/node_modules
4 changes: 4 additions & 0 deletions .prettierrc.json
@@ -0,0 +1,4 @@
{
"printWidth": 100,
"singleQuote": true
}
22 changes: 11 additions & 11 deletions README.md
Expand Up @@ -2,7 +2,7 @@

**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.
It supports [Standard SQL][], [Couchbase N1QL][], [IBM DB2][] and [Oracle PL/SQL][] dialects.
It supports [Standard SQL][], [Couchbase N1QL][], [IBM DB2][] and [Oracle PL/SQL][] dialects.

→ [Try the demo.](https://zeroturnaround.github.io/sql-formatter/)

Expand All @@ -17,9 +17,9 @@ npm install sql-formatter
## Usage

```js
import sqlFormatter from "sql-formatter";
import sqlFormatter from 'sql-formatter';

console.log(sqlFormatter.format("SELECT * FROM table1"));
console.log(sqlFormatter.format('SELECT * FROM table1'));
```

This will output:
Expand All @@ -34,9 +34,9 @@ FROM
You can also pass in configuration options:

```js
sqlFormatter.format("SELECT *", {
language: "n1ql", // Defaults to "sql"
indent: " " // Defaults to two spaces
sqlFormatter.format('SELECT *', {
language: 'n1ql', // Defaults to "sql"
indent: ' ', // Defaults to two spaces
});
```

Expand Down Expand Up @@ -90,8 +90,8 @@ $ npm run check

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

[PHP library]: https://github.com/jdorn/sql-formatter
[Standard SQL]: https://en.wikipedia.org/wiki/SQL:2011
[Couchbase N1QL]: http://www.couchbase.com/n1ql
[IBM DB2]: https://www.ibm.com/analytics/us/en/technology/db2/
[Oracle PL/SQL]: http://www.oracle.com/technetwork/database/features/plsql/index.html
[php library]: https://github.com/jdorn/sql-formatter
[standard sql]: https://en.wikipedia.org/wiki/SQL:2011
[couchbase n1ql]: http://www.couchbase.com/n1ql
[ibm db2]: https://www.ibm.com/analytics/us/en/technology/db2/
[oracle pl/sql]: http://www.oracle.com/technetwork/database/features/plsql/index.html
235 changes: 127 additions & 108 deletions index.html
@@ -1,133 +1,152 @@
<!doctype html>
<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8">
<head>
<meta charset="utf-8" />

<title>SQL formatter</title>
<meta name="description" content="A whitespace formatter for different query languages">
<meta name="description" content="A whitespace formatter for different query languages" />

<meta property="og:title" content="SQL Formatter">
<meta property="og:description" content="A whitespace formatter for different query languages">
<meta property="og:url" content="https://zeroturnaround.github.io/sql-formatter">
<meta property="og:title" content="SQL Formatter" />
<meta
property="og:description"
content="A whitespace formatter for different query languages"
/>
<meta property="og:url" content="https://zeroturnaround.github.io/sql-formatter" />

<link rel="shortcut icon" href="http://static.zeroturnaround.com/theme55/images/favicon.ico">
<link rel="shortcut icon" href="http://static.zeroturnaround.com/theme55/images/favicon.ico" />

<link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet" />

<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
font-family: 'Roboto Mono', monospace;
}
header {
position: relative;
height: 120px;
padding: 10px 20px;
border-bottom: 2px solid #8DC63F;
box-sizing: border-box;
}
.select-wrapper {
position: absolute;
bottom: 0;
left: 50%;
transform: translate(-50%, -50%);
}
h1 {
margin: 0 0 8px 0;
}
a {
text-decoration: none;
}
main {
overflow: hidden;
display: flex;
flex-direction: row;
-webkit-align-items: stretch;
align-items: stretch;
height: calc(100% - 120px);
}
.input, .output {
display: flex;
-webkit-align-items: stretch;
align-items: stretch;
width: 50%;
height: 100%;
}
.output {
border-left: 2px solid #8DC63F;
}
textarea {
width: 100%;
padding: 20px;
border: 0;
box-sizing: border-box;
font-size: 1.3em;
resize: none;
outline: none;
line-height: 1.3;
font-family: 'Roboto Mono', monospace;
}
html,
body {
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
font-family: 'Roboto Mono', monospace;
}
header {
position: relative;
height: 120px;
padding: 10px 20px;
border-bottom: 2px solid #8dc63f;
box-sizing: border-box;
}
.select-wrapper {
position: absolute;
bottom: 0;
left: 50%;
transform: translate(-50%, -50%);
}
h1 {
margin: 0 0 8px 0;
}
a {
text-decoration: none;
}
main {
overflow: hidden;
display: flex;
flex-direction: row;
-webkit-align-items: stretch;
align-items: stretch;
height: calc(100% - 120px);
}
.input,
.output {
display: flex;
-webkit-align-items: stretch;
align-items: stretch;
width: 50%;
height: 100%;
}
.output {
border-left: 2px solid #8dc63f;
}
textarea {
width: 100%;
padding: 20px;
border: 0;
box-sizing: border-box;
font-size: 1.3em;
resize: none;
outline: none;
line-height: 1.3;
font-family: 'Roboto Mono', monospace;
}
</style>
</head>
</head>

<body>
<body>
<header>
<h1>SQL Formatter</h1>
<h1>SQL Formatter</h1>

<div class="buttons">
<a href="https://www.npmjs.com/package/sql-formatter">
<img src="https://img.shields.io/npm/v/sql-formatter.svg" height="18" />
</a>
<iframe src="https://ghbtns.com/github-btn.html?user=zeroturnaround&repo=sql-formatter&type=star&count=true" frameborder="0" scrolling="0" width="120px" height="20px" style="position: relative;top: 1px;"></iframe>
</div>
<div class="buttons">
<a href="https://www.npmjs.com/package/sql-formatter">
<img src="https://img.shields.io/npm/v/sql-formatter.svg" height="18" />
</a>
<iframe
src="https://ghbtns.com/github-btn.html?user=zeroturnaround&repo=sql-formatter&type=star&count=true"
frameborder="0"
scrolling="0"
width="120px"
height="20px"
style="position: relative; top: 1px;"
></iframe>
</div>

<div class="select-wrapper">
Format
<select id="language">
<option value="sql">
SQL
</option>
<option value="n1ql">
N1QL
</option>
<option value="db2">
DB2
</option>
</select>
</div>
<div class="select-wrapper">
Format
<select id="language">
<option value="sql">
SQL
</option>
<option value="n1ql">
N1QL
</option>
<option value="db2">
DB2
</option>
</select>
</div>
</header>
<main>
<section class="input">
<textarea id="input" autofocus="true" wrap="off">SELECT supplier_name, city FROM suppliers&#10;WHERE supplier_id > 500&#10;ORDER BY supplier_name ASC, city DESC;</textarea>
</section>
<section class="output">
<textarea id="output" readonly="true" wrap="off"></textarea>
</section>
<section class="input">
<textarea id="input" autofocus="true" wrap="off">
SELECT supplier_name, city FROM suppliers&#10;WHERE supplier_id > 500&#10;ORDER BY supplier_name ASC, city DESC;</textarea
>
</section>
<section class="output">
<textarea id="output" readonly="true" wrap="off"></textarea>
</section>
</main>

<script type="text/javascript" src="https://unpkg.com/sql-formatter@latest/dist/sql-formatter.min.js"></script>
<script
type="text/javascript"
src="https://unpkg.com/sql-formatter@latest/dist/sql-formatter.min.js"
></script>
<script>
(function() {
let language = document.getElementById('language');
let input = document.getElementById('input');
let output = document.getElementById('output');
(function () {
let language = document.getElementById('language');
let input = document.getElementById('input');
let output = document.getElementById('output');

input.addEventListener('input', format);
language.addEventListener('change', format);
input.addEventListener('input', format);
language.addEventListener('change', format);

function format() {
console.time('formatting');
function format() {
console.time('formatting');

output.value = sqlFormatter.format(input.value, {language: language.options[language.selectedIndex].value});
output.value = sqlFormatter.format(input.value, {
language: language.options[language.selectedIndex].value,
});

console.timeEnd('formatting');
}
format();
})();
console.timeEnd('formatting');
}
format();
})();
</script>
</body>
</body>
</html>

0 comments on commit dc3b6c4

Please sign in to comment.