Add prettier and eslint

This commit is contained in:
Sebastian Martinez
2024-07-05 11:36:18 +02:00
parent 4f497aeb2c
commit 319f788c3c
8 changed files with 1810 additions and 31 deletions
+2
View File
@@ -2,6 +2,8 @@ node_modules
/build
/.svelte-kit
/package
/src-tauri/target
/src-tauri/gen/schemas
# Mac OS
.DS_Store
+8
View File
@@ -0,0 +1,8 @@
{
"arrowParens": "avoid",
"plugins": ["prettier-plugin-svelte"],
"svelteSortOrder": "options-scripts-styles-markup",
"bracketSameLine": true,
"proseWrap": "never",
"htmlWhitespaceSensitivity": "ignore"
}
+143
View File
@@ -0,0 +1,143 @@
import globals from "globals";
import js from "@eslint/js";
import prettier from "eslint-config-prettier";
import svelte from "eslint-plugin-svelte";
import svelteParser from "svelte-eslint-parser";
import ts from "typescript-eslint";
export default [
...[
js.configs.recommended,
...ts.configs.recommended,
prettier,
{
languageOptions: {
parser: ts.parser,
parserOptions: {
project: "./tsconfig.json",
tsconfigRootDir: import.meta.dirname,
extraFileExtensions: [".svelte"],
},
globals: { ...globals.browser, ...globals.node },
},
rules: {
"no-implicit-globals": "error",
"no-restricted-globals": [
"error",
"name",
"event",
"frames",
"history",
"length",
"content",
"origin",
"status",
],
// Require using arrow functions as callbacks.
// https://eslint.org/docs/rules/prefer-arrow-callback
"prefer-arrow-callback": "warn",
// Require using const for variables that are never modified after declared.
// https://eslint.org/docs/rules/prefer-const
"prefer-const": "warn",
// Disallow modifying variables that are declared using const.
// https://eslint.org/docs/rules/no-const-assign
"no-const-assign": "error",
// Require let or const instead of var.
// https://eslint.org/docs/rules/no-var
"no-var": "warn",
// Require `===` and `!==` comparisons.
eqeqeq: "warn",
"@typescript-eslint/no-floating-promises": "warn",
"@typescript-eslint/no-empty-function": "warn",
"@typescript-eslint/naming-convention": [
"warn",
{
selector: "enumMember",
format: ["PascalCase"],
},
{
selector: "objectLiteralProperty",
format: ["PascalCase", "camelCase"],
},
{
selector: "default",
format: ["camelCase"],
leadingUnderscore: "allow",
trailingUnderscore: "allow",
},
{
selector: "variable",
modifiers: ["const"],
format: ["camelCase", "PascalCase", "UPPER_CASE"],
leadingUnderscore: "allow",
trailingUnderscore: "allow",
},
{
selector: "typeLike",
format: ["PascalCase"],
},
// Disable @typescript-eslint/naming-convention format for imports
// https://github.com/typescript-eslint/typescript-eslint/pull/7269#issuecomment-1777628591
// https://github.com/typescript-eslint/typescript-eslint/issues/7892
{ selector: "import", format: null },
{
selector: ["objectLiteralProperty"],
modifiers: ["requiresQuotes"],
format: null,
},
],
"@typescript-eslint/no-namespace": [
"error",
{ allowDeclarations: true },
],
"@typescript-eslint/member-ordering": [
"warn",
{ default: ["field", "signature", "constructor", "method"] },
],
// Allow explict type annotations for additional clarity.
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-invalid-void-type": ["warn"],
// Disallow Unused Variables.
// https://eslint.org/docs/rules/no-unused-vars
"@typescript-eslint/no-unused-vars": [
"warn",
{ argsIgnorePattern: "^_" },
],
},
},
].map(conf => ({
...conf,
linterOptions: {
reportUnusedDisableDirectives: "error",
},
files: ["**/*.js", "**/*.ts", "**/*.svelte"],
})),
...svelte.configs["flat/recommended"],
...svelte.configs["flat/prettier"],
{
files: ["*.svelte", "**/*.svelte"],
languageOptions: {
parser: svelteParser,
parserOptions: {
parser: ts.parser,
project: "./tsconfig.json",
tsconfigRootDir: import.meta.dirname,
svelteFeatures: {
experimentalGenerics: true,
},
},
},
rules: {
"svelte/no-at-html-tags": "off",
"@typescript-eslint/no-explicit-any": "error",
},
},
{
ignores: [
"node_modules/**/*",
"src-tauri/**/*",
".svelte-kit/**/*",
"eslint.config.js",
],
},
];
+1607
View File
File diff suppressed because it is too large Load Diff
+15 -4
View File
@@ -7,8 +7,9 @@
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check": "svelte-kit sync && scripts/check",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"format": "npx prettier '**/*.@(ts|js|svelte|json|css|html|yml)' --write",
"tauri": "tauri"
},
"license": "MIT",
@@ -17,14 +18,24 @@
"@tauri-apps/plugin-shell": ">=2.0.0-beta.0"
},
"devDependencies": {
"@eslint/js": "^9.6.0",
"@sveltejs/adapter-static": "^3.0.1",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@tauri-apps/cli": ">=2.0.0-beta.0",
"@typescript-eslint/parser": "^7.15.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.41.0",
"globals": "^15.8.0",
"prettier": "^3.3.2",
"prettier-plugin-svelte": "^3.2.5",
"svelte": "^4.2.7",
"svelte-check": "^3.6.0",
"tslib": "^2.4.1",
"svelte-eslint-parser": "^0.39.2",
"tslib": "^2.4.1",
"typescript": "^5.0.0",
"vite": "^5.0.3",
"@tauri-apps/cli": ">=2.0.0-beta.0"
"typescript-eslint": "^7.15.0",
"vite": "^5.0.3"
}
}
Executable
+7
View File
@@ -0,0 +1,7 @@
#!/bin/sh
set -e
npx tsc --noEmit
npx svelte-check --tsconfig tsconfig.json --fail-on-warnings --compiler-warnings missing-custom-element-compile-options:ignore
npx eslint --cache --cache-location node_modules/.cache/eslint --max-warnings 0 .
npx prettier "**/*.@(ts|js|svelte|json|css|html|yml)" --ignore-path .gitignore --check --cache
+25 -25
View File
@@ -10,31 +10,6 @@
}
</script>
<div class="container">
<h1>Welcome to Tauri!</h1>
<div class="row">
<a href="https://vitejs.dev" target="_blank">
<img src="/vite.svg" class="logo vite" alt="Vite Logo" />
</a>
<a href="https://tauri.app" target="_blank">
<img src="/tauri.svg" class="logo tauri" alt="Tauri Logo" />
</a>
<a href="https://kit.svelte.dev" target="_blank">
<img src="/svelte.svg" class="logo svelte-kit" alt="SvelteKit Logo" />
</a>
</div>
<p>Click on the Tauri, Vite, and SvelteKit logos to learn more.</p>
<form class="row" on:submit|preventDefault={greet}>
<input id="greet-input" placeholder="Enter a name..." bind:value={name} />
<button type="submit">Greet</button>
</form>
<p>{greetMsg}</p>
</div>
<style>
.logo.vite:hover {
filter: drop-shadow(0 0 2em #747bff);
@@ -154,3 +129,28 @@
}
}
</style>
<div class="container">
<h1>Welcome to Tauri!</h1>
<div class="row">
<a href="https://vitejs.dev" target="_blank">
<img src="/vite.svg" class="logo vite" alt="Vite Logo" />
</a>
<a href="https://tauri.app" target="_blank">
<img src="/tauri.svg" class="logo tauri" alt="Tauri Logo" />
</a>
<a href="https://kit.svelte.dev" target="_blank">
<img src="/svelte.svg" class="logo svelte-kit" alt="SvelteKit Logo" />
</a>
</div>
<p>Click on the Tauri, Vite, and SvelteKit logos to learn more.</p>
<form class="row" on:submit|preventDefault={greet}>
<input id="greet-input" placeholder="Enter a name..." bind:value={name} />
<button type="submit">Greet</button>
</form>
<p>{greetMsg}</p>
</div>
+3 -2
View File
@@ -1,10 +1,11 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"include": ["src", "./*.ts"],
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"allowSyntheticDefaultImports": true,
"types": ["vite/client"],
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,