- Timestamp:
- 01/21/25 03:08:24 (3 months ago)
- Branches:
- main
- Parents:
- 0c6b92a
- Location:
- imaps-frontend/node_modules/eslint-plugin-react-refresh
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/eslint-plugin-react-refresh/README.md
r0c6b92a r79a0317 1 1 # eslint-plugin-react-refresh [](https://www.npmjs.com/package/eslint-plugin-react-refresh) 2 2 3 Validate that your components can safely be updated with fast refresh. 4 5 ## Limitations 6 7 ⚠️ To avoid false positive, by default this plugin is only applied on `tsx` & `jsx` files. See options to run on JS files. ⚠️ 8 9 The plugin rely on naming conventions (i.e. use PascalCase for components, camelCase for util functions). This is why there are some limitations: 3 Validate that your components can safely be updated with Fast Refresh. 4 5 ## Explainer 6 7 "Fast Refresh", also known as "hot reloading", is a feature in many modern bundlers. 8 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. 9 10 `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. 11 12 ### Limitations 13 14 ⚠️ To avoid false positives, by default this plugin is only applied on `tsx` & `jsx` files. See [Options](#options) to run on JS files. ⚠️ 15 16 The plugin relies on naming conventions (i.e. use PascalCase for components, camelCase for util functions). This is why there are some limitations: 10 17 11 18 - `export *` are not supported and will be reported as an error … … 22 29 ## Usage 23 30 24 ```json 25 { 26 "plugins": ["react-refresh"], 27 "rules": { 28 "react-refresh/only-export-components": "warn" 29 } 30 } 31 ``` 32 33 ### Flat config 31 This plugin provides a single rule, `react-refresh/only-export-components`. There are multiple ways to enable it. 32 33 ### Recommended config 34 35 ```js 36 import reactRefresh from "eslint-plugin-react-refresh"; 37 38 export default [ 39 /* Main config */ 40 reactRefresh.configs.recommended, 41 ]; 42 ``` 43 44 ### Vite config 45 46 This enables the `allowConstantExport` option which is supported by Vite React plugins. 47 48 ```js 49 import reactRefresh from "eslint-plugin-react-refresh"; 50 51 export default [ 52 /* Main config */ 53 reactRefresh.configs.vite, 54 ]; 55 ``` 56 57 ### Without config 34 58 35 59 ```js … … 43 67 }, 44 68 rules: { 45 "react-refresh/only-export-components": " warn",69 "react-refresh/only-export-components": "error", 46 70 }, 47 71 }, … … 49 73 ``` 50 74 51 ## Fail 75 ### Legacy config 76 77 ```jsonc 78 { 79 "plugins": ["react-refresh"], 80 "rules": { 81 "react-refresh/only-export-components": "error" 82 } 83 } 84 ``` 85 86 ## Examples 87 88 These examples are from enabling `react-refresh/only-exports-components`. 89 90 ### Fail 52 91 53 92 ```jsx … … 75 114 ``` 76 115 77 ## Pass with allowConstantExport 116 ### Pass 117 118 ```jsx 119 export default function Foo() { 120 return <></>; 121 } 122 ``` 123 124 ```jsx 125 const foo = () => {}; 126 export const Bar = () => <></>; 127 ``` 128 129 ```jsx 130 import { App } from "./App"; 131 createRoot(document.getElementById("root")).render(<App />); 132 ``` 133 134 ## Options 135 136 These options are all present on `react-refresh/only-exports-components`. 137 138 ```ts 139 interface Options { 140 allowExportNames?: string[]; 141 allowConstantExport?: boolean; 142 customHOCs?: string[]; 143 checkJS?: boolean; 144 } 145 146 const defaultOptions: Options = { 147 allowExportNames: [], 148 allowConstantExport: false, 149 customHOCs: [], 150 checkJS: false, 151 }; 152 ``` 153 154 ### allowExportNames <small>(v0.4.4)</small> 155 156 > Default: `[]` 157 158 If you use a framework that handles HMR of some specific exports, you can use this option to avoid warning for them. 159 160 Example for [Remix](https://remix.run/docs/en/main/discussion/hot-module-replacement#supported-exports): 161 162 ```json 163 { 164 "react-refresh/only-export-components": [ 165 "error", 166 { "allowExportNames": ["meta", "links", "headers", "loader", "action"] } 167 ] 168 } 169 ``` 170 171 ### allowConstantExport <small>(v0.4.0)</small> 172 173 > Default: `false` (`true` in `vite` config) 174 175 Don't warn when a constant (string, number, boolean, templateLiteral) is exported aside one or more components. 176 177 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. 178 179 ```json 180 { 181 "react-refresh/only-export-components": [ 182 "error", 183 { "allowConstantExport": true } 184 ] 185 } 186 ``` 187 188 Enabling this option allows code such as the following: 78 189 79 190 ```jsx … … 82 193 ``` 83 194 84 ## Pass 85 86 ```jsx 87 export default function Foo() { 88 return <></>; 89 } 90 ``` 91 92 ```jsx 93 const foo = () => {}; 94 export const Bar = () => <></>; 95 ``` 96 97 ```jsx 98 import { App } from "./App"; 99 createRoot(document.getElementById("root")).render(<App />); 100 ``` 101 102 ## Options 103 104 ### allowExportNames <small>(v0.4.4)</small> 105 106 If you use a framework that handles HMR of some specific exports, you can use this option to avoid warning for them. 107 108 Example for [Remix](https://remix.run/docs/en/main/other-api/dev#:~:text=React%20Fast%20Refresh,-can%20only%20handle): 195 ### checkJS <small>(v0.3.3)</small> 196 197 > Default: `false` 198 199 If your 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. 200 201 ```json 202 { 203 "react-refresh/only-export-components": ["error", { "checkJS": true }] 204 } 205 ``` 206 207 ### customHOCs <small>(v0.4.15)</small> 208 209 If you're exporting a component wrapped in a custom HOC, you can use this option to avoid false positives. 109 210 110 211 ```json 111 212 { 112 213 "react-refresh/only-export-components": [ 113 " warn",114 { " allowExportNames": ["meta", "links", "headers", "loader", "action"] }214 "error", 215 { "customHOCs": ["observer", "withAuth"] } 115 216 ] 116 217 } 117 218 ``` 118 119 ### allowConstantExport <small>(v0.4.0)</small>120 121 Don't warn when a constant (string, number, boolean, templateLiteral) is exported aside one or more components.122 123 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.124 125 ```json126 {127 "react-refresh/only-export-components": [128 "warn",129 { "allowConstantExport": true }130 ]131 }132 ```133 134 ### checkJS <small>(v0.3.3)</small>135 136 If your 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.137 138 ```json139 {140 "react-refresh/only-export-components": ["warn", { "checkJS": true }]141 }142 ``` -
imaps-frontend/node_modules/eslint-plugin-react-refresh/index.js
r0c6b92a r79a0317 21 21 var src_exports = {}; 22 22 __export(src_exports, { 23 configs: () => configs, 23 24 default: () => src_default, 24 25 rules: () => rules … … 27 28 28 29 // src/only-export-components.ts 29 var possibleReactExportRE = /^[A-Z][a-zA-Z0-9]*$/u; 30 var strictReactExportRE = /^[A-Z][a-zA-Z0-9]*[a-z]+[a-zA-Z0-9]*$/u; 30 var reactComponentNameRE = /^[A-Z][a-zA-Z0-9]*$/u; 31 31 var onlyExportComponents = { 32 32 meta: { … … 44 44 type: "object", 45 45 properties: { 46 allowExportNames: { type: "array", items: { type: "string" } }, 46 47 allowConstantExport: { type: "boolean" }, 47 c heckJS: { type: "boolean"},48 allowExportNames: { type: "array", items: { type: "string" }}48 customHOCs: { type: "array", items: { type: "string" } }, 49 checkJS: { type: "boolean" } 49 50 }, 50 51 additionalProperties: false … … 55 56 create: (context) => { 56 57 const { 58 allowExportNames, 57 59 allowConstantExport = false, 58 c heckJS = false,59 allowExportNames60 customHOCs = [], 61 checkJS = false 60 62 } = context.options[0] ?? {}; 61 63 const filename = context.filename; … … 67 69 return {}; 68 70 const allowExportNamesSet = allowExportNames ? new Set(allowExportNames) : void 0; 71 const reactHOCs = ["memo", "forwardRef", ...customHOCs]; 72 const canBeReactFunctionComponent = (init) => { 73 if (!init) 74 return false; 75 if (init.type === "ArrowFunctionExpression") 76 return true; 77 if (init.type === "CallExpression" && init.callee.type === "Identifier") { 78 return reactHOCs.includes(init.callee.name); 79 } 80 return false; 81 }; 69 82 return { 70 83 Program(program) { 71 84 let hasExports = false; 72 let mayHaveReactExport = false;85 let hasReactExport = false; 73 86 let reactIsInScope = false; 74 87 const localComponents = []; … … 78 91 if (identifierNode.type !== "Identifier") 79 92 return; 80 if ( possibleReactExportRE.test(identifierNode.name)) {93 if (reactComponentNameRE.test(identifierNode.name)) { 81 94 localComponents.push(identifierNode); 82 95 } … … 96 109 } 97 110 if (isFunction) { 98 if ( possibleReactExportRE.test(identifierNode.name)) {99 mayHaveReactExport = true;111 if (reactComponentNameRE.test(identifierNode.name)) { 112 hasReactExport = true; 100 113 } else { 101 114 nonComponentExports.push(identifierNode); … … 112 125 return; 113 126 } 114 if (!mayHaveReactExport && possibleReactExportRE.test(identifierNode.name)) { 115 mayHaveReactExport = true; 116 } 117 if (!strictReactExportRE.test(identifierNode.name)) { 127 if (reactComponentNameRE.test(identifierNode.name)) { 128 hasReactExport = true; 129 } else { 118 130 nonComponentExports.push(identifierNode); 119 131 } … … 138 150 } else if (node.type === "CallExpression") { 139 151 if (node.callee.type === "CallExpression" && node.callee.callee.type === "Identifier" && node.callee.callee.name === "connect") { 140 mayHaveReactExport = true;152 hasReactExport = true; 141 153 } else if (node.callee.type !== "Identifier") { 142 if (node.callee.type === "MemberExpression" && node.callee.property.type === "Identifier" && reactHOCs. has(node.callee.property.name)) {143 mayHaveReactExport = true;154 if (node.callee.type === "MemberExpression" && node.callee.property.type === "Identifier" && reactHOCs.includes(node.callee.property.name)) { 155 hasReactExport = true; 144 156 } else { 145 157 context.report({ messageId: "anonymousExport", node }); 146 158 } 147 } else if (!reactHOCs. has(node.callee.name)) {159 } else if (!reactHOCs.includes(node.callee.name)) { 148 160 context.report({ messageId: "anonymousExport", node }); 149 161 } else if (((_a = node.arguments[0]) == null ? void 0 : _a.type) === "FunctionExpression" && node.arguments[0].id) { 150 162 handleExportIdentifier(node.arguments[0].id, true); 151 163 } else if (((_b = node.arguments[0]) == null ? void 0 : _b.type) === "Identifier") { 152 mayHaveReactExport = true;164 hasReactExport = true; 153 165 } else { 154 166 context.report({ messageId: "anonymousExport", node }); … … 200 212 return; 201 213 if (hasExports) { 202 if ( mayHaveReactExport) {214 if (hasReactExport) { 203 215 for (const node of nonComponentExports) { 204 216 context.report({ messageId: "namedExport", node }); … … 220 232 }; 221 233 } 222 };223 var reactHOCs = /* @__PURE__ */ new Set(["memo", "forwardRef"]);224 var canBeReactFunctionComponent = (init) => {225 if (!init)226 return false;227 if (init.type === "ArrowFunctionExpression")228 return true;229 if (init.type === "CallExpression" && init.callee.type === "Identifier") {230 return reactHOCs.has(init.callee.name);231 }232 return false;233 234 }; 234 235 var notReactComponentExpression = /* @__PURE__ */ new Set([ … … 251 252 "only-export-components": onlyExportComponents 252 253 }; 253 var src_default = { rules }; 254 var plugin = { rules }; 255 var configs = { 256 recommended: { 257 plugins: { "react-refresh": plugin }, 258 rules: { "react-refresh/only-export-components": "error" } 259 }, 260 vite: { 261 plugins: { "react-refresh": plugin }, 262 rules: { 263 "react-refresh/only-export-components": [ 264 "error", 265 { allowConstantExport: true } 266 ] 267 } 268 } 269 }; 270 var src_default = { rules, configs }; 254 271 // Annotate the CommonJS export names for ESM import in node: 255 272 0 && (module.exports = { 273 configs, 256 274 rules 257 275 }); -
imaps-frontend/node_modules/eslint-plugin-react-refresh/package.json
r0c6b92a r79a0317 1 1 { 2 "name": "eslint-plugin-react-refresh", 3 "description": "Validate that your components can safely be updated with fast refresh", 4 "version": "0.4.14", 5 "author": "Arnaud Barré (https://github.com/ArnaudBarre)", 6 "license": "MIT", 7 "repository": "github:ArnaudBarre/eslint-plugin-react-refresh", 8 "main": "index.js", 2 "_development": true, 3 "_from": "eslint-plugin-react-refresh@0.4.16", 4 "_id": "eslint-plugin-react-refresh@0.4.16", 5 "_inBundle": false, 6 "_integrity": "sha512-slterMlxAhov/DZO8NScf6mEeMBBXodFUolijDvrtTxyezyLoTQaa73FyYus/VbTdftd8wBgBxPMRk3poleXNQ==", 7 "_location": "/eslint-plugin-react-refresh", 8 "_phantomChildren": {}, 9 "_requested": { 10 "type": "version", 11 "registry": true, 12 "raw": "eslint-plugin-react-refresh@0.4.16", 13 "name": "eslint-plugin-react-refresh", 14 "escapedName": "eslint-plugin-react-refresh", 15 "rawSpec": "0.4.16", 16 "saveSpec": null, 17 "fetchSpec": "0.4.16" 18 }, 19 "_requiredBy": [ 20 "#DEV:/" 21 ], 22 "_resolved": "https://registry.npmjs.org/eslint-plugin-react-refresh/-/eslint-plugin-react-refresh-0.4.16.tgz", 23 "_shasum": "149dbc9279bd16942409f1c1d2f0dce3299430ef", 24 "_spec": "eslint-plugin-react-refresh@0.4.16", 25 "_where": "/home/stevetosak/Proekt/IMaps/imaps-frontend", 26 "author": { 27 "name": "Arnaud Barré", 28 "url": "https://github.com/ArnaudBarre" 29 }, 30 "bugs": { 31 "url": "https://github.com/ArnaudBarre/eslint-plugin-react-refresh/issues" 32 }, 33 "bundleDependencies": false, 34 "deprecated": false, 35 "description": "Validate that your components can safely be updated with Fast Refresh", 36 "homepage": "https://github.com/ArnaudBarre/eslint-plugin-react-refresh#readme", 9 37 "keywords": [ 10 38 "eslint", … … 14 42 "fast refresh" 15 43 ], 44 "license": "MIT", 45 "main": "index.js", 46 "name": "eslint-plugin-react-refresh", 16 47 "peerDependencies": { 17 "eslint": ">=7" 18 } 48 "eslint": ">=8.40" 49 }, 50 "repository": { 51 "type": "git", 52 "url": "git+https://github.com/ArnaudBarre/eslint-plugin-react-refresh.git" 53 }, 54 "type": "commonjs", 55 "types": "index.d.ts", 56 "version": "0.4.16" 19 57 }
Note:
See TracChangeset
for help on using the changeset viewer.