Skip to content

Commit 1a23a3f

Browse files
committed
fix: gracefully fail
1 parent 0ea6593 commit 1a23a3f

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/rules/format.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ export const rule = createRule<Options, MessageIds>({
101101

102102
const sqlTagIsPresent = tagName === sqlTag;
103103

104+
if (ignoreTagless && !sqlTagIsPresent) {
105+
return;
106+
}
107+
108+
if (ignoreExpressions && node.quasis.length !== 1) {
109+
return;
110+
}
111+
104112
const templateElement = node.quasis.find((quasi) => {
105113
return quasi.type === AST_NODE_TYPES.TemplateElement;
106114
});
@@ -118,23 +126,15 @@ export const rule = createRule<Options, MessageIds>({
118126

119127
const lastLine = lines[lines.length - 1];
120128

121-
if (!lastLine) {
122-
throw new Error('Unexpected');
123-
}
124-
125-
indentAnchorOffset = lastLine.length;
129+
if (lastLine) {
130+
indentAnchorOffset = lastLine.length;
131+
} else {
132+
indentAnchorOffset = 0;
133+
}
126134
} else if (templateElement.value.raw.search(/\S/u) === 0) {
127135
indentAnchorOffset = tabWidth;
128136
}
129137

130-
if (ignoreTagless && !sqlTagIsPresent) {
131-
return;
132-
}
133-
134-
if (ignoreExpressions && node.quasis.length !== 1) {
135-
return;
136-
}
137-
138138
const magic = '"gajus-eslint-plugin-sql"';
139139

140140
const literal = node.quasis

0 commit comments

Comments
 (0)