|
1 |
| -import type { TypedFlatConfigItem } from '../types' |
| 1 | +import type { OptionsUnicorn, TypedFlatConfigItem } from '../types' |
2 | 2 | import { pluginUnicorn } from '../plugins'
|
3 | 3 |
|
4 |
| -export async function unicorn(): Promise<TypedFlatConfigItem[]> { |
| 4 | +export async function unicorn(options: OptionsUnicorn): Promise<TypedFlatConfigItem[]> { |
5 | 5 | return [
|
6 | 6 | {
|
7 | 7 | name: 'antfu/unicorn/rules',
|
8 | 8 | plugins: {
|
9 | 9 | unicorn: pluginUnicorn,
|
10 | 10 | },
|
11 | 11 | rules: {
|
12 |
| - // Pass error message when throwing errors |
13 |
| - 'unicorn/error-message': 'error', |
14 |
| - // Uppercase regex escapes |
15 |
| - 'unicorn/escape-case': 'error', |
16 |
| - // Array.isArray instead of instanceof |
17 |
| - 'unicorn/no-instanceof-array': 'error', |
18 |
| - // Ban `new Array` as `Array` constructor's params are ambiguous |
19 |
| - 'unicorn/no-new-array': 'error', |
20 |
| - // Prevent deprecated `new Buffer()` |
21 |
| - 'unicorn/no-new-buffer': 'error', |
22 |
| - // Lowercase number formatting for octal, hex, binary (0x1'error' instead of 0X1'error') |
23 |
| - 'unicorn/number-literal-case': 'error', |
24 |
| - // textContent instead of innerText |
25 |
| - 'unicorn/prefer-dom-node-text-content': 'error', |
26 |
| - // includes over indexOf when checking for existence |
27 |
| - 'unicorn/prefer-includes': 'error', |
28 |
| - // Prefer using the node: protocol |
29 |
| - 'unicorn/prefer-node-protocol': 'error', |
30 |
| - // Prefer using number properties like `Number.isNaN` rather than `isNaN` |
31 |
| - 'unicorn/prefer-number-properties': 'error', |
32 |
| - // String methods startsWith/endsWith instead of more complicated stuff |
33 |
| - 'unicorn/prefer-string-starts-ends-with': 'error', |
34 |
| - // Enforce throwing type error when throwing error while checking typeof |
35 |
| - 'unicorn/prefer-type-error': 'error', |
36 |
| - // Use new when throwing error |
37 |
| - 'unicorn/throw-new-error': 'error', |
| 12 | + ...(options.allRecommended |
| 13 | + ? pluginUnicorn.configs['flat/recommended'].rules |
| 14 | + : { |
| 15 | + 'unicorn/consistent-empty-array-spread': 'error', |
| 16 | + 'unicorn/consistent-function-scoping': 'error', |
| 17 | + 'unicorn/error-message': 'error', |
| 18 | + 'unicorn/escape-case': 'error', |
| 19 | + 'unicorn/new-for-builtins': 'error', |
| 20 | + 'unicorn/no-instanceof-array': 'error', |
| 21 | + 'unicorn/no-new-array': 'error', |
| 22 | + 'unicorn/no-new-buffer': 'error', |
| 23 | + 'unicorn/number-literal-case': 'error', |
| 24 | + 'unicorn/prefer-dom-node-text-content': 'error', |
| 25 | + 'unicorn/prefer-includes': 'error', |
| 26 | + 'unicorn/prefer-node-protocol': 'error', |
| 27 | + 'unicorn/prefer-number-properties': 'error', |
| 28 | + 'unicorn/prefer-string-starts-ends-with': 'error', |
| 29 | + 'unicorn/prefer-type-error': 'error', |
| 30 | + 'unicorn/throw-new-error': 'error', |
| 31 | + }), |
38 | 32 | },
|
39 | 33 | },
|
40 | 34 | ]
|
|
0 commit comments