Skip to content

Commit

Permalink
add lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-8 committed Apr 24, 2024
1 parent 26a0ca6 commit 0f30720
Show file tree
Hide file tree
Showing 8 changed files with 2,341 additions and 49 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Lint changes

on:
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

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

- uses: actions/setup-node@v3
with:
node-version: 18
cache: pnpm

- run: pnpm install

- name: Run ESLint on changed files
uses: tj-actions/eslint-changed-files@v24
with:
config_path: eslint.config.js
file_extensions: |
**/*.ts
**/*.js
**/*.svelte
**/*.composition
**/*.html
**/*.markdown
**/*.json
**/*.yml
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ jobs:
cache: pnpm
registry-url: 'https://registry.npmjs.org'

- run: npx changelogithub
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Install Dependencies
run: pnpm i

Expand All @@ -43,3 +39,7 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
NPM_CONFIG_PROVENANCE: true

- run: npx changelogithub
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
name: Lint, Svelte Check, & Unit Test Push
name: Svelte Check, & Unit Test Push

on:
push:
branches:
- '**'

jobs:
# lint:
# name: Lint
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3

# - uses: pnpm/action-setup@v2
# with:
# version: 8.6.0

# - uses: actions/setup-node@v3
# with:
# node-version: 18
# cache: pnpm

# - run: pnpm install

# - name: Lint
# run: pnpm lint

unit_test:
name: Svelte Check & Unit Test
runs-on: ubuntu-latest
Expand All @@ -45,7 +25,7 @@ jobs:
- run: pnpm install
- run: pnpm sync
- run: pnpm check

- name: Run Vitest Unit Tests
run: pnpm test

