-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add recommended presets for each plugin (#940)
- Loading branch information
Showing
27 changed files
with
614 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/plugins/eslint-plugin-react-debug/src/configs/all.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { RulePreset } from "@eslint-react/shared"; | ||
import { DEFAULT_ESLINT_REACT_SETTINGS } from "@eslint-react/shared"; | ||
|
||
export const name = "react-debug/all"; | ||
|
||
export const rules = { | ||
"react-debug/class-component": "warn", | ||
"react-debug/function-component": "warn", | ||
"react-debug/hook": "warn", | ||
"react-debug/is-from-react": "off", | ||
} as const satisfies RulePreset; | ||
|
||
export const settings = { | ||
"react-x": DEFAULT_ESLINT_REACT_SETTINGS, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
import { name, version } from "../package.json"; | ||
import classComponent from "./rules/class-component"; | ||
import functionComponent from "./rules/function-component"; | ||
import hook from "./rules/hook"; | ||
import isFromReact from "./rules/is-from-react"; | ||
import type { RulePreset } from "@eslint-react/shared"; | ||
|
||
export default { | ||
meta: { | ||
name, | ||
version, | ||
}, | ||
rules: { | ||
"class-component": classComponent, | ||
"function-component": functionComponent, | ||
hook: hook, | ||
"is-from-react": isFromReact, | ||
import * as allConfig from "./configs/all"; | ||
import { plugin } from "./plugin"; | ||
|
||
function makeConfig(config: { name: string; rules: RulePreset }) { | ||
return { | ||
...config, | ||
plugins: { | ||
"react-x": plugin, | ||
}, | ||
}; | ||
} | ||
|
||
// Part: deprecated rules | ||
/** @deprecated Use `hook` instead */ | ||
"react-hooks": hook, | ||
function makeLegacyConfig(config: { rules: RulePreset }) { | ||
return { | ||
plugins: ["react-x"], | ||
rules: config.rules, | ||
}; | ||
} | ||
|
||
export default { | ||
...plugin, | ||
configs: { | ||
["all"]: makeConfig(allConfig), | ||
["all-legacy"]: makeLegacyConfig(allConfig), | ||
}, | ||
} as const; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { name, version } from "../package.json"; | ||
import classComponent from "./rules/class-component"; | ||
import functionComponent from "./rules/function-component"; | ||
import hook from "./rules/hook"; | ||
import isFromReact from "./rules/is-from-react"; | ||
|
||
export const plugin = { | ||
meta: { | ||
name, | ||
version, | ||
}, | ||
rules: { | ||
"class-component": classComponent, | ||
"function-component": functionComponent, | ||
hook: hook, | ||
"is-from-react": isFromReact, | ||
|
||
// Part: deprecated rules | ||
/** @deprecated Use `hook` instead */ | ||
"react-hooks": hook, | ||
}, | ||
} as const; |
23 changes: 23 additions & 0 deletions
23
packages/plugins/eslint-plugin-react-dom/src/configs/recommended.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { RulePreset } from "@eslint-react/shared"; | ||
import { DEFAULT_ESLINT_REACT_SETTINGS } from "@eslint-react/shared"; | ||
|
||
export const name = "react-dom/recommended"; | ||
|
||
export const rules = { | ||
"react-dom/no-dangerously-set-innerhtml": "warn", | ||
"react-dom/no-dangerously-set-innerhtml-with-children": "error", | ||
"react-dom/no-find-dom-node": "error", | ||
"react-dom/no-missing-button-type": "warn", | ||
"react-dom/no-missing-iframe-sandbox": "warn", | ||
"react-dom/no-namespace": "error", | ||
"react-dom/no-render-return-value": "error", | ||
"react-dom/no-script-url": "warn", | ||
"react-dom/no-unknown-property": "warn", | ||
"react-dom/no-unsafe-iframe-sandbox": "warn", | ||
"react-dom/no-unsafe-target-blank": "warn", | ||
"react-dom/no-void-elements-with-children": "warn", | ||
} as const satisfies RulePreset; | ||
|
||
export const settings = { | ||
"react-x": DEFAULT_ESLINT_REACT_SETTINGS, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,28 @@ | ||
import { name, version } from "../package.json"; | ||
import noDangerouslySetInnerHTML from "./rules/no-dangerously-set-innerhtml"; | ||
import noDangerouslySetInnerHTMLWithChildren from "./rules/no-dangerously-set-innerhtml-with-children"; | ||
import noFindDomNode from "./rules/no-find-dom-node"; | ||
import noMissingButtonType from "./rules/no-missing-button-type"; | ||
import noMissingIframeSandbox from "./rules/no-missing-iframe-sandbox"; | ||
import noNamespace from "./rules/no-namespace"; | ||
import noRenderReturnValue from "./rules/no-render-return-value"; | ||
import noScriptUrl from "./rules/no-script-url"; | ||
import noUnknownProperty from "./rules/no-unknown-property"; | ||
import noUnsafeIframeSandbox from "./rules/no-unsafe-iframe-sandbox"; | ||
import noUnsafeTargetBlank from "./rules/no-unsafe-target-blank"; | ||
import noVoidElementsWithChildren from "./rules/no-void-elements-with-children"; | ||
import type { RulePreset } from "@eslint-react/shared"; | ||
|
||
export default { | ||
meta: { | ||
name, | ||
version, | ||
}, | ||
rules: { | ||
"no-dangerously-set-innerhtml": noDangerouslySetInnerHTML, | ||
"no-dangerously-set-innerhtml-with-children": noDangerouslySetInnerHTMLWithChildren, | ||
"no-find-dom-node": noFindDomNode, | ||
"no-missing-button-type": noMissingButtonType, | ||
"no-missing-iframe-sandbox": noMissingIframeSandbox, | ||
"no-namespace": noNamespace, | ||
"no-render-return-value": noRenderReturnValue, | ||
"no-script-url": noScriptUrl, | ||
"no-unknown-property": noUnknownProperty, | ||
"no-unsafe-iframe-sandbox": noUnsafeIframeSandbox, | ||
"no-unsafe-target-blank": noUnsafeTargetBlank, | ||
"no-void-elements-with-children": noVoidElementsWithChildren, | ||
import * as recommendedConfig from "./configs/recommended"; | ||
import { plugin } from "./plugin"; | ||
|
||
function makeConfig(config: { name: string; rules: RulePreset }) { | ||
return { | ||
...config, | ||
plugins: { | ||
"react-x": plugin, | ||
}, | ||
}; | ||
} | ||
|
||
// Part: deprecated rules | ||
/** @deprecated Use `no-void-elements-with-children` instead */ | ||
"no-children-in-void-dom-elements": noVoidElementsWithChildren, | ||
function makeLegacyConfig(config: { rules: RulePreset }) { | ||
return { | ||
plugins: ["react-x"], | ||
rules: config.rules, | ||
}; | ||
} | ||
|
||
export default { | ||
...plugin, | ||
configs: { | ||
["recommended"]: makeConfig(recommendedConfig), | ||
["recommended-legacy"]: makeLegacyConfig(recommendedConfig), | ||
}, | ||
} as const; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { name, version } from "../package.json"; | ||
import noDangerouslySetInnerHTML from "./rules/no-dangerously-set-innerhtml"; | ||
import noDangerouslySetInnerHTMLWithChildren from "./rules/no-dangerously-set-innerhtml-with-children"; | ||
import noFindDomNode from "./rules/no-find-dom-node"; | ||
import noMissingButtonType from "./rules/no-missing-button-type"; | ||
import noMissingIframeSandbox from "./rules/no-missing-iframe-sandbox"; | ||
import noNamespace from "./rules/no-namespace"; | ||
import noRenderReturnValue from "./rules/no-render-return-value"; | ||
import noScriptUrl from "./rules/no-script-url"; | ||
import noUnknownProperty from "./rules/no-unknown-property"; | ||
import noUnsafeIframeSandbox from "./rules/no-unsafe-iframe-sandbox"; | ||
import noUnsafeTargetBlank from "./rules/no-unsafe-target-blank"; | ||
import noVoidElementsWithChildren from "./rules/no-void-elements-with-children"; | ||
|
||
export const plugin = { | ||
meta: { | ||
name, | ||
version, | ||
}, | ||
rules: { | ||
"no-dangerously-set-innerhtml": noDangerouslySetInnerHTML, | ||
"no-dangerously-set-innerhtml-with-children": noDangerouslySetInnerHTMLWithChildren, | ||
"no-find-dom-node": noFindDomNode, | ||
"no-missing-button-type": noMissingButtonType, | ||
"no-missing-iframe-sandbox": noMissingIframeSandbox, | ||
"no-namespace": noNamespace, | ||
"no-render-return-value": noRenderReturnValue, | ||
"no-script-url": noScriptUrl, | ||
"no-unknown-property": noUnknownProperty, | ||
"no-unsafe-iframe-sandbox": noUnsafeIframeSandbox, | ||
"no-unsafe-target-blank": noUnsafeTargetBlank, | ||
"no-void-elements-with-children": noVoidElementsWithChildren, | ||
|
||
// Part: deprecated rules | ||
/** @deprecated Use `no-void-elements-with-children` instead */ | ||
"no-children-in-void-dom-elements": noVoidElementsWithChildren, | ||
}, | ||
} as const; |
9 changes: 9 additions & 0 deletions
9
packages/plugins/eslint-plugin-react-hooks-extra/src/configs/recommended.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { RulePreset } from "@eslint-react/shared"; | ||
|
||
export const name = "react-hooks-extra/recommended"; | ||
|
||
export const rules = { | ||
"react-hooks-extra/no-direct-set-state-in-use-effect": "warn", | ||
"react-hooks-extra/no-useless-custom-hooks": "warn", | ||
"react-hooks-extra/prefer-use-state-lazy-initialization": "warn", | ||
} as const satisfies RulePreset; |
54 changes: 25 additions & 29 deletions
54
packages/plugins/eslint-plugin-react-hooks-extra/src/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,28 @@ | ||
import { name, version } from "../package.json"; | ||
import noDirectSetStateInUseEffect from "./rules/no-direct-set-state-in-use-effect"; | ||
import noDirectSetStateInUseLayoutEffect from "./rules/no-direct-set-state-in-use-layout-effect"; | ||
import noUnnecessaryUseCallback from "./rules/no-unnecessary-use-callback"; | ||
import noUnnecessaryUseMemo from "./rules/no-unnecessary-use-memo"; | ||
import noUselessCustomHooks from "./rules/no-useless-custom-hooks"; | ||
import preferUseStateLazyInitialization from "./rules/prefer-use-state-lazy-initialization"; | ||
import type { RulePreset } from "@eslint-react/shared"; | ||
|
||
export default { | ||
meta: { | ||
name, | ||
version, | ||
}, | ||
rules: { | ||
"no-direct-set-state-in-use-effect": noDirectSetStateInUseEffect, | ||
"no-direct-set-state-in-use-layout-effect": noDirectSetStateInUseLayoutEffect, | ||
"no-unnecessary-use-callback": noUnnecessaryUseCallback, | ||
"no-unnecessary-use-memo": noUnnecessaryUseMemo, | ||
"no-useless-custom-hooks": noUselessCustomHooks, | ||
"prefer-use-state-lazy-initialization": preferUseStateLazyInitialization, | ||
import * as recommendedConfig from "./configs/recommended"; | ||
import { plugin } from "./plugin"; | ||
|
||
function makeConfig(config: { name: string; rules: RulePreset }) { | ||
return { | ||
...config, | ||
plugins: { | ||
"react-x": plugin, | ||
}, | ||
}; | ||
} | ||
|
||
// Part: deprecated rules | ||
/** @deprecated Use `no-useless-custom-hooks` instead */ | ||
"ensure-custom-hooks-using-other-hooks": noUselessCustomHooks, | ||
/** @deprecated Use `no-unnecessary-use-callback` instead */ | ||
"ensure-use-callback-has-non-empty-deps": noUnnecessaryUseCallback, | ||
/** @deprecated Use `no-unnecessary-use-memo` instead */ | ||
"ensure-use-memo-has-non-empty-deps": noUnnecessaryUseMemo, | ||
/** @deprecated Use `no-useless-custom-hooks` instead */ | ||
"no-redundant-custom-hook": noUselessCustomHooks, | ||
function makeLegacyConfig(config: { rules: RulePreset }) { | ||
return { | ||
plugins: ["react-x"], | ||
rules: config.rules, | ||
}; | ||
} | ||
|
||
export default { | ||
...plugin, | ||
configs: { | ||
["recommended"]: makeConfig(recommendedConfig), | ||
["recommended-legacy"]: makeLegacyConfig(recommendedConfig), | ||
}, | ||
} as const; | ||
}; |
Oops, something went wrong.