Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
docs(projects): update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Dec 13, 2023
1 parent 58ab09a commit c4ecc6d
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 17 deletions.
136 changes: 125 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# SoybeanJS's ESLint flat config presets

- Default config Lint JavaScript and TypeScript.
- Support Vue, React, ReactNative, SolidJS, Svelte and Astro on demand.
- Use Prettier to format JSON, JSONC, YAML, CSS, HTML, TOML, Markdown and so on.
- Support Vue, React, ReactNative, Solid, Svelte and Astro on demand.
- Use ESlint and Prettier to format HTML, CSS, LESS, SCSS, JSON, JSONC, YAML, TOML, Markdown.

> [!WARNING]
> ESlint will use new flat config when version 1.0.0 released.
## Usage

Expand All @@ -14,25 +17,40 @@ pnpm i -D eslint typescript @soybeanjs/eslint-config

### ESLint config file

create config file "eslint.config.js"
- With [`"type": "module"`](https://nodejs.org/api/packages.html#type) in `package.json`

- Create config file `eslint.config.js`

- Import config from `@soybeanjs/eslint-config`

```js
import { defineConfig } from '@soybeanjs/eslint-config';

export default defineConfig({
// options
});
```

> [!NOTE]
> See [Options](##Options) for more details.
### ESLint settings in VSCode

```json
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.organizeImports": false
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
},
"editor.formatOnSave": false,
"eslint.experimental.useFlatConfig": true,
"eslint.validate": [
// add the languages you want to lint here
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
// "javascript", // support builtin
// "javascriptreact", // support builtin
// "typescript", // support builtin
// "typescriptreact", // support builtin
// "vue", // support builtin
// add the languages you want to lint
"svelte",
"astro",
"html",
Expand All @@ -46,3 +64,99 @@ create config file "eslint.config.js"
"prettier.enable": false
}
```

### Scripts in package.json

```json
{
"scripts": {
"lint": "eslint . --fix"
}
}
```

## Options

#### interface Options

````typescript
interface Options {
/**
* The current working directory
*
* @default process.cwd()
*/
cwd: string;
/** The globs to ignore lint */
ignores: string[];
/**
* Default prettier rules
*
* @default
* ```json
* {
* "printWidth": 120,
* "singleQuote": true,
* "trailingComma": "none",
* "arrowParens": "avoid",
* "htmlWhitespaceSensitivity": "ignore"
* }
* ```
*/
prettierRules: PartialPrettierExtendedOptions;
/**
* Whether to use prettierrc
*
* If true, the rules in prettierrc will override the default rules
*
* @default true
*/
usePrettierrc: boolean;

/**
* @default
* {
* "html": true,
* "css": true,
* "json": true,
* }
*/
formatter: {
html?: boolean;
css?: boolean;
json?: boolean;
markdown?: boolean;
yaml?: boolean;
toml?: boolean;
};
vue?: VueOptions | boolean;
react?: RuleBaseOptions | boolean;
'react-native'?: RuleBaseOptions | boolean;
solid?: RuleBaseOptions | boolean;
svelte?: RuleBaseOptions | boolean;
astro?: RuleBaseOptions | boolean;
}

type RuleBaseOptions<T = NonNullable<unknown>> = T & {
/** The glob patterns to lint */
files?: string[];
/** Override rules */
overrides?: PartialEslintFlatRules;
};

type VueOptions = RuleBaseOptions<{
/**
* The vue version
*
* @default 3
*/
version?: 2 | 3;
}>;
````

## Thanks

**Inspired by the following projects:**

- [Antfu's eslint-config](https://github.com/antfu/eslint-config)
- [Sxzz's eslint-config](https://github.com/sxzz/eslint-config)
7 changes: 1 addition & 6 deletions src/types/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,13 @@ export type FlatConfigItem = Omit<FlatESLintConfigItem<EslintFlatRules, false>,
plugins?: Record<string, any>;
};

type WithFiles<T> = T & {
export type RuleBaseOptions<T = NonNullable<unknown>> = T & {
/** The glob patterns to lint */
files?: string[];
};

type WithOverrides<T> = T & {
/** Override rules */
overrides?: PartialEslintFlatRules;
};

export type RuleBaseOptions<T = NonNullable<unknown>> = WithFiles<T> & WithOverrides<T>;

export type RequiredRuleBaseOptions = Required<RuleBaseOptions>;

export type OnDemandRuleKey = 'vue' | 'react' | 'react-native' | 'solid' | 'svelte' | 'astro';
Expand Down

0 comments on commit c4ecc6d

Please sign in to comment.