Skip to content

Commit

Permalink
update lint to 9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-8 committed Apr 30, 2024
1 parent f92f49d commit ab29a65
Show file tree
Hide file tree
Showing 11 changed files with 1,241 additions and 1,296 deletions.
27 changes: 14 additions & 13 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ jobs:

- run: pnpm lint

# - 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
- name: Run ESLint on changed files
uses: tj-actions/eslint-changed-files@v25
with:
config_path: eslint.config.js
escape_paths: false
file_extensions: |
**/*.ts
**/*.js
**/*.svelte
**/*.composition
**/*.html
**/*.markdown
**/*.json
**/*.yml
23 changes: 12 additions & 11 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
"titleBar.activeBackground": "#ff400089",
"titleBar.inactiveBackground": "#ff3e0069",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveForeground": "#e7e7e799"
"titleBar.inactiveForeground": "#e7e7e799",
},

// Kitbook
"files.associations": {
"*.composition": "svelte"
"*.composition": "svelte",
},
"foam.completion.label": "title",
"foam.edit.linkReferenceDefinitions": "withExtensions",
"foam.files.ignore": [
"**/node_modules/**/*",
"**/.svelte-kit/**/*",
"**/dist/**/*"
"**/dist/**/*",
],
"foam.files.notesExtensions": "composition",

Expand All @@ -25,20 +25,22 @@
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
"source.organizeImports": "never",
},
// Silence stylistic rules in IDE, but still auto fix them
"eslint.rules.customizations": [
{ "rule": "@stylistic/*", "severity": "off" },
{ "rule": "style*", "severity": "off" },
{ "rule": "style/*", "severity": "off" },
{ "rule": "format/*", "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/order", "severity": "off" },
{ "rule": "sort-imports", "severity": "off" },
],
"eslint.validate": [
"javascript",
Expand All @@ -48,9 +50,8 @@
"svelte",
"json",
"jsonc",
"yaml"
"yaml",
],
"eslint.experimental.useFlatConfig": true,

"unocss.root": "packages/kitbook",
"svelte.plugin.svelte.compilerWarnings": {
Expand All @@ -77,6 +78,6 @@
"a11y-structure": "ignore",
"a11y-mouse-events-have-key-events": "ignore",
"a11y-missing-content": "ignore",
"a11y-no-static-element-interactions": "ignore"
}
"a11y-no-static-element-interactions": "ignore",
},
}
153 changes: 125 additions & 28 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,143 @@
// 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, { typescript } from '@antfu/eslint-config'
import { svelte } from './lint/svelte.js'
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'

