Skip to content

Commit f41da14

Browse files
committed
fix eslint
1 parent 7c0c0d2 commit f41da14

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

packages/addons/eslint/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default defineAddon({
5252
});
5353

5454
sv.file('eslint.config.js', (content) => {
55-
const { ast, generateCode } = parseScript(content);
55+
const { ast, additionalComments, generateCode } = parseScript(content);
5656

5757
const eslintConfigs: Array<AstTypes.Expression | AstTypes.SpreadElement> = [];
5858
imports.addDefault(ast, { from: './svelte.config.js', as: 'svelteConfig' });
@@ -84,18 +84,20 @@ export default defineAddon({
8484
if (rules.properties[0].type !== 'Property') {
8585
throw new Error('rules.properties[0].type !== "Property"');
8686
}
87-
rules.properties[0].key.leadingComments = [
87+
additionalComments.set(rules.properties[0].key, [
8888
{
8989
type: 'Line',
9090
value:
91-
' typescript-eslint strongly recommend that you do not use the no-undef lint rule on TypeScript projects.'
91+
' typescript-eslint strongly recommend that you do not use the no-undef lint rule on TypeScript projects.',
92+
position: 'leading'
9293
},
9394
{
9495
type: 'Line',
9596
value:
96-
' see: https://typescript-eslint.io/troubleshooting/faqs/eslint/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors'
97+
' see: https://typescript-eslint.io/troubleshooting/faqs/eslint/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors',
98+
position: 'leading'
9799
}
98-
];
100+
]);
99101

100102
const globalsConfig = object.create({
101103
languageOptions: {

packages/core/tooling/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export type {
5353
export function parseScript(content: string): {
5454
ast: TsEstree.Program;
5555
comments: TsEstree.Comment[];
56+
additionalComments: WeakMap<TsEstree.Node, AdditionalComment[]>;
5657
} {
5758
const comments: TsEstree.Comment[] = [];
5859

@@ -86,7 +87,8 @@ export function parseScript(content: string): {
8687

8788
return {
8889
ast,
89-
comments
90+
comments,
91+
additionalComments: new WeakMap()
9092
};
9193
}
9294

packages/core/tooling/parsers.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
import * as utils from './index.ts';
22
import MagicString from 'magic-string';
3+
import type { TsEstree } from './js/ts-estree.ts';
4+
import type { AdditionalComment } from 'esrap/languages/ts';
35

46
type ParseBase = {
57
source: string;
68
generateCode(): string;
79
};
810

9-
export function parseScript(
10-
source: string
11-
): { ast: utils.AstTypes.Program; comments: utils.AstTypes.Comment[] } & ParseBase {
12-
const { ast, comments } = utils.parseScript(source);
13-
const generateCode = () => utils.serializeScript(ast, comments, source);
11+
export function parseScript(source: string): {
12+
ast: utils.AstTypes.Program;
13+
comments: utils.AstTypes.Comment[];
14+
additionalComments: WeakMap<TsEstree.Node, AdditionalComment[]>;
15+
} & ParseBase {
16+
const { ast, comments, additionalComments } = utils.parseScript(source);
17+
const generateCode = () => utils.serializeScript(ast, comments, source, additionalComments);
1418

15-
return { ast, comments, source, generateCode };
19+
return { ast, comments, additionalComments, source, generateCode };
1620
}
1721

1822
export function parseCss(source: string): { ast: utils.CssAst } & ParseBase {

0 commit comments

Comments
 (0)