Skip to content

Commit

Permalink
feat: allow to configure unicorn using recommended
Browse files Browse the repository at this point in the history
  • Loading branch information
kelsos committed Sep 19, 2024
1 parent 915e53b commit fe712ee
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 63 deletions.
128 changes: 66 additions & 62 deletions src/configs/unicorn.ts
Original file line number Diff line number Diff line change
@@ -1,74 +1,78 @@
import { pluginUnicorn } from '../plugins';
import type { TypedFlatConfigItem } from '../types';
import type { OptionsUnicorn, TypedFlatConfigItem } from '../types';

export async function unicorn(): Promise<TypedFlatConfigItem[]> {
export async function unicorn(options: OptionsUnicorn = {}): Promise<TypedFlatConfigItem[]> {
return [
{
name: 'rotki/unicorn/rules',
plugins: {
unicorn: pluginUnicorn,
},
rules: {
'unicorn/better-regex': 'error',
'unicorn/catch-error-name': 'error',
'unicorn/custom-error-definition': 'error',
'unicorn/error-message': 'error',
'unicorn/escape-case': 'error',
'unicorn/explicit-length-check': 'error',
'unicorn/filename-case': [
'error',
{
cases: { kebabCase: true, pascalCase: true },
ignore: [/^[A-Z]+\..*$/],
},
],
'unicorn/new-for-builtins': 'error',
// 'unicorn/no-array-callback-reference': 'error',
'unicorn/no-array-method-this-argument': 'error',
'unicorn/no-array-push-push': 'error',
'unicorn/no-console-spaces': 'error',
'unicorn/no-for-loop': 'error',
'unicorn/no-hex-escape': 'error',
'unicorn/no-instanceof-array': 'error',
'unicorn/no-invalid-remove-event-listener': 'error',
'unicorn/no-lonely-if': 'error',
// 'unicorn/no-new-array': 'error',
'unicorn/no-new-buffer': 'error',
'unicorn/no-static-only-class': 'error',
'unicorn/no-unnecessary-await': 'error',
'unicorn/no-zero-fractions': `error`,
// 'unicorn/prefer-add-event-listener': 'error',
'unicorn/prefer-array-find': 'error',
'unicorn/prefer-array-flat-map': 'error',
'unicorn/prefer-array-index-of': 'error',
'unicorn/prefer-array-some': 'error',
'unicorn/prefer-at': 'error',
'unicorn/prefer-blob-reading-methods': 'error',
'unicorn/prefer-date-now': 'error',
// 'unicorn/prefer-dom-node-append': 'error',
// 'unicorn/prefer-dom-node-dataset': 'error',
// 'unicorn/prefer-dom-node-remove': 'error',
'unicorn/prefer-dom-node-text-content': 'error',
'unicorn/prefer-includes': 'error',
'unicorn/prefer-keyboard-event-key': 'error',
'unicorn/prefer-math-trunc': 'error',
'unicorn/prefer-modern-dom-apis': 'error',
'unicorn/prefer-modern-math-apis': 'error',
'unicorn/prefer-negative-index': 'error',
'unicorn/prefer-node-protocol': 'error',
// 'unicorn/prefer-number-properties': 'error', TODO: re-evaluate
'unicorn/prefer-optional-catch-binding': 'error',
'unicorn/prefer-prototype-methods': 'error',
// 'unicorn/prefer-query-selector': 'error', TODO: re-evaluate
'unicorn/prefer-reflect-apply': 'error',
'unicorn/prefer-regexp-test': 'error',
// 'unicorn/prefer-string-replace-all': 'error', TODO: re-evaluate
// 'unicorn/prefer-string-slice': 'error', TODO re-evaluate
'unicorn/prefer-string-starts-ends-with': 'error',
'unicorn/prefer-string-trim-start-end': 'error',
'unicorn/prefer-top-level-await': 'error',
'unicorn/prefer-type-error': 'error',
'unicorn/throw-new-error': 'error',
...(options.allRecommended
? pluginUnicorn.configs['flat/recommended'].rules
: {
'unicorn/better-regex': 'error',
'unicorn/catch-error-name': 'error',
'unicorn/custom-error-definition': 'error',
'unicorn/error-message': 'error',
'unicorn/escape-case': 'error',
'unicorn/explicit-length-check': 'error',
'unicorn/filename-case': [
'error',
{
cases: { kebabCase: true, pascalCase: true },
ignore: [/^[A-Z]+\..*$/],
},
],
'unicorn/new-for-builtins': 'error',
// 'unicorn/no-array-callback-reference': 'error',
'unicorn/no-array-method-this-argument': 'error',
'unicorn/no-array-push-push': 'error',
'unicorn/no-console-spaces': 'error',
'unicorn/no-for-loop': 'error',
'unicorn/no-hex-escape': 'error',
'unicorn/no-instanceof-array': 'error',
'unicorn/no-invalid-remove-event-listener': 'error',
'unicorn/no-lonely-if': 'error',
// 'unicorn/no-new-array': 'error',
'unicorn/no-new-buffer': 'error',
'unicorn/no-static-only-class': 'error',
'unicorn/no-unnecessary-await': 'error',
'unicorn/no-zero-fractions': `error`,
// 'unicorn/prefer-add-event-listener': 'error',
'unicorn/prefer-array-find': 'error',
'unicorn/prefer-array-flat-map': 'error',
'unicorn/prefer-array-index-of': 'error',
'unicorn/prefer-array-some': 'error',
'unicorn/prefer-at': 'error',
'unicorn/prefer-blob-reading-methods': 'error',
'unicorn/prefer-date-now': 'error',
// 'unicorn/prefer-dom-node-append': 'error',
// 'unicorn/prefer-dom-node-dataset': 'error',
// 'unicorn/prefer-dom-node-remove': 'error',
'unicorn/prefer-dom-node-text-content': 'error',
'unicorn/prefer-includes': 'error',
'unicorn/prefer-keyboard-event-key': 'error',
'unicorn/prefer-math-trunc': 'error',
'unicorn/prefer-modern-dom-apis': 'error',
'unicorn/prefer-modern-math-apis': 'error',
'unicorn/prefer-negative-index': 'error',
'unicorn/prefer-node-protocol': 'error',
// 'unicorn/prefer-number-properties': 'error', TODO: re-evaluate
'unicorn/prefer-optional-catch-binding': 'error',
'unicorn/prefer-prototype-methods': 'error',
// 'unicorn/prefer-query-selector': 'error', TODO: re-evaluate
'unicorn/prefer-reflect-apply': 'error',
'unicorn/prefer-regexp-test': 'error',
// 'unicorn/prefer-string-replace-all': 'error', TODO: re-evaluate
// 'unicorn/prefer-string-slice': 'error', TODO re-evaluate
'unicorn/prefer-string-starts-ends-with': 'error',
'unicorn/prefer-string-trim-start-end': 'error',
'unicorn/prefer-top-level-await': 'error',
'unicorn/prefer-type-error': 'error',
'unicorn/throw-new-error': 'error',
}),
},
},
{
Expand Down
6 changes: 5 additions & 1 deletion src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export function rotki(
rotki: enableRotki,
storybook: enableStorybook,
typescript: enableTypeScript = isPackageExists('typescript'),
unicorn: enableUnicorn = true,
vue: enableVue = VuePackages.some(i => isPackageExists(i)),
vueI18n: enableVueI18n,
} = options;
Expand Down Expand Up @@ -124,12 +125,15 @@ export function rotki(
imports({
stylistic: stylisticOptions,
}),
unicorn(),

// Optional plugins (installed but not enabled by default)
perfectionist(),
);

if (enableUnicorn) {
configs.push(unicorn(enableUnicorn === true ? {} : enableUnicorn));
}

if (enableVue) {
componentExts.push('vue');
}
Expand Down
16 changes: 16 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ export interface OptionsComponentExts {
componentExts?: string[];
}

export interface OptionsUnicorn {
/**
* Include all rules recommended by `eslint-plugin-unicorn`, instead of only ones picked by Anthony.
*
* @default false
*/
allRecommended?: boolean;
}

export interface OptionsTypeScriptParserOptions {
/**
* Additional parser options for TypeScript.
Expand Down Expand Up @@ -254,6 +263,13 @@ export interface OptionsConfig extends OptionsComponentExts, OptionsProjectType
*/
jsx?: boolean;

/**
* Options for eslint-plugin-unicorn.
*
* @default true
*/
unicorn?: boolean | OptionsUnicorn;

/**
* Enable test support.
*
Expand Down

0 comments on commit fe712ee

Please sign in to comment.