Skip to content

Commit

Permalink
chore: add linting, knip, CI
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtechsimetka committed Oct 29, 2023
1 parent 4690b79 commit 835849f
Show file tree
Hide file tree
Showing 15 changed files with 920 additions and 404 deletions.
31 changes: 12 additions & 19 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
module.exports = {
root: true,
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:svelte/recommended',
'prettier'
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
plugins: ['svelte3', '@typescript-eslint'],
ignorePatterns: ['*.cjs'],
overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }],
settings: {
'svelte3/typescript': () => require('typescript'),
},
parserOptions: {
sourceType: 'module',
ecmaVersion: 2020,
extraFileExtensions: ['.svelte']
},
env: {
browser: true,
es2017: true,
node: true
node: true,
},
globals: {
svelte: true,
},
overrides: [
{
files: ['*.svelte'],
parser: 'svelte-eslint-parser',
parserOptions: {
parser: '@typescript-eslint/parser'
}
}
]
};
}
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: 'weekly'
38 changes: 38 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Check

on:
push:
branches:
- 'main'
pull_request:
branches:
- '**'

jobs:
check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Use Node.js 18
uses: actions/setup-node@v4
with:
node-version: 18

- uses: pnpm/action-setup@v2
with:
version: 7

- name: Install npm deps
run: pnpm install --frozen-lockfile

- name: Check the build
run: pnpm run check

- name: Code linting
run: pnpm run lint

- name: Check dependencies, unused code
run: pnpm run knip
4 changes: 2 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"semi": false,
"trailingComma": "all",
"printWidth": 100,
"plugins": ["prettier-plugin-svelte"],
"pluginSearchDirs": ["."],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
}
35 changes: 35 additions & 0 deletions knip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import sveltePreprocess from 'svelte-preprocess'
import { preprocess, compile } from 'svelte/compiler'
import type { KnipConfig } from 'knip'

const sveltePreprocessor = sveltePreprocess()

const config: KnipConfig = {
ignore: [
'**/*.d.ts',
'**/schemas.ts',
'src/lib/objects/hello-world/index.ts',
'src/lib/objects/external/iframe.svelte',
'src/lib/objects/split/types.ts',
'src/lib/objects/split/contracts/**/*',
],
paths: {
// This ain't pretty, but Svelte basically does the same
'$app/*': ['node_modules/@sveltejs/kit/src/runtime/app/*'],
'$env/*': ['.svelte-kit/ambient.d.ts'],
'$lib/*': ['src/lib/*'],
},
compilers: {
svelte: async (text: string) => {
const processed = await preprocess(text, sveltePreprocessor, { filename: 'dummy.ts' })
const compiled = compile(processed.code)
return compiled.js.code
},
css: (text: string) => [...text.matchAll(/(?<=@)import[^;]+/g)].join('\n'),
},
ignoreExportsUsedInFile: true,
ignoreBinaries: ['docker'],
ignoreDependencies: ['@typechain/ethers-v6'],
}

export default config
44 changes: 23 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
"test": "npm run test:integration && npm run test:unit",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --plugin-search-dir . --check . && eslint .",
"format": "prettier --plugin-search-dir . --write .",
"lint": "prettier --plugin prettier-plugin-svelte --check . && eslint .",
"format": "prettier --plugin prettier-plugin-svelte --write .",
"test:integration": "playwright test",
"test:unit": "vitest"
"test:unit": "vitest",
"knip": "knip"
},
"exports": {
".": {
Expand All @@ -30,24 +31,25 @@
"svelte": "^4.0.0"
},
"devDependencies": {
"@playwright/test": "^1.28.1",
"@sveltejs/adapter-auto": "^2.0.0",
"@sveltejs/kit": "^1.20.4",
"@sveltejs/package": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte": "^2.30.0",
"prettier": "^2.8.0",
"prettier-plugin-svelte": "^2.10.1",
"publint": "^0.1.9",
"svelte": "^4.0.5",
"svelte-check": "^3.4.3",
"tslib": "^2.4.1",
"typescript": "^5.0.0",
"vite": "^4.4.2",
"vitest": "^0.32.2"
"@playwright/test": "^1.39.0",
"@sveltejs/adapter-auto": "^2.1.0",
"@sveltejs/kit": "^1.27.1",
"@sveltejs/package": "^2.2.2",
"@typescript-eslint/eslint-plugin": "^6.9.0",
"@typescript-eslint/parser": "^6.9.0",
"eslint": "^8.52.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-svelte": "^2.34.0",
"knip": "2.17.1",
"prettier": "^3.0.3",
"prettier-plugin-svelte": "^3.0.3",
"publint": "^0.2.5",
"svelte": "^4.2.2",
"svelte-check": "^3.5.2",
"tslib": "^2.6.2",
"typescript": "^5.2.2",
"vite": "^4.5.0",
"vitest": "^0.34.6"
},
"svelte": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
10 changes: 5 additions & 5 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { PlaywrightTestConfig } from '@playwright/test';
import type { PlaywrightTestConfig } from '@playwright/test'

const config: PlaywrightTestConfig = {
webServer: {
command: 'npm run build && npm run preview',
port: 4173
port: 4173,
},
testDir: 'tests',
testMatch: /(.+\.)?(test|spec)\.[jt]s/
};
testMatch: /(.+\.)?(test|spec)\.[jt]s/,
}

export default config;
export default config
Loading

0 comments on commit 835849f

Please sign in to comment.