Skip to content

Commit

Permalink
feat: add jsdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Jan 29, 2024
1 parent da34a48 commit 01ac442
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 23 deletions.
41 changes: 31 additions & 10 deletions README.md
Expand Up @@ -23,25 +23,46 @@ Require Node.js >= 16.14.

## Usage

```js
// eslint.config.js
import { all } from '@sxzz/eslint-config'

export default all
```

### Custom Config

```js
import { sxzz } from '@sxzz/eslint-config'
export default sxzz(
[
/* your custom config */
],
{ vue: true, prettier: true, markdown: true, unocss: false },
// Features: it'll detect installed dependency and enable necessary features automatically
{
prettier: true,
markdown: true,
vue: true, // auto detection
unocss: false, // auto detection
},
)
```

### Presets

```js
// eslint.config.js
import {
presetJavaScript, // Ignore common files and include javascript support
presetJsonc, // Includes basic json(c) file support and sorting json keys
presetLangsExtensions, // Includes markdown, yaml + `presetJsonc` support
presetBasic, // Includes `presetJavaScript` and typescript support

// Includes
// - `presetBasic` (JS+TS) support
// - `presetLangsExtensions` (markdown, yaml, jsonc) support
// - Vue support
// - UnoCSS support (`uno.config.ts` is required)
// - Prettier support
presetAll,
} from '@sxzz/eslint-config'

export default presetAll
```

See [preset.ts](./src/presets.ts) for more details.

### VSCode

```jsonc
Expand Down
6 changes: 6 additions & 0 deletions eslint.config.js
Expand Up @@ -14,6 +14,12 @@ export default sxzz(
'sort-keys/sort-keys-fix': 'error',
},
},
{
files: ['**/*.md/*'],
rules: {
'sort-imports': 'off',
},
},
],
{ vue: true },
)
40 changes: 27 additions & 13 deletions src/presets.ts
Expand Up @@ -18,49 +18,63 @@ import {
} from './configs'
import type { FlatESLintConfigItem } from 'eslint-define-config'

/** Ignore common files and include javascript support */
export const presetJavaScript = [
...ignores,
...javascript,
...comments,
...imports,
...unicorn,
]

/** Includes basic json(c) file support and sorting json keys */
export const presetJsonc = [...jsonc, ...sortPackageJson, ...sortTsconfig]
/** Includes markdown, yaml + `presetJsonc` support */
export const presetLangsExtensions = [...markdown, ...yml, ...presetJsonc]

export const basic = [...presetJavaScript, ...typescript]
export { basic as presetBasic }

export const all = [
...basic,
/** Includes `presetJavaScript` and typescript support */
export const presetBasic = [...presetJavaScript, ...typescript, ...sortKeys]
/**
* Includes
* - `presetBasic` (JS+TS) support
* - `presetLangsExtensions` (markdown, yaml, jsonc) support
* - Vue support
* - UnoCSS support (`uno.config.ts` is required)
* - Prettier support
*/
export const presetAll = [
...presetBasic,
...presetLangsExtensions,
...sortKeys,
...vue,
...unocss,
...prettier,
]
export { presetBasic as basic, presetAll as all }

/**
*
* @param config
* @param features
* @returns
*/
export function sxzz(
config: FlatESLintConfigItem | FlatESLintConfigItem[] = [],
{
vue: enableVue = hasVue,
prettier: enablePrettier = true,
markdown: enableMarkdown = true,
sortKeys: enableSortKeys = true,
unocss: enableUnocss = hasUnocss,
}: Partial<{
/** Vue support. Auto-enable. */
vue: boolean
/** Prettier support. Default: true */
prettier: boolean
/** markdown support. Default: true */
markdown: boolean
/** UnoCSS support. Auto-enable. */
unocss: boolean
sortKeys: boolean
}> = {},
): FlatESLintConfigItem[] {
const configs = [...basic, ...yml, ...presetJsonc]
if (enableSortKeys) {
configs.push(...sortKeys)
}
const configs = [...presetBasic, ...yml, ...presetJsonc]
if (enableVue) {
configs.push(...vue)
}
Expand Down

0 comments on commit 01ac442

Please sign in to comment.