Skip to content

Commit

Permalink
feat: add eslint-plugin-promise (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 authored Jan 2, 2023
1 parent 694223a commit 87b27f1
Show file tree
Hide file tree
Showing 23 changed files with 415 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
}
Loading

0 comments on commit 87b27f1

Please sign in to comment.