Skip to content

Commit d2a9927

Browse files
authored
chore: disable no-undef ESLint rule in TypeScript project (#483)
* chore: disable `no-unused-vars` ESLint rule in TypeScript project * no-unused-vars -> no-undef * better format
1 parent 1184c1a commit d2a9927

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

.changeset/rich-zebras-hunt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'sv': patch
3+
---
4+
5+
chore: disable `no-undef` ESLint rule in TypeScript project

packages/addons/eslint/index.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,31 @@ export default defineAddon({
8585
const globalsNode = common.createSpreadElement(common.expressionFromString('globals.node'));
8686
const globalsObjLiteral = object.createEmpty();
8787
globalsObjLiteral.properties = [globalsBrowser, globalsNode];
88+
const off = common.createLiteral('off');
89+
const rules = object.create({
90+
'"no-undef"': off
91+
});
92+
93+
if (rules.properties[0].type !== 'ObjectProperty') {
94+
throw new Error('rules.properties[0].type !== "ObjectProperty"');
95+
}
96+
rules.properties[0].key.comments = [
97+
{
98+
type: 'Block',
99+
value:
100+
'*\n * typescript-eslint strongly recommend that you do not use the no-undef lint rule on TypeScript projects.\n * 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\n ',
101+
leading: true,
102+
trailing: false
103+
}
104+
];
105+
88106
const globalsConfig = object.create({
89107
languageOptions: object.create({
90108
globals: globalsObjLiteral
91-
})
109+
}),
110+
rules: typescript ? rules : undefined
92111
});
112+
93113
eslintConfigs.push(globalsConfig);
94114

95115
if (typescript) {

0 commit comments

Comments
 (0)