Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add eslint-plugin-promise #162

Merged
merged 1 commit into from Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -72,6 +72,7 @@
"eslint-plugin-n": "~15.6.0",
"eslint-plugin-node": "~11.1.0",
"eslint-plugin-prettier": "~4.2.1",
"eslint-plugin-promise": "~6.1.1",
"eslint-plugin-sonarjs": "~0.17.0",
"eslint-plugin-spellcheck": "~0.0.20",
"eslint-plugin-unicorn": "~45.0.2",
Expand Down
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

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

6 changes: 6 additions & 0 deletions scripts/generate-rule-files/src/plugins-map.ts
Expand Up @@ -7,6 +7,8 @@ import eslintPluginJSDoc from 'eslint-plugin-jsdoc';
import eslintPluginJsonc from 'eslint-plugin-jsonc';
import * as eslintPluginMdx from 'eslint-plugin-mdx';
// @ts-expect-error
import eslintPluginPromise from 'eslint-plugin-promise';
// @ts-expect-error
import eslintPluginNode from 'eslint-plugin-node';
// @ts-expect-error
import eslintPluginN from 'eslint-plugin-n';
Expand Down Expand Up @@ -72,6 +74,10 @@ export const PLUGIN_REGISTRY: Readonly<Record<string, Plugin>> = {
name: 'Node',
rules: (eslintPluginNode as Plugin).rules,
},
promise: {
name: 'Promise',
rules: (eslintPluginPromise as Plugin).rules,
},
sonarjs: {
name: 'SonarJS',
prefix: 'sonarjs',
Expand Down
6 changes: 6 additions & 0 deletions src/config/extends/eslint-plugin-promise.d.ts
@@ -0,0 +1,6 @@
/**
* Eslint promise extensions.
*
* @see [Eslint promise extensions](https://github.com/eslint-community/eslint-plugin-promise#usage)
*/
export type PromiseExtensions = 'plugin:promise/recommended';
2 changes: 2 additions & 0 deletions src/config/extends/index.d.ts
Expand Up @@ -7,6 +7,7 @@ import type { MdxExtensions } from './eslint-plugin-mdx';
import type { NExtensions } from './eslint-plugin-n';
import type { NodeExtensions } from './eslint-plugin-node';
import type { PrettierExtensions } from './eslint-plugin-prettier';
import type { PromiseExtensions } from './eslint-plugin-promise';
import type { SonarjsExtensions } from './eslint-plugin-sonarjs';
import type { UnicornExtensions } from './eslint-plugin-unicorn';
import type { VueExtensions } from './eslint-plugin-vue';
Expand All @@ -27,6 +28,7 @@ export type KnownExtensions = LiteralUnion<
| NExtensions
| NodeExtensions
| PrettierExtensions
| PromiseExtensions
| SonarjsExtensions
| TypescriptEslintExtensions
| UnicornExtensions
Expand Down
1 change: 1 addition & 0 deletions src/config/plugin.d.ts
Expand Up @@ -9,6 +9,7 @@ export type Plugin = LiteralUnion<
| 'jsdoc'
| 'mdx'
| 'prettier'
| 'promise'
| 'sonarjs'
| 'spellcheck'
| 'unicorn'
Expand Down
2 changes: 2 additions & 0 deletions src/rules/index.d.ts
Expand Up @@ -5,6 +5,7 @@ import type { JSDocRules } from './jsdoc';
import type { JsoncRules } from './jsonc';
import type { NRules } from './n';
import type { NodeRules } from './node';
import type { PromiseRules } from './promise';
import type { RuleConfig } from './rule-config';
import type { SonarJSRules } from './sonarjs';
import type { SpellcheckRules } from './spellcheck';
Expand All @@ -27,6 +28,7 @@ export type Rules = Partial<
JsoncRules &
NodeRules &
NRules &
PromiseRules &
SonarJSRules &
SpellcheckRules &
TypeScriptRules &
Expand Down
31 changes: 31 additions & 0 deletions src/rules/promise/always-return.d.ts
@@ -0,0 +1,31 @@
import type { RuleConfig } from '../rule-config';

/**
* Option.
*/
export interface AlwaysReturnOption {
ignoreLastCallback?: boolean;
}

/**
* Options.
*/
export type AlwaysReturnOptions = [AlwaysReturnOption?];

/**
*
* @see [always-return](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/always-return.md)
*/
export type AlwaysReturnRuleConfig = RuleConfig<AlwaysReturnOptions>;

/**
*
* @see [always-return](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/always-return.md)
*/
export interface AlwaysReturnRule {
/**
*
* @see [always-return](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/always-return.md)
*/
'promise/always-return': AlwaysReturnRuleConfig;
}
19 changes: 19 additions & 0 deletions src/rules/promise/avoid-new.d.ts
@@ -0,0 +1,19 @@
import type { RuleConfig } from '../rule-config';

/**
*
* @see [avoid-new](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/avoid-new.md)
*/
export type AvoidNewRuleConfig = RuleConfig<[]>;

/**
*
* @see [avoid-new](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/avoid-new.md)
*/
export interface AvoidNewRule {
/**
*
* @see [avoid-new](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/avoid-new.md)
*/
'promise/avoid-new': AvoidNewRuleConfig;
}
33 changes: 33 additions & 0 deletions src/rules/promise/catch-or-return.d.ts
@@ -0,0 +1,33 @@
import type { RuleConfig } from '../rule-config';

/**
* Option.
*/
export interface CatchOrReturnOption {
allowFinally?: boolean;
allowThen?: boolean;
terminationMethod?: string | string[];
}

/**
* Options.
*/
export type CatchOrReturnOptions = [CatchOrReturnOption?];

/**
*
* @see [catch-or-return](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/catch-or-return.md)
*/
export type CatchOrReturnRuleConfig = RuleConfig<CatchOrReturnOptions>;

/**
*
* @see [catch-or-return](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/catch-or-return.md)
*/
export interface CatchOrReturnRule {
/**
*
* @see [catch-or-return](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/catch-or-return.md)
*/
'promise/catch-or-return': CatchOrReturnRuleConfig;
}
34 changes: 34 additions & 0 deletions src/rules/promise/index.d.ts
@@ -0,0 +1,34 @@
import type { AlwaysReturnRule } from './always-return';
import type { AvoidNewRule } from './avoid-new';
import type { CatchOrReturnRule } from './catch-or-return';
import type { NoCallbackInPromiseRule } from './no-callback-in-promise';
import type { NoMultipleResolvedRule } from './no-multiple-resolved';
import type { NoNativeRule } from './no-native';
import type { NoNestingRule } from './no-nesting';
import type { NoNewStaticsRule } from './no-new-statics';
import type { NoPromiseInCallbackRule } from './no-promise-in-callback';
import type { NoReturnInFinallyRule } from './no-return-in-finally';
import type { NoReturnWrapRule } from './no-return-wrap';
import type { ParamNamesRule } from './param-names';
import type { PreferAwaitToCallbacksRule } from './prefer-await-to-callbacks';
import type { PreferAwaitToThenRule } from './prefer-await-to-then';
import type { ValidParamsRule } from './valid-params';

/**
* All Promise rules.
*/
export type PromiseRules = ParamNamesRule &
NoReturnWrapRule &
AlwaysReturnRule &
CatchOrReturnRule &
PreferAwaitToCallbacksRule &
PreferAwaitToThenRule &
NoNativeRule &
NoCallbackInPromiseRule &
NoPromiseInCallbackRule &
NoNestingRule &
AvoidNewRule &
NoNewStaticsRule &
NoReturnInFinallyRule &
ValidParamsRule &
NoMultipleResolvedRule;
32 changes: 32 additions & 0 deletions src/rules/promise/no-callback-in-promise.d.ts
@@ -0,0 +1,32 @@
import type { RuleConfig } from '../rule-config';

/**
* Option.
*/
export interface NoCallbackInPromiseOption {
exceptions?: string[];
}

/**
* Options.
*/
export type NoCallbackInPromiseOptions = [NoCallbackInPromiseOption?];

/**
*
* @see [no-callback-in-promise](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/no-callback-in-promise.md)
*/
export type NoCallbackInPromiseRuleConfig =
RuleConfig<NoCallbackInPromiseOptions>;

/**
*
* @see [no-callback-in-promise](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/no-callback-in-promise.md)
*/
export interface NoCallbackInPromiseRule {
/**
*
* @see [no-callback-in-promise](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/no-callback-in-promise.md)
*/
'promise/no-callback-in-promise': NoCallbackInPromiseRuleConfig;
}
19 changes: 19 additions & 0 deletions src/rules/promise/no-multiple-resolved.d.ts
@@ -0,0 +1,19 @@
import type { RuleConfig } from '../rule-config';

/**
*
* @see [no-multiple-resolved](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/no-multiple-resolved.md)
*/
export type NoMultipleResolvedRuleConfig = RuleConfig<[]>;

/**
*
* @see [no-multiple-resolved](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/no-multiple-resolved.md)
*/
export interface NoMultipleResolvedRule {
/**
*
* @see [no-multiple-resolved](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/no-multiple-resolved.md)
*/
'promise/no-multiple-resolved': NoMultipleResolvedRuleConfig;
}
19 changes: 19 additions & 0 deletions src/rules/promise/no-native.d.ts
@@ -0,0 +1,19 @@
import type { RuleConfig } from '../rule-config';

/**
*
* @see [no-native](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/no-native.md)
*/
export type NoNativeRuleConfig = RuleConfig<[]>;

/**
*
* @see [no-native](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/no-native.md)
*/
export interface NoNativeRule {
/**
*
* @see [no-native](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/no-native.md)
*/
'promise/no-native': NoNativeRuleConfig;
}
19 changes: 19 additions & 0 deletions src/rules/promise/no-nesting.d.ts
@@ -0,0 +1,19 @@
import type { RuleConfig } from '../rule-config';

/**
*
* @see [no-nesting](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/no-nesting.md)
*/
export type NoNestingRuleConfig = RuleConfig<[]>;

/**
*
* @see [no-nesting](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/no-nesting.md)
*/
export interface NoNestingRule {
/**
*
* @see [no-nesting](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/no-nesting.md)
*/
'promise/no-nesting': NoNestingRuleConfig;
}
19 changes: 19 additions & 0 deletions src/rules/promise/no-new-statics.d.ts
@@ -0,0 +1,19 @@
import type { RuleConfig } from '../rule-config';

/**
*
* @see [no-new-statics](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/no-new-statics.md)
*/
export type NoNewStaticsRuleConfig = RuleConfig<[]>;

/**
*
* @see [no-new-statics](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/no-new-statics.md)
*/
export interface NoNewStaticsRule {
/**
*
* @see [no-new-statics](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/no-new-statics.md)
*/
'promise/no-new-statics': NoNewStaticsRuleConfig;
}
19 changes: 19 additions & 0 deletions src/rules/promise/no-promise-in-callback.d.ts
@@ -0,0 +1,19 @@
import type { RuleConfig } from '../rule-config';

/**
*
* @see [no-promise-in-callback](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/no-promise-in-callback.md)
*/
export type NoPromiseInCallbackRuleConfig = RuleConfig<[]>;

/**
*
* @see [no-promise-in-callback](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/no-promise-in-callback.md)
*/
export interface NoPromiseInCallbackRule {
/**
*
* @see [no-promise-in-callback](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/no-promise-in-callback.md)
*/
'promise/no-promise-in-callback': NoPromiseInCallbackRuleConfig;
}
19 changes: 19 additions & 0 deletions src/rules/promise/no-return-in-finally.d.ts
@@ -0,0 +1,19 @@
import type { RuleConfig } from '../rule-config';

/**
*
* @see [no-return-in-finally](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/no-return-in-finally.md)
*/
export type NoReturnInFinallyRuleConfig = RuleConfig<[]>;

/**
*
* @see [no-return-in-finally](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/no-return-in-finally.md)
*/
export interface NoReturnInFinallyRule {
/**
*
* @see [no-return-in-finally](https://github.com/eslint-community/eslint-plugin-promise/blob/main/docs/rules/no-return-in-finally.md)
*/
'promise/no-return-in-finally': NoReturnInFinallyRuleConfig;
}