Skip to content

Commit fefe975

Browse files
committed
fix: remove unnecessary use of astring
1 parent 384893d commit fefe975

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

cspell.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ words:
88
- slonik
99
- tagless
1010
- gitdown
11-
- astring
1211
- quasis
1312
- singlestoredb
1413
- tidb

package-lock.json

Lines changed: 0 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
},
77
"dependencies": {
88
"@typescript-eslint/utils": "^8.18.1",
9-
"astring": "^1.9.0",
109
"debug": "^4.4.0",
1110
"lodash": "^4.17.21",
1211
"multiline-ts": "^4.0.1",

src/rules/format.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,36 @@ export default createRuleTester(
88
{},
99
{
1010
invalid: [
11+
{
12+
code: multiline`
13+
await pool.query(sql.typeAlias('void')\`
14+
UPDATE assistant_response
15+
SET
16+
messages = \${sql.jsonb(pickedMessages as unknown as SerializableValue[])}
17+
WHERE id = \${assistantResponse.id}
18+
\`);
19+
`,
20+
errors: [
21+
{
22+
messageId: 'format',
23+
},
24+
],
25+
options: [
26+
{},
27+
{
28+
tabWidth: 4,
29+
},
30+
],
31+
output: multiline`
32+
await pool.query(sql.typeAlias('void')\`
33+
UPDATE assistant_response
34+
SET
35+
messages = \${sql.jsonb(pickedMessages as unknown as SerializableValue[])}
36+
WHERE
37+
id = \${assistantResponse.id}
38+
\`);
39+
`,
40+
},
1141
{
1242
code: multiline`
1343
sql\`

src/rules/format.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { createRule } from '../factories/createRule';
22
import { dropBaseIndent } from '../utilities/dropBaseIndent';
33
import { isSqlQuery } from '../utilities/isSqlQuery';
44
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
5-
import { generate } from 'astring';
65
import { format } from 'sql-formatter';
76

87
type MessageIds = 'format';
@@ -174,12 +173,15 @@ export const rule = createRule<Options, MessageIds>({
174173
let final = formatted;
175174

176175
const expressionCount = node.expressions.length;
176+
177177
let index = 0;
178178

179179
while (index <= expressionCount - 1) {
180180
final = final.replace(
181181
magic,
182-
'${' + generate(node.expressions[index]) + '}',
182+
'${' +
183+
context.sourceCode.getText(node.expressions[index]) +
184+
'}',
183185
);
184186

185187
index++;

0 commit comments

Comments
 (0)