Skip to content

Commit

Permalink
feat: add support for rotki/eslint-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
kelsos committed Jan 11, 2024
1 parent aef3bb2 commit 8d288e2
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 0 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@
"typecheck": "tsc --noEmit"
},
"peerDependencies": {
"@rotki/eslint-plugin": ">=0.0.3",
"eslint": ">=8.56.0",
"eslint-plugin-cypress": ">=2.15.0"
},
"peerDependenciesMeta": {
"@rotki/eslint-plugin": {
"optional": true
},
"eslint-plugin-cypress": {
"optional": true
}
Expand Down
19 changes: 19 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/configs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export * from './node';

export * from './perfectionist';

export * from './rotki-plugin';

export * from './sort';

export * from './stylistic';
Expand Down
53 changes: 53 additions & 0 deletions src/configs/rotki-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import globals from 'globals';
import { ensurePackages, interopDefault } from '../utils';
import { GLOB_SRC, GLOB_VUE } from '../globs';
import type { FlatConfigItem, OptionsFiles, OptionsHasTypeScript, OptionsOverrides } from '../types';

export async function rotkiPlugin(options: OptionsOverrides & OptionsHasTypeScript & OptionsFiles = {}): Promise<FlatConfigItem[]> {
const {
files = [GLOB_SRC, GLOB_VUE],
overrides = {},
} = options;

await ensurePackages([
'@rotki/eslint-plugin',
]);

const [rotkiPlugin, parserVue] = await Promise.all([
interopDefault(import('@rotki/eslint-plugin')),
interopDefault(import('vue-eslint-parser')),
] as const);

return [
{
plugins: {
'@rotki': rotkiPlugin,
},
},
{
files,
languageOptions: {
globals: {
...globals.browser,
...globals.es2015,
},
parser: parserVue,
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 2022,
extraFileExtensions: ['.vue'],
parser: options.typescript
? await interopDefault(import('@typescript-eslint/parser')) as any
: null,
sourceType: 'module',
},
},
rules: {
...rotkiPlugin.configs.recommended.rules,
...overrides,
},
},
];
}
9 changes: 9 additions & 0 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
markdown,
node,
perfectionist,
rotkiPlugin,
sortPackageJson,
sortTsconfig,
stylistic,
Expand Down Expand Up @@ -55,6 +56,7 @@ export async function rotki(
cypress: enableCypress,
gitignore: enableGitignore = true,
isInEditor = !!((process.env.VSCODE_PID || process.env.JETBRAINS_IDE || process.env.VIM) && !process.env.CI),
rotki: enableRotki = false,
typescript: enableTypeScript = isPackageExists('typescript'),
vue: enableVue = VuePackages.some(i => isPackageExists(i)),
} = options;
Expand Down Expand Up @@ -138,6 +140,13 @@ export async function rotki(
}));
}

if (enableRotki) {
configs.push(rotkiPlugin({
overrides: getOverrides(options, 'rotki'),
typescript: !!enableTypeScript,
}));
}

if (options.jsonc ?? true) {
configs.push(
jsonc({
Expand Down
12 changes: 12 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export type Rules = WrapRuleConfig<
'cypress/no-force': RuleConfig<[]>;
'cypress/no-async-tests': RuleConfig<[]>;
'cypress/no-pause': RuleConfig<[]>;
} & {
'@rotki/no-deprecated-classes': RuleConfig<[]>;
}
>
>;
Expand Down Expand Up @@ -292,6 +294,16 @@ export interface OptionsConfig extends OptionsComponentExts {
*/
cypress?: boolean | OptionsCypress;

/**
* Enable rotki linting
* Requires installing:
* - `@rotki/eslint-plugin`
*
*
* @default false
*/
rotki?: boolean;

/**
* Control to disable some rules in editors.
* @default auto-detect based on the process.env
Expand Down

0 comments on commit 8d288e2

Please sign in to comment.