Skip to content

Commit c58122c

Browse files
committed
feat: forward eslint ignores
feat: disable ts rule `no-unused-expressions` in Svelte for $effects feat: Svelte-rules only in Svelte files breaking: rename `repo-package` to `repo-pack`
1 parent 03ac53e commit c58122c

File tree

8 files changed

+160
-86
lines changed

8 files changed

+160
-86
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ Bun-engine driven tools used for development, build, package release and more.
66

77
### ESLint
88

9+
Create a script that fixes issues, and also removes unused imports:
10+
```
11+
"scripts": {
12+
"format": "bun --bun eslint --config ./eslint.config.ts --rule 'unused-imports/no-unused-imports: [warn]' --fix . "
13+
},
14+
```
15+
916
`eslint.config.ts`
1017
```ts
11-
import eslint from 'github:refzlund/repo/eslint'
18+
import eslint from '@refzlund/repo/eslint'
1219

1320
const config = eslint(import.meta.url)
1421

@@ -23,7 +30,7 @@ export default config
2330
`tsconfig.json`
2431
```jsonc
2532
{
26-
"extends": "github:refzlund/repo/tsconfig.base.json"
33+
"extends": "@refzlund/repo/tsconfig.base.json"
2734
}
2835
```
2936

@@ -33,12 +40,12 @@ export default config
3340
### CLI colors and spinners
3441

3542
```ts
36-
import 'github:refzlund/repo/cli-colors' // via `colors`
43+
import '@refzlund/repo/cli-colors' // via `colors`
3744
console.log('text'.green)
3845
```
3946

4047
```ts
41-
import spin 'github:refzlund/repo/cli-spinner' // via `ora`
48+
import spin '@refzlund/repo/cli-spinner' // via `ora`
4249
const spinner = spin('Loading...')
4350
spinner.succeed('Successful!')
4451
```
@@ -49,7 +56,7 @@ spinner.succeed('Successful!')
4956
5057
### Packaging for publish
5158
52-
Via `bunx repo-package`
59+
Via `bunx repo-pack`
5360
5461
> ⠴ Packaging my-package v2.0.3
5562
> ✔ Finished packaging my-package v2.0.3 -> _package
File renamed without changes.

config/eslint/eslint-config.ts

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,59 @@ import 'eslint-import-resolver-typescript' // required for eslint-plugin-import-
1717
import tailwind from 'eslint-plugin-tailwindcss'
1818

1919
// Config
20-
import { IGNORE_PATTERNS } from './ignore-patterns'
20+
import { ignorePatterns } from './ignore-patterns'
2121
import { SLOW_RULES } from './slow-rules'
2222
import { IMPORTING_RULES } from './importing-rules'
2323
import { TYPESCRIPT_RULES } from './typescript-rules'
2424
import { STYLISTIC_RULES } from './stylistic-rules'
25-
import { SVELTE_RULES } from './svelte-rules'
25+
import { svelteESLint } from './svelte-rules'
26+
import type { ParserOptions } from './eslint-types.js'
2627

27-
export function eslint(metaURL: string) {
28+
interface ESLintOptions {
29+
/**
30+
### Default ignores
31+
32+
'\*\*\/.svelte-kit/*'
33+
'\*\*\/node_modules/**'
34+
'\*\*\/node_modules/zod/**'
35+
'\*\*\/node_modules/zod/lib/**'
36+
'\*\*\/node_modules/zod/lib/index.mjs'
37+
'\*\*\/.wrangler/*'
38+
'\*\*\/.git/*'
39+
'\*\*\/.mongodb/*'
40+
'\*\*\/.cloudflare/*'
41+
'\*\*\/lang/src/paraglide/*'
42+
'\*\*\/src-tauri/target/*'
43+
'\*\*\/_package/*'
44+
'\*\*\/.turbo/**'
45+
*/
46+
ignores?: string[]
47+
}
48+
49+
export default function eslint(metaURL: string, opts: ESLintOptions = {}) {
2850
const gitignorePath = fileURLToPath(new URL('./.gitignore', metaURL))
2951
const tsconfigPath = fileURLToPath(new URL('./tsconfig.json', metaURL))
3052
const tsconfigPaths = fileURLToPath(new URL('./*/tsconfig.json', metaURL))
3153

54+
const parserOptions = {
55+
projectService: { defaultProject: tsconfigPath },
56+
parser: ts.parser,
57+
// Optimizing for performance
58+
tsconfigRootDir: metaURL,
59+
project: [
60+
tsconfigPath,
61+
tsconfigPaths
62+
],
63+
extraFileExtensions: ['.svelte'],
64+
svelteConfig,
65+
cacheLifetime: { glob: 'Infinity' },
66+
// Add cache strategy for better performance
67+
cache: true
68+
} satisfies ParserOptions
69+
3270
return ts.config(
3371
includeIgnoreFile(gitignorePath),
34-
IGNORE_PATTERNS,
72+
ignorePatterns(...(opts?.ignores || [])),
3573
js.configs.recommended,
3674
ts.configs.recommended,
3775
svelte.configs.recommended,
@@ -45,21 +83,7 @@ export function eslint(metaURL: string) {
4583
...globals.browser,
4684
...globals.node
4785
},
48-
parserOptions: {
49-
projectService: { defaultProject: tsconfigPath },
50-
extraFileExtensions: ['.svelte'],
51-
parser: ts.parser,
52-
svelteConfig,
53-
// Optimizing for performance
54-
tsconfigRootDir: metaURL,
55-
project: [
56-
tsconfigPath,
57-
tsconfigPaths
58-
],
59-
cacheLifetime: { glob: 'Infinity' },
60-
// Add cache strategy for better performance
61-
cache: true
62-
}
86+
parserOptions
6387
},
6488
plugins: {
6589
'@stylistic': stylistic,
@@ -70,10 +94,9 @@ export function eslint(metaURL: string) {
7094
...SLOW_RULES,
7195
...IMPORTING_RULES,
7296
...TYPESCRIPT_RULES,
73-
...STYLISTIC_RULES,
74-
...SVELTE_RULES
97+
...STYLISTIC_RULES
7598
}
76-
}
77-
99+
},
100+
svelteESLint(svelteConfig, parserOptions)
78101
)
79102
}

config/eslint/eslint-types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type { ConfigWithExtends } from 'typescript-eslint'
2+
3+
export type ParserOptions = NonNullable<NonNullable<ConfigWithExtends['languageOptions']>['parserOptions']>

config/eslint/ignore-patterns.ts

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
11
import { globalIgnores } from 'eslint/config'
22

3-
export const IGNORE_PATTERNS = globalIgnores([
4-
'**/.svelte-kit/*',
5-
'**/node_modules/**',
6-
'**/node_modules/zod/**',
7-
'**/node_modules/zod/lib/**',
8-
'**/node_modules/zod/lib/index.mjs',
9-
'**/.wrangler/*',
10-
'**/.git/*',
11-
'**/.mongodb/*',
12-
'**/.cloudflare/*',
13-
'**/lang/src/paraglide/*',
14-
'**/src-tauri/target/*',
15-
'**/.turbo/**'
16-
])
3+
/**
4+
### Default ignores
5+
6+
'\*\*\/.svelte-kit/*'
7+
'\*\*\/node_modules/**'
8+
'\*\*\/node_modules/zod/**'
9+
'\*\*\/node_modules/zod/lib/**'
10+
'\*\*\/node_modules/zod/lib/index.mjs'
11+
'\*\*\/.wrangler/*'
12+
'\*\*\/.git/*'
13+
'\*\*\/.mongodb/*'
14+
'\*\*\/.cloudflare/*'
15+
'\*\*\/lang/src/paraglide/*'
16+
'\*\*\/src-tauri/target/*'
17+
'\*\*\/_package/*'
18+
'\*\*\/.turbo/**'
19+
*/
20+
export function ignorePatterns(...patterns: string[]) {
21+
return globalIgnores([
22+
'**/.svelte-kit/*',
23+
'**/node_modules/**',
24+
'**/node_modules/zod/**',
25+
'**/node_modules/zod/lib/**',
26+
'**/node_modules/zod/lib/index.mjs',
27+
'**/.wrangler/*',
28+
'**/.git/*',
29+
'**/.mongodb/*',
30+
'**/.cloudflare/*',
31+
'**/lang/src/paraglide/*',
32+
'**/src-tauri/target/*',
33+
'**/_package/*',
34+
'**/.turbo/**',
35+
...patterns
36+
])
37+
}

config/eslint/svelte-rules.ts

Lines changed: 61 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,64 @@
1-
import type { RuleEntry } from '@eslint/config-helpers'
1+
import type { ConfigWithExtends } from 'typescript-eslint'
2+
import type { ParserOptions } from './eslint-types'
23

3-
export const SVELTE_RULES = {
4-
'svelte/html-quotes': ['error', { 'prefer': 'single' }],
5-
'svelte/max-attributes-per-line': [
6-
'error',
7-
{
8-
'multiline': 1,
9-
'singleline': 2
10-
}
11-
],
12-
'svelte/indent': ['error', { 'indent': 'tab' }],
13-
'svelte/shorthand-attribute': 'error',
14-
'svelte/shorthand-directive': 'error',
15-
'svelte/sort-attributes': 'error',
16-
'svelte/spaced-html-comment': 'error',
17-
'svelte/no-spaces-around-equal-signs-in-attribute': 'error',
18-
'svelte/first-attribute-linebreak': [
19-
'error',
20-
{
21-
'multiline': 'below',
22-
'singleline': 'beside'
23-
}
24-
],
25-
'svelte/html-closing-bracket-new-line': [
26-
'error',
27-
{
28-
'singleline': 'never',
29-
'multiline': 'always',
30-
'selfClosingTag': {
31-
'singleline': 'never',
32-
'multiline': 'always'
4+
export function svelteESLint(
5+
svelteConfig: unknown,
6+
parserOptions: ParserOptions
7+
) {
8+
return {
9+
files: ['**/*.{js,mjs,cjs,ts,svelte}'],
10+
ignores: ['./**/node_modules/**'],
11+
languageOptions: {
12+
parserOptions: {
13+
...parserOptions,
14+
extraFileExtensions: ['.svelte'],
15+
svelteConfig
3316
}
17+
},
18+
rules: {
19+
// used in $effects to trigger them
20+
'@typescript-eslint/no-unused-expressions': 'off',
21+
22+
'svelte/html-quotes': ['error', { 'prefer': 'single' }],
23+
'svelte/max-attributes-per-line': [
24+
'error',
25+
{
26+
'multiline': 1,
27+
'singleline': 2
28+
}
29+
],
30+
'svelte/indent': ['error', { 'indent': 'tab' }],
31+
'svelte/shorthand-attribute': 'error',
32+
'svelte/shorthand-directive': 'error',
33+
'svelte/sort-attributes': 'error',
34+
'svelte/spaced-html-comment': 'error',
35+
'svelte/no-spaces-around-equal-signs-in-attribute': 'error',
36+
'svelte/first-attribute-linebreak': [
37+
'error',
38+
{
39+
'multiline': 'below',
40+
'singleline': 'beside'
41+
}
42+
],
43+
'svelte/html-closing-bracket-new-line': [
44+
'error',
45+
{
46+
'singleline': 'never',
47+
'multiline': 'always',
48+
'selfClosingTag': {
49+
'singleline': 'never',
50+
'multiline': 'always'
51+
}
52+
}
53+
],
54+
'svelte/html-closing-bracket-spacing': [
55+
'error',
56+
{
57+
'startTag': 'never',
58+
'endTag': 'never',
59+
'selfClosingTag': 'always'
60+
}
61+
]
3462
}
35-
],
36-
'svelte/html-closing-bracket-spacing': [
37-
'error',
38-
{
39-
'startTag': 'never',
40-
'endTag': 'never',
41-
'selfClosingTag': 'always'
42-
}
43-
]
44-
} satisfies Record<string, RuleEntry>
63+
} satisfies ConfigWithExtends
64+
}

eslint.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { eslint } from './config/eslint/eslint-config'
1+
import eslint from './config/eslint/eslint-config'
22

33
const config = eslint(import.meta.url)
44

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
"description": "A repository for repository management tools and set-ups.",
44
"license": "MIT",
55
"type": "module",
6-
"version": "1.0.0-next.2",
6+
"version": "1.0.0-next.3",
77
"scripts": {
88
"format": "bun --bun eslint --config ./eslint.config.ts --rule 'unused-imports/no-unused-imports: [warn]' --fix . "
99
},
1010
"bin": {
11-
"repo-package": "./bin/repo-package.ts"
11+
"repo-pack": "./bin/repo-pack.ts"
1212
},
1313
"exports": {
1414
"./cli-colors": "./forward/cli-colors.ts",

0 commit comments

Comments
 (0)