Update
This commit is contained in:
50
src/index.ts
50
src/index.ts
@ -56,11 +56,18 @@ export interface LocalRuleOptions {
|
||||
|
||||
export type RuleOptions = Rules & Partial<LocalRuleOptions>;
|
||||
|
||||
export interface CustomRule {
|
||||
rule: () => Promise<{
|
||||
default: Rule.RuleModule | ESLintUtils.RuleModule<string, unknown[]>;
|
||||
}>;
|
||||
options?: RuleLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* ESLint Configuration.
|
||||
* @see [ESLint Configuration](https://eslint.org/docs/latest/user-guide/configuring/)
|
||||
*/
|
||||
type Config = Omit<ESLintConfig, 'rules'> & {
|
||||
export type InputConfig = Omit<ESLintConfig, 'rules'> & {
|
||||
/**
|
||||
* Rules.
|
||||
* @see [Rules](https://eslint.org/docs/latest/user-guide/configuring/rules)
|
||||
@ -68,24 +75,13 @@ type Config = Omit<ESLintConfig, 'rules'> & {
|
||||
rules?: RuleOptions;
|
||||
|
||||
/**
|
||||
* Glob pattern to find paths to custom rule files in JavaScript or TypeScript.
|
||||
* Note this must be a string literal or an array of string literals since
|
||||
* this is statically analyzed.
|
||||
*/
|
||||
customRules?: {
|
||||
rule: () => Promise<{
|
||||
default: Rule.RuleModule | ESLintUtils.RuleModule<string, unknown[]>;
|
||||
}>;
|
||||
options?: RuleLevel;
|
||||
}[];
|
||||
customRuleFiles?: string | string[];
|
||||
};
|
||||
|
||||
export function defineCustomRule<Options extends readonly unknown[]>(
|
||||
rule: () => Promise<{
|
||||
default: Rule.RuleModule | ESLintUtils.RuleModule<string, Options>;
|
||||
}>,
|
||||
options?: Options,
|
||||
) {
|
||||
return { rule, options };
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a ESLint config object.
|
||||
*
|
||||
@ -104,15 +100,17 @@ export function defineCustomRule<Options extends readonly unknown[]>(
|
||||
* Non bundled:
|
||||
* 1. [`graphql`](https://the-guild.dev/graphql/eslint/rules)
|
||||
*/
|
||||
export function extendConfig({
|
||||
plugins = [],
|
||||
settings,
|
||||
rules,
|
||||
extends: _extends,
|
||||
overrides,
|
||||
customRules,
|
||||
...rest
|
||||
}: Config = {}): ESLintConfig {
|
||||
export function extendConfig(of: InputConfig = {}): ESLintConfig {
|
||||
const {
|
||||
plugins = [],
|
||||
settings,
|
||||
rules,
|
||||
extends: _extends,
|
||||
overrides,
|
||||
customRuleFiles,
|
||||
...rest
|
||||
} = of;
|
||||
|
||||
const hasReact = plugins.includes('react');
|
||||
const hasReactRefresh = plugins.includes('react-refresh');
|
||||
const hasUnicorn = plugins.includes('unicorn');
|
||||
@ -129,7 +127,7 @@ export function extendConfig({
|
||||
fs.mkdirSync(ruleDir, { recursive: true });
|
||||
}
|
||||
|
||||
const result: Config = {
|
||||
const result: InputConfig = {
|
||||
root: true,
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: unique('@typescript-eslint', 'import', 'rules', plugins),
|
||||
|
Reference in New Issue
Block a user