Skip to content

Commit

Permalink
feat: add ts typings
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Oct 17, 2024
1 parent 410e17b commit 5d356c4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
44 changes: 44 additions & 0 deletions lib/mod.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @fileoverview Allow multiple configurations of a rule without overriding it.
* @author
* 唯然<weiran.zsd@outlook.com>
*/

declare module "@weiran.zsd/multi-eslint-rule-config" {
import { Linter, Rule } from "eslint";

interface RuleOptions {
rule: string | Rule.RuleModule;
ruleConfig: Linter.RuleEntry;
asRuleName?: string;
plugin?: {
rules: Record<string, Rule.RuleModule>;
};
}

interface ConfigOptions {
name: string;
plugins: {
[prefix: string]: {
meta: {
name: string;
version: string;
};
rules: Record<string, Rule.RuleModule>;
};
};
rules: Record<string, Linter.RuleEntry>;
}

/**
* Generates a configuration object for ESLint with multiple rule configurations.
*
* @param options - Array or single item containing rule options to configure.
* @param prefix - Optional prefix to use for the plugin (default is "@@").
* @returns The generated configuration object.
*/
export function config(
options: RuleOptions | RuleOptions[],
prefix?: string,
): ConfigOptions;
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"author": "唯然<weiran.zsd@outlook.com",
"type": "commonjs",
"exports": "./lib/mod.js",
"types": "./lib/mod.d.ts",
"files": [
"LICENSE",
"README.md",
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Why?

This plugin allows you to configure the same ESLint rule multiple times, which is not possible with the default ESLint behavior. Normally, when the same rule (e.g., no-debugger) is defined more than once, the latter configuration overwrites the previous one. With this plugin, you can apply multiple configurations for the same rule, offering greater flexibility in defining your ESLint settings. This can be particularly useful for different scenarios or environments that require specific rule adjustments without overriding previous configurations.
This plugin allows you to configure the same ESLint rule multiple times, which is not possible with the default ESLint behavior. Normally, when the same rule (e.g., `[no-restricted-imports](https://eslint.org/docs/latest/rules/no-restricted-imports)`) is configured more than once, the latter configuration overwrites the previous one. With this plugin, you can apply multiple configurations for the same rule, offering greater flexibility in defining your ESLint settings. This can be particularly useful for different scenarios or environments that require specific rule adjustments without overriding previous configurations.

## Usage

Expand Down

0 comments on commit 5d356c4

Please sign in to comment.