Skip to content

Commit

Permalink
feat(addons): Respect .gitignore in eslint addon (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
ieedan authored Dec 2, 2024
1 parent 478b72c commit 33ecdd5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-peas-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sv': patch
---

feat: respect `.gitignore` in `eslint` add-on
16 changes: 11 additions & 5 deletions packages/addons/eslint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default defineAddon({
const prettierInstalled = Boolean(dependencyVersion('prettier'));

sv.devDependency('eslint', '^9.7.0');
sv.devDependency('@eslint/compat', '^1.2.3');
sv.devDependency('globals', '^15.0.0');
sv.devDependency('eslint-plugin-svelte', '^2.36.0');

Expand Down Expand Up @@ -56,6 +57,14 @@ export default defineAddon({
AstKinds.ExpressionKind | AstTypes.SpreadElement | AstTypes.ObjectExpression
> = [];

const gitIgnorePathStatement = common.statementFromString(
'\nconst gitignorePath = fileURLToPath(new URL("./.gitignore", import.meta.url));'
);
common.addStatement(ast, gitIgnorePathStatement);

const ignoresConfig = common.expressionFromString('includeIgnoreFile(gitignorePath)');
eslintConfigs.push(ignoresConfig);

const jsConfig = common.expressionFromString('js.configs.recommended');
eslintConfigs.push(jsConfig);

Expand Down Expand Up @@ -92,11 +101,6 @@ export default defineAddon({
eslintConfigs.push(svelteTSParserConfig);
}

const ignoresConfig = object.create({
ignores: common.expressionFromString('["build/", ".svelte-kit/", "dist/"]')
});
eslintConfigs.push(ignoresConfig);

let exportExpression: AstTypes.ArrayExpression | AstTypes.CallExpression;
if (typescript) {
const tsConfigCall = functions.call('ts.config', []);
Expand All @@ -121,8 +125,10 @@ export default defineAddon({

// imports
if (typescript) imports.addDefault(ast, 'typescript-eslint', 'ts');
imports.addNamed(ast, 'node:url', { fileURLToPath: 'fileURLToPath' });
imports.addDefault(ast, 'globals', 'globals');
imports.addDefault(ast, 'eslint-plugin-svelte', 'svelte');
imports.addNamed(ast, '@eslint/compat', { includeIgnoreFile: 'includeIgnoreFile' });
imports.addDefault(ast, '@eslint/js', 'js');

return generateCode();
Expand Down
2 changes: 2 additions & 0 deletions packages/create/templates/demo/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ node_modules
# Output
.output
.vercel
.netlify
.wrangler
/.svelte-kit
/build

Expand Down
2 changes: 2 additions & 0 deletions packages/create/templates/library/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ node_modules
# Output
.output
.vercel
.netlify
.wrangler
/.svelte-kit
/build
/dist
Expand Down
2 changes: 2 additions & 0 deletions packages/create/templates/minimal/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ node_modules
# Output
.output
.vercel
.netlify
.wrangler
/.svelte-kit
/build

Expand Down

0 comments on commit 33ecdd5

Please sign in to comment.