inital upload
This commit is contained in:
21
node_modules/eslint-plugin-react-refresh/LICENSE
generated
vendored
Normal file
21
node_modules/eslint-plugin-react-refresh/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Arnaud Barré (https://github.com/ArnaudBarre)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
218
node_modules/eslint-plugin-react-refresh/README.md
generated
vendored
Normal file
218
node_modules/eslint-plugin-react-refresh/README.md
generated
vendored
Normal file
@@ -0,0 +1,218 @@
|
||||
# eslint-plugin-react-refresh [](https://www.npmjs.com/package/eslint-plugin-react-refresh)
|
||||
|
||||
Validate that your components can safely be updated with Fast Refresh.
|
||||
|
||||
## Explainer
|
||||
|
||||
"Fast Refresh", also known as "hot reloading", is a feature in many modern bundlers.
|
||||
If you update some React component(s) on disk, then the bundler will know to update only the impacted parts of your page -- without a full page reload.
|
||||
|
||||
`eslint-plugin-react-refresh` enforces that your components are structured in a way that integrations such as [react-refresh](https://www.npmjs.com/package/react-refresh) expect.
|
||||
|
||||
### Limitations
|
||||
|
||||
⚠️ To avoid false positives, by default this plugin is only applied on `tsx` & `jsx` files. See [Options](#options) to run on JS files. ⚠️
|
||||
|
||||
The plugin relies on naming conventions (i.e. use PascalCase for components, camelCase for util functions). This is why there are some limitations:
|
||||
|
||||
- `export *` are not supported and will be reported as an error
|
||||
- Anonymous function are not supported (i.e `export default function() {}`)
|
||||
- Class components are not supported
|
||||
- All-uppercase function export is considered an error when not using direct named export (ex `const CMS = () => <></>; export { CMS }`)
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm i -D eslint-plugin-react-refresh
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
This plugin provides a single rule, `react-refresh/only-export-components`. There are multiple ways to enable it.
|
||||
|
||||
### Recommended config
|
||||
|
||||
```js
|
||||
import reactRefresh from "eslint-plugin-react-refresh";
|
||||
|
||||
export default [
|
||||
/* Main config */
|
||||
reactRefresh.configs.recommended,
|
||||
];
|
||||
```
|
||||
|
||||
### Vite config
|
||||
|
||||
This enables the `allowConstantExport` option which is supported by Vite React plugins.
|
||||
|
||||
```js
|
||||
import reactRefresh from "eslint-plugin-react-refresh";
|
||||
|
||||
export default [
|
||||
/* Main config */
|
||||
reactRefresh.configs.vite,
|
||||
];
|
||||
```
|
||||
|
||||
### Without config
|
||||
|
||||
```js
|
||||
import reactRefresh from "eslint-plugin-react-refresh";
|
||||
|
||||
export default [
|
||||
{
|
||||
// in main config for TSX/JSX source files
|
||||
plugins: {
|
||||
"react-refresh": reactRefresh,
|
||||
},
|
||||
rules: {
|
||||
"react-refresh/only-export-components": "error",
|
||||
},
|
||||
},
|
||||
];
|
||||
```
|
||||
|
||||
### Legacy config
|
||||
|
||||
```jsonc
|
||||
{
|
||||
"plugins": ["react-refresh"],
|
||||
"rules": {
|
||||
"react-refresh/only-export-components": "error"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
These examples are from enabling `react-refresh/only-exports-components`.
|
||||
|
||||
### Fail
|
||||
|
||||
```jsx
|
||||
export const foo = () => {};
|
||||
export const Bar = () => <></>;
|
||||
```
|
||||
|
||||
```jsx
|
||||
export default function () {}
|
||||
export default compose()(MainComponent)
|
||||
```
|
||||
|
||||
```jsx
|
||||
export * from "./foo";
|
||||
```
|
||||
|
||||
```jsx
|
||||
const Tab = () => {};
|
||||
export const tabs = [<Tab />, <Tab />];
|
||||
```
|
||||
|
||||
```jsx
|
||||
const App = () => {};
|
||||
createRoot(document.getElementById("root")).render(<App />);
|
||||
```
|
||||
|
||||
### Pass
|
||||
|
||||
```jsx
|
||||
export default function Foo() {
|
||||
return <></>;
|
||||
}
|
||||
```
|
||||
|
||||
```jsx
|
||||
const foo = () => {};
|
||||
export const Bar = () => <></>;
|
||||
```
|
||||
|
||||
```jsx
|
||||
import { App } from "./App";
|
||||
createRoot(document.getElementById("root")).render(<App />);
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
These options are all present on `react-refresh/only-exports-components`.
|
||||
|
||||
```ts
|
||||
interface Options {
|
||||
allowExportNames?: string[];
|
||||
allowConstantExport?: boolean;
|
||||
customHOCs?: string[];
|
||||
checkJS?: boolean;
|
||||
}
|
||||
|
||||
const defaultOptions: Options = {
|
||||
allowExportNames: [],
|
||||
allowConstantExport: false,
|
||||
customHOCs: [],
|
||||
checkJS: false,
|
||||
};
|
||||
```
|
||||
|
||||
### allowExportNames <small>(v0.4.4)</small>
|
||||
|
||||
> Default: `[]`
|
||||
|
||||
If you use a framework that handles HMR of some specific exports, you can use this option to avoid warning for them.
|
||||
|
||||
Example for [Remix](https://remix.run/docs/en/main/discussion/hot-module-replacement#supported-exports):
|
||||
|
||||
```json
|
||||
{
|
||||
"react-refresh/only-export-components": [
|
||||
"error",
|
||||
{ "allowExportNames": ["meta", "links", "headers", "loader", "action"] }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### allowConstantExport <small>(v0.4.0)</small>
|
||||
|
||||
> Default: `false` (`true` in `vite` config)
|
||||
|
||||
Don't warn when a constant (string, number, boolean, templateLiteral) is exported aside one or more components.
|
||||
|
||||
This should be enabled if the fast refresh implementation correctly handles this case (HMR when the constant doesn't change, propagate update to importers when the constant changes.). Vite supports it, PR welcome if you notice other integrations works well.
|
||||
|
||||
```json
|
||||
{
|
||||
"react-refresh/only-export-components": [
|
||||
"error",
|
||||
{ "allowConstantExport": true }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Enabling this option allows code such as the following:
|
||||
|
||||
```jsx
|
||||
export const CONSTANT = 3;
|
||||
export const Foo = () => <></>;
|
||||
```
|
||||
|
||||
### checkJS <small>(v0.3.3)</small>
|
||||
|
||||
> Default: `false`
|
||||
|
||||
If you're using JSX inside `.js` files (which I don't recommend because it forces you to configure every tool you use to switch the parser), you can still use the plugin by enabling this option. To reduce the number of false positive, only files importing `react` are checked.
|
||||
|
||||
```json
|
||||
{
|
||||
"react-refresh/only-export-components": ["error", { "checkJS": true }]
|
||||
}
|
||||
```
|
||||
|
||||
### customHOCs <small>(v0.4.15)</small>
|
||||
|
||||
If you're exporting a component wrapped in a custom HOC, you can use this option to avoid false positives.
|
||||
|
||||
```json
|
||||
{
|
||||
"react-refresh/only-export-components": [
|
||||
"error",
|
||||
{ "customHOCs": ["observer", "withAuth"] }
|
||||
]
|
||||
}
|
||||
```
|
||||
14
node_modules/eslint-plugin-react-refresh/index.d.ts
generated
vendored
Normal file
14
node_modules/eslint-plugin-react-refresh/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
type Config = {
|
||||
plugins: { "react-refresh": { rules: Record<string, any> } };
|
||||
rules: Record<string, any>;
|
||||
};
|
||||
|
||||
declare const _default: {
|
||||
rules: Record<string, any>;
|
||||
configs: {
|
||||
recommended: Config;
|
||||
vite: Config;
|
||||
};
|
||||
};
|
||||
|
||||
export = _default;
|
||||
294
node_modules/eslint-plugin-react-refresh/index.js
generated
vendored
Normal file
294
node_modules/eslint-plugin-react-refresh/index.js
generated
vendored
Normal file
@@ -0,0 +1,294 @@
|
||||
"use strict";
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
|
||||
// src/index.ts
|
||||
var index_exports = {};
|
||||
__export(index_exports, {
|
||||
configs: () => configs,
|
||||
default: () => index_default,
|
||||
rules: () => rules
|
||||
});
|
||||
module.exports = __toCommonJS(index_exports);
|
||||
|
||||
// src/only-export-components.ts
|
||||
var reactComponentNameRE = /^[A-Z][a-zA-Z0-9]*$/u;
|
||||
var onlyExportComponents = {
|
||||
meta: {
|
||||
messages: {
|
||||
exportAll: "This rule can't verify that `export *` only exports components.",
|
||||
namedExport: "Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components.",
|
||||
anonymousExport: "Fast refresh can't handle anonymous components. Add a name to your export.",
|
||||
localComponents: "Fast refresh only works when a file only exports components. Move your component(s) to a separate file.",
|
||||
noExport: "Fast refresh only works when a file has exports. Move your component(s) to a separate file.",
|
||||
reactContext: "Fast refresh only works when a file only exports components. Move your React context(s) to a separate file."
|
||||
},
|
||||
type: "problem",
|
||||
schema: [
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
allowExportNames: { type: "array", items: { type: "string" } },
|
||||
allowConstantExport: { type: "boolean" },
|
||||
customHOCs: { type: "array", items: { type: "string" } },
|
||||
checkJS: { type: "boolean" }
|
||||
},
|
||||
additionalProperties: false
|
||||
}
|
||||
]
|
||||
},
|
||||
defaultOptions: [],
|
||||
create: (context) => {
|
||||
const {
|
||||
allowExportNames,
|
||||
allowConstantExport = false,
|
||||
customHOCs = [],
|
||||
checkJS = false
|
||||
} = context.options[0] ?? {};
|
||||
const filename = context.filename;
|
||||
if (filename.includes(".test.") || filename.includes(".spec.") || filename.includes(".cy.") || filename.includes(".stories.")) {
|
||||
return {};
|
||||
}
|
||||
const shouldScan = filename.endsWith(".jsx") || filename.endsWith(".tsx") || checkJS && filename.endsWith(".js");
|
||||
if (!shouldScan) return {};
|
||||
const allowExportNamesSet = allowExportNames ? new Set(allowExportNames) : void 0;
|
||||
const reactHOCs = ["memo", "forwardRef", ...customHOCs];
|
||||
const canBeReactFunctionComponent = (init) => {
|
||||
if (!init) return false;
|
||||
const jsInit = skipTSWrapper(init);
|
||||
if (jsInit.type === "ArrowFunctionExpression") return true;
|
||||
if (jsInit.type === "CallExpression" && jsInit.callee.type === "Identifier") {
|
||||
return reactHOCs.includes(jsInit.callee.name);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
return {
|
||||
Program(program) {
|
||||
let hasExports = false;
|
||||
let hasReactExport = false;
|
||||
let reactIsInScope = false;
|
||||
const localComponents = [];
|
||||
const nonComponentExports = [];
|
||||
const reactContextExports = [];
|
||||
const handleExportIdentifier = (identifierNode, isFunction, init) => {
|
||||
if (identifierNode.type !== "Identifier") {
|
||||
nonComponentExports.push(identifierNode);
|
||||
return;
|
||||
}
|
||||
if (allowExportNamesSet == null ? void 0 : allowExportNamesSet.has(identifierNode.name)) return;
|
||||
if (allowConstantExport && init && constantExportExpressions.has(skipTSWrapper(init).type)) {
|
||||
return;
|
||||
}
|
||||
if (isFunction) {
|
||||
if (reactComponentNameRE.test(identifierNode.name)) {
|
||||
hasReactExport = true;
|
||||
} else {
|
||||
nonComponentExports.push(identifierNode);
|
||||
}
|
||||
} else {
|
||||
if (init && init.type === "CallExpression" && // createContext || React.createContext
|
||||
(init.callee.type === "Identifier" && init.callee.name === "createContext" || init.callee.type === "MemberExpression" && init.callee.property.type === "Identifier" && init.callee.property.name === "createContext")) {
|
||||
reactContextExports.push(identifierNode);
|
||||
return;
|
||||
}
|
||||
if (init && // Switch to allowList?
|
||||
notReactComponentExpression.has(init.type)) {
|
||||
nonComponentExports.push(identifierNode);
|
||||
return;
|
||||
}
|
||||
if (reactComponentNameRE.test(identifierNode.name)) {
|
||||
hasReactExport = true;
|
||||
} else {
|
||||
nonComponentExports.push(identifierNode);
|
||||
}
|
||||
}
|
||||
};
|
||||
const isHOCCallExpression = (node) => {
|
||||
const isCalleeHOC = (
|
||||
// support for react-redux
|
||||
// export default connect(mapStateToProps, mapDispatchToProps)(...)
|
||||
node.callee.type === "CallExpression" && node.callee.callee.type === "Identifier" && node.callee.callee.name === "connect" || // React.memo(...)
|
||||
node.callee.type === "MemberExpression" && node.callee.property.type === "Identifier" && reactHOCs.includes(node.callee.property.name) || // memo(...)
|
||||
node.callee.type === "Identifier" && reactHOCs.includes(node.callee.name)
|
||||
);
|
||||
if (!isCalleeHOC) return false;
|
||||
if (node.arguments.length === 0) return false;
|
||||
const arg = skipTSWrapper(node.arguments[0]);
|
||||
switch (arg.type) {
|
||||
case "Identifier":
|
||||
return true;
|
||||
case "FunctionExpression":
|
||||
if (!arg.id) return false;
|
||||
handleExportIdentifier(arg.id, true);
|
||||
return true;
|
||||
case "CallExpression":
|
||||
return isHOCCallExpression(arg);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
};
|
||||
const handleExportDeclaration = (node) => {
|
||||
if (node.type === "VariableDeclaration") {
|
||||
for (const variable of node.declarations) {
|
||||
handleExportIdentifier(
|
||||
variable.id,
|
||||
canBeReactFunctionComponent(variable.init),
|
||||
variable.init
|
||||
);
|
||||
}
|
||||
} else if (node.type === "FunctionDeclaration") {
|
||||
if (node.id === null) {
|
||||
context.report({ messageId: "anonymousExport", node });
|
||||
} else {
|
||||
handleExportIdentifier(node.id, true);
|
||||
}
|
||||
} else if (node.type === "CallExpression") {
|
||||
const isValid = isHOCCallExpression(node);
|
||||
if (isValid) {
|
||||
hasReactExport = true;
|
||||
} else {
|
||||
context.report({ messageId: "anonymousExport", node });
|
||||
}
|
||||
} else if (node.type === "TSEnumDeclaration") {
|
||||
nonComponentExports.push(node.id);
|
||||
}
|
||||
};
|
||||
for (const node of program.body) {
|
||||
if (node.type === "ExportAllDeclaration") {
|
||||
if (node.exportKind === "type") continue;
|
||||
hasExports = true;
|
||||
context.report({ messageId: "exportAll", node });
|
||||
} else if (node.type === "ExportDefaultDeclaration") {
|
||||
hasExports = true;
|
||||
const declaration = skipTSWrapper(node.declaration);
|
||||
if (declaration.type === "VariableDeclaration" || declaration.type === "FunctionDeclaration" || declaration.type === "CallExpression") {
|
||||
handleExportDeclaration(declaration);
|
||||
}
|
||||
if (declaration.type === "Identifier") {
|
||||
handleExportIdentifier(declaration);
|
||||
}
|
||||
if (declaration.type === "ArrowFunctionExpression") {
|
||||
context.report({ messageId: "anonymousExport", node });
|
||||
}
|
||||
} else if (node.type === "ExportNamedDeclaration") {
|
||||
if (node.exportKind === "type") continue;
|
||||
hasExports = true;
|
||||
if (node.declaration) {
|
||||
handleExportDeclaration(skipTSWrapper(node.declaration));
|
||||
}
|
||||
for (const specifier of node.specifiers) {
|
||||
handleExportIdentifier(
|
||||
specifier.exported.type === "Identifier" && specifier.exported.name === "default" ? specifier.local : specifier.exported
|
||||
);
|
||||
}
|
||||
} else if (node.type === "VariableDeclaration") {
|
||||
for (const variable of node.declarations) {
|
||||
if (variable.id.type === "Identifier" && reactComponentNameRE.test(variable.id.name) && canBeReactFunctionComponent(variable.init)) {
|
||||
localComponents.push(variable.id);
|
||||
}
|
||||
}
|
||||
} else if (node.type === "FunctionDeclaration") {
|
||||
if (reactComponentNameRE.test(node.id.name)) {
|
||||
localComponents.push(node.id);
|
||||
}
|
||||
} else if (node.type === "ImportDeclaration" && node.source.value === "react") {
|
||||
reactIsInScope = true;
|
||||
}
|
||||
}
|
||||
if (checkJS && !reactIsInScope) return;
|
||||
if (hasExports) {
|
||||
if (hasReactExport) {
|
||||
for (const node of nonComponentExports) {
|
||||
context.report({ messageId: "namedExport", node });
|
||||
}
|
||||
for (const node of reactContextExports) {
|
||||
context.report({ messageId: "reactContext", node });
|
||||
}
|
||||
} else if (localComponents.length) {
|
||||
for (const node of localComponents) {
|
||||
context.report({ messageId: "localComponents", node });
|
||||
}
|
||||
}
|
||||
} else if (localComponents.length) {
|
||||
for (const node of localComponents) {
|
||||
context.report({ messageId: "noExport", node });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
var skipTSWrapper = (node) => {
|
||||
if (node.type === "TSAsExpression" || node.type === "TSSatisfiesExpression") {
|
||||
return node.expression;
|
||||
}
|
||||
return node;
|
||||
};
|
||||
var constantExportExpressions = /* @__PURE__ */ new Set([
|
||||
"Literal",
|
||||
// 1, "foo"
|
||||
"UnaryExpression",
|
||||
// -1
|
||||
"TemplateLiteral",
|
||||
// `Some ${template}`
|
||||
"BinaryExpression"
|
||||
// 24 * 60
|
||||
]);
|
||||
var notReactComponentExpression = /* @__PURE__ */ new Set([
|
||||
"ArrayExpression",
|
||||
"AwaitExpression",
|
||||
"BinaryExpression",
|
||||
"ChainExpression",
|
||||
"ConditionalExpression",
|
||||
"Literal",
|
||||
"LogicalExpression",
|
||||
"ObjectExpression",
|
||||
"TemplateLiteral",
|
||||
"ThisExpression",
|
||||
"UnaryExpression",
|
||||
"UpdateExpression"
|
||||
]);
|
||||
|
||||
// src/index.ts
|
||||
var rules = {
|
||||
"only-export-components": onlyExportComponents
|
||||
};
|
||||
var plugin = { rules };
|
||||
var configs = {
|
||||
recommended: {
|
||||
name: "react-refresh/recommended",
|
||||
plugins: { "react-refresh": plugin },
|
||||
rules: { "react-refresh/only-export-components": "error" }
|
||||
},
|
||||
vite: {
|
||||
name: "react-refresh/vite",
|
||||
plugins: { "react-refresh": plugin },
|
||||
rules: {
|
||||
"react-refresh/only-export-components": [
|
||||
"error",
|
||||
{ allowConstantExport: true }
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
var index_default = { rules, configs };
|
||||
// Annotate the CommonJS export names for ESM import in node:
|
||||
0 && (module.exports = {
|
||||
configs,
|
||||
rules
|
||||
});
|
||||
21
node_modules/eslint-plugin-react-refresh/package.json
generated
vendored
Normal file
21
node_modules/eslint-plugin-react-refresh/package.json
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "eslint-plugin-react-refresh",
|
||||
"description": "Validate that your components can safely be updated with Fast Refresh",
|
||||
"version": "0.4.20",
|
||||
"type": "commonjs",
|
||||
"author": "Arnaud Barré (https://github.com/ArnaudBarre)",
|
||||
"license": "MIT",
|
||||
"repository": "github:ArnaudBarre/eslint-plugin-react-refresh",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"keywords": [
|
||||
"eslint",
|
||||
"eslint-plugin",
|
||||
"react",
|
||||
"react-refresh",
|
||||
"fast refresh"
|
||||
],
|
||||
"peerDependencies": {
|
||||
"eslint": ">=8.40"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user