// https://github.com/antfu/eslint-config
// Inspect: npx @eslint/config-inspector
export default antfu(
{
vue: false,
// typescript: false,
},
...typescript({
componentExts: ['svelte', 'composition'],
overrides: {
//
},
}),
// @ts-expect-error - does not fit the defineConfig types
svelte,
{
ignores: [
'examples/**',
'**/.svelte-kit**',
'**/package/**',
'**/src/routes/kitbook/**',
'**/src/lib/routes/+layout.ts',
'.eslintcache',
],
stylistic: {
overrides: {
'style/brace-style': ['error', '1tbs', { allowSingleLine: true }],
},
},
svelte: true,
},
{
rules: {
'jsdoc/require-property-description': 'off',
'jsdoc/require-returns-description': 'off',
'no-console': ['warn', { allow: ['warn', 'error', 'info'] }],
},
},
{
name: 'jacob/svelte/stylistic',
files: ['**/*.svelte', '**/*.composition'],
plugins: {
'svelte-stylistic': svelteStylistic,
},
rules: {
'svelte-stylistic/brackets-same-line': 'error',
'svelte-stylistic/consistent-attribute-lines': 'error',
},
},
{
files: ['**/*.test.ts'],
rules: {
'test/consistent-test-it': ['error', { fn: 'test', withinDescribe: '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'],
},
},
).overrides({
'antfu/typescript/rules': {
files: ['**/*.svelte', '**/*.composition'],
rules: {
// Need to check if duplicates in these
...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',
'eqeqeq': '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
'curly': 'off',
'antfu/if-newline': 'off',
'node/prefer-global/process': 'off',
'test/consistent-test-it': ['error', { fn: 'test', withinDescribe: 'test' }],
},
},
)
'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 }],

// '@typescript-eslint/no-var-requires': 'off',
// '@typescript-eslint/no-unused-vars': 'off',
// '@typescript-eslint/no-empty-function': 'off',
// '@typescript-eslint/no-explicit-any': 'off',
// '@typescript-eslint/explicit-module-boundary-types': 'off',
// '@typescript-eslint/ban-ts-comment': 'off',
// 'no-undef': 'off',
// 'a11y-click-events-have-key-events': 'off',
'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',
},
},
})
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@
"check-packages": "pnpm update --interactive --recursive --latest"
},
"devDependencies": {
"@antfu/eslint-config": "1.0.0-beta.29",
"@typescript-eslint/eslint-plugin": "6.9.0",
"@typescript-eslint/parser": "6.9.0",
"@antfu/eslint-config": "2.16.0",
"@typescript-eslint/eslint-plugin": "7.8.0",
"@typescript-eslint/parser": "7.8.0",
"bumpp": "^9.4.0",
"eslint": "^8.52.0",
"eslint-define-config": "^1.24.1",
"eslint-plugin-svelte": "^2.34.0",
"eslint": "^9.1.1",
"eslint-define-config": "^2.1.0",
"eslint-plugin-svelte": "^2.38.0",
"eslint-plugin-svelte-stylistic": "^0.0.4",
"lint-staged": "^14.0.1",
"lint-staged": "^15.2.2",
"prettier": "^2.8.8",
"simple-git-hooks": "^2.9.0",
"simple-git-hooks": "^2.11.1",
"svelte": "^4.2.15",
"typescript": "~5.4.5",
"vite": "^5.2.10",
"vitest": "^1.5.0"
"vitest": "^1.5.2"
},
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged"
Expand Down
2 changes: 1 addition & 1 deletion packages/format-snapshot-results-action/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"@actions/github": "^5.0.1",
"@vercel/ncc": "^0.38.1",
"typescript": "^5.4.5",
"vitest": "^1.5.0"
"vitest": "^1.5.2"
}
}
4 changes: 2 additions & 2 deletions packages/kitbook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@
"prettier": "^2.8.8",
"publint": "^0.2.7",
"svelte": "^4.2.15",
"svelte-check": "^3.6.9",
"svelte-check": "^3.7.0",
"tslib": "^2.6.2",
"typescript": "~5.4.5",
"unocss": "^0.59.4",
"vite": "^5.2.10",
"vite-plugin-inspect": "^0.8.4",
"vitest": "^1.5.0"
"vitest": "^1.5.2"
},
"stackblitz": {
"installDependencies": false,
Expand Down
30 changes: 25 additions & 5 deletions packages/kitbook/src/docs/4-component-compositions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ When you're prototyping and documentation needs go beyond simply passing props a

[[4-component-compositions.composition]]

This Kitbook's [[SearchResult]] page also has a simple Composition.
You can also create a Composition beside a corresponding markdown documentation page as you see in [[complex-examples]] (look at the source code) - just click the `Add Composition` button when viewing your markdown page.

This Kitbook's [[SearchResult]] page has a simple Composition you could peak at.

## Extension Support

To get these files with the `.composition` extension to work like Svelte files, you'll need to update the extensions property in your svelte config:

Expand All @@ -27,29 +31,45 @@ And add this VSCode setting:
}
```

And if you are using eslint:
Add the extension to eslint like this in a fresh project:

```js twoslash title=".eslintrc.cjs" {6}
module.exports = {
overrides: [
{
files: [
'*.svelte',
'*.composition'
'*.composition',
]
// ...
}
]
}
```

You can also create a Composition beside a corresponding markdown documentation page as you see in [[complex-examples]] (look at the source code) - just click the `Add Composition` button when viewing your markdown page.
If you find yourself wrestling with Prettier, I recommend using [`@antfu/eslint-config`](https://github.com/antfu/eslint-config) and ESLint's flat config for both linting and formatting. See Kitbook's own [`eslint.config.js`](https://github.com/jacob-8/kitbook/blob/main/eslint.config.js) for a thorough example that has Typescript and Svelte support, but here's a basic starter:

```js twoslash title="eslint.config.js" {6,9}
import { antfu } from '@antfu/eslint-config'

export default antfu({ svelte: true })
.overrides({
'antfu/typescript/rules': {
files: ['**/*.svelte', '**/*.composition'],
},
'antfu/svelte/rules': {
files: ['**/*.composition'],
},
})
```

---

Now that you have a composition in place, learn how to [[5-write-documentation|document your components]], including sprinkling in compositions where helpful.

[//begin]: # "Autogenerated link references for markdown compatibility"
[4-component-compositions.composition]: 4-component-compositions.composition "4-component-compositions"
[SearchResult]: ../lib/layout/sidebar/search/SearchResult.md "SearchResult"
[complex-examples]: 2-compositions/complex-examples.md "Advanced Composition Use Cases"
[SearchResult]: ../lib/layout/sidebar/search/SearchResult.md "SearchResult"
[5-write-documentation|document your components]: 5-write-documentation.md "Write Documentation"
[//end]: # "Autogenerated link references"
Loading

0 comments on commit ab29a65

Please sign in to comment.