Skip to content

Commit

Permalink
feat: add eslint-plugin-vuetify support
Browse files Browse the repository at this point in the history
  • Loading branch information
kelsos committed Jan 12, 2024
1 parent 04b5e56 commit 80d500c
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 19 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,18 @@
"peerDependencies": {
"@rotki/eslint-plugin": ">=0.0.3",
"eslint": ">=8.56.0",
"eslint-plugin-cypress": ">=2.15.0"
"eslint-plugin-cypress": ">=2.15.0",
"eslint-plugin-vuetify": "^1 || ^2"
},
"peerDependenciesMeta": {
"@rotki/eslint-plugin": {
"optional": true
},
"eslint-plugin-cypress": {
"optional": true
},
"eslint-plugin-vuetify": {
"optional": true
}
},
"dependencies": {
Expand Down
51 changes: 45 additions & 6 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 @@ -32,4 +32,6 @@ export * from './unicorn';

export * from './vue';

export * from './vuetify';

export * from './yaml';
6 changes: 3 additions & 3 deletions src/configs/rotki-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ export async function rotkiPlugin(options: OptionsOverrides & OptionsHasTypeScri
'@rotki/eslint-plugin',
]);

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

return [
{
plugins: {
'@rotki': rotkiPlugin,
'@rotki': pluginRotki,
},
},
{
Expand All @@ -45,7 +45,7 @@ export async function rotkiPlugin(options: OptionsOverrides & OptionsHasTypeScri
},
},
rules: {
...rotkiPlugin.configs.recommended.rules,
...pluginRotki.configs.recommended.rules,
...overrides,
},
},
Expand Down
52 changes: 52 additions & 0 deletions src/configs/vuetify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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 vuetify(options: OptionsOverrides & OptionsHasTypeScript & OptionsFiles = {}): Promise<FlatConfigItem[]> {
const {
files = [GLOB_SRC, GLOB_VUE],
overrides = { },
} = options;

await ensurePackages(['eslint-plugin-vuetify']);

const [pluginVuetify, parserVue] = await Promise.all([
interopDefault(import('eslint-plugin-vuetify')),
interopDefault(import('vue-eslint-parser')),
] as const);

return [
{
plugins: {
vuetify: pluginVuetify,
},
},
{
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: {
...pluginVuetify.configs.base.rules,
...pluginVuetify.configs.recommended.rules,
...overrides,
},
},
];
}
12 changes: 11 additions & 1 deletion src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
typescript,
unicorn,
vue,
vuetify,
yaml,
} from './configs';
import { combine, interopDefault } from './utils';
Expand Down Expand Up @@ -56,9 +57,10 @@ 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,
rotki: enableRotki,
typescript: enableTypeScript = isPackageExists('typescript'),
vue: enableVue = VuePackages.some(i => isPackageExists(i)),
vuetify: enableVuetify,
} = options;

const stylisticOptions = options.stylistic === false
Expand Down Expand Up @@ -147,6 +149,14 @@ export async function rotki(
}));
}

if (enableVuetify) {
configs.push(vuetify({
...resolveSubOptions(options, 'vuetify'),
overrides: getOverrides(options, 'vuetify'),
typescript: !!enableTypeScript,
}));
}

if (options.jsonc ?? true) {
configs.push(
jsonc({
Expand Down
2 changes: 2 additions & 0 deletions src/globs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export const GLOB_EXCLUDE = [
'**/output',
'**/coverage',
'**/temp',
'**/logs',
'**/build',
'**/fixtures',
'**/.vitepress/cache',
'**/.nuxt',
Expand Down
20 changes: 12 additions & 8 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { VuetifyRules } from './vendor/rules/vuetify';
import type { VendoredPrettierOptions } from './vendor/prettier';
import type { FlatGitignoreOptions } from 'eslint-config-flat-gitignore';
import type { ParserOptions } from '@typescript-eslint/parser';
Expand Down Expand Up @@ -55,7 +56,7 @@ export type Rules = WrapRuleConfig<
'cypress/no-pause': RuleConfig<[]>;
} & {
'@rotki/no-deprecated-classes': RuleConfig<[]>;
}
} & VuetifyRules
>
>;

Expand Down Expand Up @@ -248,13 +249,6 @@ export interface OptionsConfig extends OptionsComponentExts {
*/
yaml?: boolean | OptionsOverrides;

/**
* Enable TOML support.
*
* @default true
*/
toml?: boolean | OptionsOverrides;

/**
* Enable linting for **code snippets** in Markdown.
*
Expand Down Expand Up @@ -304,6 +298,16 @@ export interface OptionsConfig extends OptionsComponentExts {
*/
rotki?: boolean;

/**
* Enable vuetify linting support.
* Requires installing:
* - `eslint-plugin-vuetify`
*
*
* @default false
*/
vuetify?: boolean | OptionsOverrides;

/**
* Control to disable some rules in editors.
* @default auto-detect based on the process.env
Expand Down
18 changes: 18 additions & 0 deletions src/vendor/rules/vuetify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { RuleConfig } from '@antfu/eslint-define-config';

export type ValidVLostConfiguration = [{
allowModifiers?: boolean;
}];

export interface VuetifyRules {
'vue/valid-v-slot': RuleConfig<ValidVLostConfiguration>;

'vuetify/no-deprecated-classes': RuleConfig<[]>;
'vuetify/no-deprecated-colors': RuleConfig<[]>;
'vuetify/no-deprecated-components': RuleConfig<[]>;
'vuetify/no-deprecated-events': RuleConfig<[]>;
'vuetify/no-deprecated-props': RuleConfig<[]>;
'vuetify/no-deprecated-slots': RuleConfig<[]>;

'vuetify/grid-unknown-attributes': RuleConfig<[]>;
}
42 changes: 42 additions & 0 deletions src/vendor/vuetify.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Types are based on v2.x of vuetify plugin.
* Not paying to much attention to it since we are going to use the
* recommended anyway.
*/
declare module 'eslint-plugin-vuetify' {
import type { ValidVLostConfiguration, VuetifyRules } from './rules/vuetify';
import type { RuleConfig } from '@antfu/eslint-define-config';

const baseRules = {
'vue/valid-v-slot': ['error' as const, {
allowModifiers: true,
}] satisfies RuleConfig<ValidVLostConfiguration>,

'vuetify/no-deprecated-classes': 'error' as const,
'vuetify/no-deprecated-colors': 'error' as const, // v2.x
'vuetify/no-deprecated-components': 'error' as const,
'vuetify/no-deprecated-events': 'error' as const, // v2.x
'vuetify/no-deprecated-props': 'error' as const,
'vuetify/no-deprecated-slots': 'error' as const, // v2.x
};

const baseConfig = {
plugins: ['vuetify'],
rules: baseRules,
};

export const vuetify: {
rules: VuetifyRules;
configs: {
base: typeof baseConfig;
recommended: typeof baseConfig & {
rules: {
'vuetify/grid-unknown-attributes': 'error';
};
};
};
};

// eslint-disable-next-line import/no-default-export
export default vuetify;
}

0 comments on commit 80d500c

Please sign in to comment.