Expand All @@ -56,4 +36,4 @@ jobs:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
# with:
# status: ${{ job.status }}
# fields: workflow,repo,message,commit,author,action,ref # selectable (default: repo,message)
# fields: workflow,repo,message,commit,author,action,ref # selectable (default: repo,message)
18 changes: 11 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,41 @@
"titleBar.activeBackground": "#ff400089",
"titleBar.inactiveBackground": "#ff3e0069",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveForeground": "#e7e7e799"
"titleBar.inactiveForeground": "#e7e7e799",
},
"files.associations": {
"*.composition": "svelte"
"*.composition": "svelte",
},
"foam.edit.linkReferenceDefinitions": "withExtensions",
"foam.files.ignore": [
"**/node_modules/**/*",
"**/.svelte-kit/**/*",
"**/dist/**/*"
"**/dist/**/*",
],
"foam.completion.label": "title",
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"prettier.enable": false,
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
"source.organizeImports": "never",
},
// Silence the stylistic rules in your IDE, but still auto fix them
"eslint.rules.customizations": [
{ "rule": "@stylistic/*", "severity": "off" },
{ "rule": "style*", "severity": "off" },
{ "rule": "*-indent", "severity": "off" },
{ "rule": "*indent", "severity": "off" },
{ "rule": "*-spacing", "severity": "off" },
{ "rule": "*-spaces", "severity": "off" },
{ "rule": "*-order", "severity": "off" },
{ "rule": "*-dangle", "severity": "off" },
{ "rule": "*-newline", "severity": "off" },
{ "rule": "*quotes", "severity": "off" },
{ "rule": "*semi", "severity": "off" }
{ "rule": "*semi", "severity": "off" },
{ "rule": "import/newline-after-import", "severity": "off" },
{ "rule": "import/order", "severity": "off" },
{ "rule": "sort-imports", "severity": "off" },
{ "rule": "ts/no-empty-function", "severity": "off" },
],
"eslint.validate": [
"javascript",
Expand All @@ -43,7 +47,7 @@
"svelte",
"json",
"jsonc",
"yaml"
"yaml",
],
"eslint.experimental.useFlatConfig": true,
"svelte.plugin.svelte.compilerWarnings": {
Expand Down
162 changes: 162 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
// To run automatically on commit, add `simple-git-hooks` and `lint-staged` then run `npx simple-git-hooks` once. After that all commits will be linted.

// @ts-check
import { antfu } from '@antfu/eslint-config'
import jsEslintPlugin from '@eslint/js'
import tsEslintPlugin from '@typescript-eslint/eslint-plugin'
import svelteStylistic from 'eslint-plugin-svelte-stylistic'

// Inspect: npx @eslint/config-inspector
export default antfu(
{
ignores: [
'**/.svelte-kit**',
'**/functions/lib/**',
'.eslintcache',
'packages/scripts/import/old**',
'**/route/kitbook/**',
'**/locales/**',
'supabase/functions/**',
],
stylistic: {
overrides: {
'style/brace-style': ['error', '1tbs', { allowSingleLine: true }],
'antfu/if-newline': 'off',
'curly': 'off',
},
},
svelte: true,
},
{
name: 'jacob/svelte/stylistic',
files: ['**/*.svelte', '**/*.composition'],
plugins: {
'svelte-stylistic': svelteStylistic,
},
rules: {
'svelte-stylistic/brackets-same-line': 'error',
'svelte-stylistic/consistent-attribute-lines': 'error',
},
},
{
name: 'jacob/test/rules',
files: ['**/*.test.ts'],
rules: {
'test/consistent-test-it': ['error', { fn: 'test' }],
'test/no-commented-out-tests': 'error',
'test/no-disabled-tests': 'error',
'test/consistent-test-filename': 'error',
'test/expect-expect': 'error',
'test/no-alias-methods': 'error',
'test/no-conditional-expect': 'error',
'test/no-conditional-in-test': 'error',
'test/no-conditional-tests': 'error',
'test/no-duplicate-hooks': 'error',
'test/no-focused-tests': 'error',
'test/no-standalone-expect': 'error',
'test/no-test-return-statement': 'error',
'test/prefer-comparison-matcher': 'error',
'test/prefer-hooks-on-top': 'error',
'test/prefer-spy-on': 'error',
'test/prefer-to-be-falsy': 'error',
'test/prefer-to-be-truthy': 'error',
'test/prefer-to-contain': 'error',
'test/prefer-to-have-length': 'error',
'test/valid-describe-callback': 'error',
'test/valid-expect': 'error',
},
},
{
name: 'jacob/settings',
files: ['.vscode/*.json'],
rules: {
'jsonc/comma-dangle': ['error', 'always-multiline'],
},
},
{
name: 'ld/script-exceptions',
files: ['packages/{scripts,functions}/**'],
rules: {
'no-console': 'off',
'ts/no-unused-vars': 'off',
'ts/no-var-requires': 'off',
},
},
{
name: 'ld/intercontinental-dictionaries-series',
files: ['**/ids-import/**'],
rules: {
'ts/no-unused-vars': 'off',
'no-undef': 'off',
},
},
).overrides({
'antfu/typescript/rules': {
files: ['**/*.svelte', '**/*.composition'],
rules: {
...jsEslintPlugin.configs.recommended.rules,
// ...tsEslintPlugin.configs.recommended.rules, // cause the rest to break
...tsEslintPlugin.configs.stylistic.rules,

'prefer-destructuring': 'error',
'no-constant-binary-expression': 'error',
'ts/default-param-last': 'error',
'require-await': 'error',
'prefer-object-spread': 'error',
'no-useless-concat': 'error',
'no-else-return': 'error',
'no-console': ['error', { allow: ['warn', 'error', 'info', 'time', 'timeEnd'] }],
'require-atomic-updates': 'error',
'style/quotes': ['error', 'single', {
allowTemplateLiterals: true,
avoidEscape: true,
}],
'ts/no-unused-vars': ['warn', {
argsIgnorePattern: '^_',
caughtErrors: 'none',
ignoreRestSiblings: true,
// vars: 'all', // is this helpful?
varsIgnorePattern: '^\\$\\$Props$',
}],

'ts/no-explicit-any': 'warn',
'prefer-named-capture-group': 'warn',

'no-undef': 'off',
'no-unused-vars': 'off',
'no-alert': 'off',
'ts/ban-ts-comment': 'off',
'ts/sort-type-constituents': 'off', // prefer logical rather than alphabetical sorting
},
},
'antfu/svelte/rules': {
files: ['**/*.composition'],
rules: {
'svelte/valid-compile': ['error', { ignoreWarnings: true }], // throws error on a11y issues
'svelte/no-dom-manipulating': 'error',
'svelte/no-store-async': 'error', // causes issues with auto-unsubscribing features
'svelte/require-store-reactive-access': 'error',
'svelte/require-event-dispatcher-types': 'error',
'svelte/button-has-type': 'error',
'svelte/no-extra-reactive-curlies': 'error',
'svelte/mustache-spacing': 'error',
'svelte/html-closing-bracket-spacing': 'error',
'svelte/no-reactive-reassign': ['warn', { props: false }],

'svelte/html-quotes': 'off', // should it enforce double quotes?
'svelte/no-at-html-tags': 'off',
'no-unused-expressions': 'off',
'no-inner-declarations': 'off',
'style/space-infix-ops': 'off',
'no-undef-init': 'off',
'no-self-assign': 'off',
},
},
})

// learn more
// https://github.com/AndreaPontrandolfo/sheriff
// https://github.com/enso-org/enso/blob/b2c1f97437870fa7b7a4d7c2d3630e2d2bd6fc2c/app/ide-desktop/eslint.config.js
// https://github.com/azat-io/eslint-config/blob/044959d8fef2acff50e252b8a238be933cd38eea/base/index.ts
// https://github.com/darkobits/eslint-plugin/blob/f55a64dc9038148f3227cda7ae4543dffcb0b14e/src/config-sets/ts
// https://github.com/azat-io/eslint-config/blob/044959d8fef2acff50e252b8a238be933cd38eea/react/index.ts
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
"check": "svelte-check --tsconfig ./tsconfig.json --threshold error --diagnostic-sources js,svelte --compiler-warnings a11y-no-static-element-interactions:ignore",
"check:watch": "svelte-check --tsconfig ./tsconfig.json --threshold warning --diagnostic-sources js,svelte --watch",
"test": "vitest",
"lint": "eslint . --cache --quiet",
"lint:fix": "eslint . --cache --fix",
"lint:inspect": "eslint --inspect-config",
"check-packages": "pnpm update --interactive --recursive --latest",
"release": "bumpp"
},
Expand All @@ -62,16 +65,23 @@
"svelte": "^3.55.0 || ^4.0.0 || ^5.0.0"
},
"devDependencies": {
"@antfu/eslint-config": "2.13.3",
"@iconify/json": "^2.2.203",
"@sveltejs/adapter-auto": "3.2.0",
"@sveltejs/kit": "2.5.7",
"@sveltejs/package": "2.3.1",
"@sveltejs/vite-plugin-svelte": "^3.1.0",
"@testing-library/jest-dom": "^5.16.5",
"@typescript-eslint/eslint-plugin": "7.7.1",
"@unocss/svelte-scoped": "^0.59.4",
"bumpp": "^9.4.0",
"eslint": "^9.1.1",
"eslint-plugin-svelte": "^2.38.0",
"eslint-plugin-svelte-stylistic": "^0.0.4",
"kitbook": "1.0.0-beta.28",
"lint-staged": "^15.2.2",
"publint": "^0.2.7",
"simple-git-hooks": "^2.11.1",
"svelte": "^4.2.15",
"svelte-check": "^3.6.9",
"svelte2tsx": "^0.7.6",
Expand All @@ -80,5 +90,11 @@
"unocss": "^0.59.4",
"vite": "^5.2.10",
"vitest": "^1.5.0"
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
},
"lint-staged": {
"*": "eslint --fix"
}
}
Loading

0 comments on commit 0f30720

Please sign in to comment.