{"id":26904263,"url":"https://github.com/gstj/safe-jsx","last_synced_at":"2025-04-01T10:53:00.212Z","repository":{"id":164233883,"uuid":"639671983","full_name":"GSTJ/safe-jsx","owner":"GSTJ","description":"An ESLint plugin that enforces explicit boolean conversion before using the \u0026\u0026 operator with JSX in React and React Native applications.","archived":false,"fork":false,"pushed_at":"2024-04-10T03:33:02.000Z","size":50,"stargazers_count":28,"open_issues_count":10,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-05-02T02:55:14.218Z","etag":null,"topics":["boolean","conversion","eslint","eslint-plugin","javascript","jsx","linting","quality","react","react-native","safe-settings"],"latest_commit_sha":null,"homepage":"https://github.com/GSTJ/safe-jsx","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GSTJ.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":["gstj"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2023-05-12T01:10:25.000Z","updated_at":"2024-02-26T14:43:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"770c8a6b-7c5f-42ae-9fda-aba6901e9133","html_url":"https://github.com/GSTJ/safe-jsx","commit_stats":{"total_commits":41,"total_committers":2,"mean_commits":20.5,"dds":0.07317073170731703,"last_synced_commit":"c670d7e9d22e75dd69a988c4429a47ca40fedb0f"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GSTJ%2Fsafe-jsx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GSTJ%2Fsafe-jsx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GSTJ%2Fsafe-jsx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GSTJ%2Fsafe-jsx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GSTJ","download_url":"https://codeload.github.com/GSTJ/safe-jsx/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246628338,"owners_count":20808106,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["boolean","conversion","eslint","eslint-plugin","javascript","jsx","linting","quality","react","react-native","safe-settings"],"created_at":"2025-04-01T10:52:59.470Z","updated_at":"2025-04-01T10:53:00.198Z","avatar_url":"https://github.com/GSTJ.png","language":"TypeScript","funding_links":["https://github.com/sponsors/gstj"],"categories":[],"sub_categories":[],"readme":"# 🛡️ eslint-plugin-safe-jsx\n\n`eslint-plugin-safe-jsx` is an ESLint plugin that enforces explicit boolean conversion before using the \u0026\u0026 operator with JSX in React and React Native applications. This plugin improves the reliability of your code by helping prevent certain types of bugs that can break your app.\n\n## 💡 Why Use eslint-plugin-safe-jsx?\n\nIn JavaScript, certain \"falsy\" values such as `0`, `''`, and `null` can lead to unexpected behavior when used in a logical expression. This can be particularly problematic in React JSX code, where you might be expecting a boolean value.\n\nConsider the following example:\n\n```jsx\nconst myText = 0;\nmyText \u0026\u0026 \u003cText\u003e{myText}\u003c/Text\u003e;\n```\n\nIn this scenario, the code tries to render `0` outside the Text component, leading to a failure. The issue is even more critical when the variable value comes from a server or an external source. This ESLint rule helps prevent such scenarios from occurring.\n\nWith `eslint-plugin-safe-jsx`, ESLint will alert you to these potential errors and can even auto-fix them, like so:\n\n```jsx\nconst myText = 0;\nBoolean(myText) \u0026\u0026 \u003cText\u003e{myText}\u003c/Text\u003e;\n```\n\nNow, `myText` is explicitly converted to a boolean before being used in the logical expression, preventing the `0` from being rendered.\n\nFor more examples, check out our [test cases](./src/rules/jsx-explicit-boolean.test.tsx).\n\n## 🚀 Installation\n\nYou'll first need to install [ESLint](https://eslint.org/docs/latest/user-guide/getting-started):\n\n```sh\n# npm\nnpm install eslint --save-dev\n\n# yarn\nyarn add eslint --dev\n```\n\nNext, install `eslint-plugin-safe-jsx`:\n\n```sh\n# npm\nnpm install eslint-plugin-safe-jsx --save-dev\n\n# yarn\nyarn add eslint-plugin-safe-jsx --dev\n```\n\n**Note:** If you installed ESLint globally (using the `-g` flag in npm, or the `global` prefix in yarn) then you must also install `eslint-plugin-safe-jsx` globally.\n\n## ⚙️ Usage\n\nAdd `safe-jsx` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:\n\n```json\n{\n  \"plugins\": [\"safe-jsx\"]\n}\n```\n\nThen configure the rules you want to use under the rules section.\n\n```json\n{\n  \"rules\": {\n    \"safe-jsx/jsx-explicit-boolean\": \"error\" // or \"warn\"\n  }\n}\n```\n\n## 📚 Supported Rules\n\n- `jsx-explicit-boolean`: Enforces explicit boolean conversion before using the \u0026\u0026 operator with JSX.\n\n## 🤝 Contributing\n\nWe welcome your contributions! For major changes, please open an issue first to discuss what you would like to change. Don't forget to update tests as appropriate.\n\n## 📃 License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgstj%2Fsafe-jsx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgstj%2Fsafe-jsx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgstj%2Fsafe-jsx/lists"}