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

Add support for React #193

Merged
merged 6 commits into from Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -75,6 +75,7 @@
"eslint-plugin-node": "~11.1.0",
"eslint-plugin-prettier": "~4.2.1",
"eslint-plugin-promise": "~6.1.1",
"eslint-plugin-react": "~7.32.2",
"eslint-plugin-sonarjs": "~0.19.0",
"eslint-plugin-spellcheck": "~0.0.20",
"eslint-plugin-unicorn": "~46.0.0",
Expand Down
111 changes: 111 additions & 0 deletions pnpm-lock.yaml

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

@@ -0,0 +1,23 @@
diff --git a/src/rules/react/jsx-no-constructed-context-values.d.ts b/src/rules/react/jsx-no-constructed-context-values.d.ts
index 410f060..e356693 100644
--- a/src/rules/react/jsx-no-constructed-context-values.d.ts
+++ b/src/rules/react/jsx-no-constructed-context-values.d.ts
@@ -1,17 +1,9 @@
import type { RuleConfig } from '../rule-config';

-/**
- * Option.
- */
-export interface JsxNoConstructedContextValuesOption {
- [k: string]: any;
-}
-
/**
* Options.
*/
-export type JsxNoConstructedContextValuesOptions =
- JsxNoConstructedContextValuesOption;
+export type JsxNoConstructedContextValuesOptions = [];

/**
* Disallows JSX context provider values from taking values that will cause needless rerenders.
4 changes: 4 additions & 0 deletions scripts/generate-rule-files/src/plugins-map.ts
Expand Up @@ -55,6 +55,10 @@ export const PLUGIN_REGISTRY: Readonly<Record<string, Plugin>> = {
name: 'Promise',
module: 'eslint-plugin-promise',
},
react: {
name: 'React',
module: 'eslint-plugin-react',
},
sonarjs: {
name: 'SonarJS',
prefix: 'sonarjs',
Expand Down
9 changes: 9 additions & 0 deletions src/config/extends/eslint-plugin-react.d.ts
@@ -0,0 +1,9 @@
/**
* Eslint React extensions.
*
* @see [Eslint React extensions](https://github.com/jsx-eslint/eslint-plugin-react)
*/
export type ReactExtensions =
| 'plugin:react/all'
| 'plugin:react/jsx-runtime'
| 'plugin:react/recommended';
2 changes: 2 additions & 0 deletions src/config/extends/index.d.ts
Expand Up @@ -10,6 +10,7 @@ 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 { ReactExtensions } from './eslint-plugin-react';
import type { SonarjsExtensions } from './eslint-plugin-sonarjs';
import type { UnicornExtensions } from './eslint-plugin-unicorn';
import type { VitestExtensions } from './eslint-plugin-vitest';
Expand All @@ -34,6 +35,7 @@ export type KnownExtensions = LiteralUnion<
| NodeExtensions
| PrettierExtensions
| PromiseExtensions
| ReactExtensions
| SonarjsExtensions
| TypescriptEslintExtensions
| UnicornExtensions
Expand Down
1 change: 1 addition & 0 deletions src/config/plugin.d.ts
Expand Up @@ -11,6 +11,7 @@ export type Plugin = LiteralUnion<
| 'mdx'
| 'prettier'
| 'promise'
| 'react'
| 'sonarjs'
| 'spellcheck'
| 'unicorn'
Expand Down
2 changes: 2 additions & 0 deletions src/config/settings/index.d.ts
Expand Up @@ -2,6 +2,7 @@ import type { ImportSettings } from './import';
import type { JSDocSettings } from './jsdoc';
import type { MdxSettings } from './mdx';
import type { NodeSettings } from './node';
import type { ReactSettings } from './react';

/**
* Settings.
Expand All @@ -11,4 +12,5 @@ export interface Settings
JSDocSettings,
MdxSettings,
NodeSettings,
ReactSettings,
Partial<Record<string, unknown>> {}
101 changes: 101 additions & 0 deletions src/config/settings/react.d.ts
@@ -0,0 +1,101 @@
import type { LiteralUnion } from '../../utility-types';

/**
* React settings.
*
* @see [React settings](https://github.com/jsx-eslint/eslint-plugin-react)
*/
export interface ReactSettings extends Partial<Record<string, unknown>> {
react?: {
/**
* Regex for Component Factory to use.
*
* @default 'createReactClass'
*/
createClass?: LiteralUnion<'createReactClass'>;

/**
* Pragma to use.
*
* @default 'React'
*/
pragma?: LiteralUnion<'React'>;

/**
* Fragment to use (may be a property of <pragma>).
*
* @default 'Fragment'
*/
fragment?: LiteralUnion<'Fragment'>;

/**
* React version. "detect" automatically picks the version you have installed.
*
* You can also use `16.0`, `16.3`, etc, if you want to override the detected value.
*
* It will default to "latest" and warn if missing, and to "detect" in the future.
*
* @default 'latest'
*/
version?: LiteralUnion<'latest' | 'detect'>;

/**
* Flow version.
*/
flowVersion?: string;
};

/**
* The names of any function used to wrap propTypes, e.g. `forbidExtraProps`.
*
* If this isn't set, any propTypes wrapped in a function will be skipped.
*/
propWrapperFunctions?: Array<
| string
| {
property: string;
object?: string;
/**
* For rules that check exact prop wrappers.
*/
exact?: boolean;
[k: string]: any;

Check warning on line 62 in src/config/settings/react.d.ts

View workflow job for this annotation

GitHub Actions / Lint: node-18, ubuntu-latest

Unexpected any. Specify a different type
}
>;

/**
* The name of any function used to wrap components, e.g. Mobx `observer` function.
*
* If this isn't set, components wrapped by these functions will be skipped.
*/
componentWrapperFunctions?: Array<
| string
| {
property: string;
object?: string;
[k: string]: any;

Check warning on line 76 in src/config/settings/react.d.ts

View workflow job for this annotation

GitHub Actions / Lint: node-18, ubuntu-latest

Unexpected any. Specify a different type
}
>;

/**
* Components used as alternatives to <form> for forms, eg. <Form endpoint={ url } />.
*/
formComponents?: Array<
| string
| {
name: string;
formAttribute: string;
}
>;

/**
* Components used as alternatives to <a> for linking, eg. <Link to={ url } />.
*/
linkComponents?: Array<
| string
| {
name: string;
linkAttribute: string;
}
>;
}
2 changes: 2 additions & 0 deletions src/rules/index.d.ts
Expand Up @@ -8,6 +8,7 @@ import type { JsoncRules } from './jsonc';
import type { NRules } from './n';
import type { NodeRules } from './node';
import type { PromiseRules } from './promise';
import type { ReactRules } from './react';
import type { RuleConfig } from './rule-config';
import type { SonarJSRules } from './sonarjs';
import type { SpellcheckRules } from './spellcheck';
Expand All @@ -34,6 +35,7 @@ export type Rules = Partial<
NodeRules &
NRules &
PromiseRules &
ReactRules &
SonarJSRules &
SpellcheckRules &
TypeScriptRules &
Expand Down