38 lines
972 B
TypeScript
38 lines
972 B
TypeScript
import type { ESLintUtils } from '@typescript-eslint/utils';
|
|
import type { Rule, Linter } from 'eslint';
|
|
|
|
export function defineRules(rules: {
|
|
[ruleName: string]: Rule.RuleModule | ESLintUtils.RuleModule<string, unknown[]>;
|
|
}) {
|
|
return rules;
|
|
}
|
|
|
|
export function defineConfig(config: Linter.Config): Linter.Config;
|
|
export function defineConfig(config: Linter.Config[]): Linter.Config[];
|
|
|
|
export function defineConfig(config: Linter.Config | Linter.Config[]) {
|
|
if (!config || (Array.isArray(config) && config.some(c => !c))) {
|
|
console.trace();
|
|
throw new Error('Config cannot be empty');
|
|
}
|
|
return config;
|
|
}
|
|
|
|
export function defineRule({
|
|
name,
|
|
create,
|
|
...meta
|
|
}: Rule.RuleMetaData & {
|
|
name?: string;
|
|
create: (context: Rule.RuleContext) => Rule.RuleListener;
|
|
}): Rule.RuleModule {
|
|
const module: Rule.RuleModule = {
|
|
meta,
|
|
create,
|
|
};
|
|
if (name != null) {
|
|
Object.defineProperty(module, 'name', { value: name });
|
|
}
|
|
return module;
|
|
}
|