Skip to content

Commit eacd3b4

Browse files
committed
docs: document fixed code
1 parent e860270 commit eacd3b4

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

.README/rules/format.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ The first option is an object with the following configuration.
1717
|`ignoreTagless`|boolean|`true`|Does not format queries that are written without using `sql` tag.|
1818

1919
The second option is an object with the [`pg-formatter` configuration](https://github.com/gajus/pg-formatter#configuration).
20+
21+
<!-- assertions format -->

README.md

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# eslint-plugin-sql
33

44
[![Travis build status](http://img.shields.io/travis/gajus/eslint-plugin-sql/master.svg?style=flat-square)](https://travis-ci.org/gajus/eslint-plugin-sql)
5-
[![Coveralls](https://img.shields.io/coveralls/gajus/eslint-plugin-sql.svg?style=flat-square)](https://coveralls.io/github/gajus/eslint-plugin-sql)
65
[![NPM version](http://img.shields.io/npm/v/eslint-plugin-sql.svg?style=flat-square)](https://www.npmjs.org/package/eslint-plugin-sql)
76
[![Canonical Code Style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)
87
[![Twitter Follow](https://img.shields.io/twitter/follow/kuizinas.svg?style=social&label=Follow)](https://twitter.com/kuizinas)
@@ -87,6 +86,59 @@ The first option is an object with the following configuration.
8786

8887
The second option is an object with the [`pg-formatter` configuration](https://github.com/gajus/pg-formatter#configuration).
8988

89+
The following patterns are considered problems:
90+
91+
```js
92+
`SELECT 1`
93+
// Options: [{"ignoreInline":false,"ignoreTagless":false}]
94+
// Message: Format the query
95+
// Fixed code:
96+
// `SELECT
97+
// 1
98+
// `
99+
100+
`SELECT 2`
101+
// Options: [{"ignoreInline":false,"ignoreTagless":false},{"spaces":2}]
102+
// Message: Format the query
103+
// Fixed code:
104+
// `SELECT
105+
// 2
106+
// `
107+
108+
sql`SELECT 3`
109+
// Options: [{"ignoreInline":false}]
110+
// Message: Format the query
111+
// Fixed code:
112+
// sql`SELECT
113+
// 3
114+
// `
115+
116+
`SELECT ${'foo'} FROM ${'bar'}`
117+
// Options: [{"ignoreInline":false,"ignoreTagless":false}]
118+
// Message: Format the query
119+
// Fixed code:
120+
// `SELECT
121+
// ${'foo'}
122+
// FROM
123+
// ${'bar'}
124+
// `
125+
```
126+
127+
The following patterns are not considered problems:
128+
129+
```js
130+
sql`SELECT 1`
131+
// Options: [{"ignoreInline":true}]
132+
133+
`SELECT 2`
134+
// Options: [{"ignoreTagless":true}]
135+
136+
`SELECT ${'foo'} FROM ${'bar'}`
137+
// Options: [{"ignoreExpressions":true,"ignoreInline":false,"ignoreTagless":false}]
138+
```
139+
140+
141+
90142
<a name="eslint-plugin-sql-rules-no-unsafe-query"></a>
91143
### <code>no-unsafe-query</code>
92144

@@ -122,8 +174,8 @@ foo`SELECT ${'bar'}`
122174
The following patterns are not considered problems:
123175

124176
```js
125-
// Options: [{"allowLiteral":true}]
126177
`SELECT 1`
178+
// Options: [{"allowLiteral":true}]
127179

128180
sql`SELECT 1`
129181

bin/readmeAssertions.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import glob from 'glob';
1010
const formatCodeSnippet = (setup) => {
1111
const paragraphs = [];
1212

13+
paragraphs.push(setup.code);
14+
1315
if (setup.options) {
1416
paragraphs.push('// Options: ' + JSON.stringify(setup.options));
1517
}
1618

17-
paragraphs.push(setup.code);
18-
1919
if (setup.errors) {
2020
setup.errors.forEach((message) => {
2121
paragraphs.push('// Message: ' + message.message);
@@ -26,6 +26,10 @@ const formatCodeSnippet = (setup) => {
2626
paragraphs.push('// Additional rules: ' + JSON.stringify(setup.rules));
2727
}
2828

29+
if (setup.output) {
30+
paragraphs.push('// Fixed code: \n// ' + setup.output.split('\n').join('\n// '));
31+
}
32+
2933
return paragraphs.join('\n');
3034
};
3135

0 commit comments

Comments
 (0)