{"id":13635869,"url":"https://github.com/palantir/tslint-react","last_synced_at":"2025-05-16T13:04:37.412Z","repository":{"id":38455541,"uuid":"61270075","full_name":"palantir/tslint-react","owner":"palantir","description":":orange_book: Lint rules related to React \u0026 JSX for TSLint.","archived":false,"fork":false,"pushed_at":"2023-03-13T13:35:48.000Z","size":222,"stargazers_count":749,"open_issues_count":1,"forks_count":76,"subscribers_count":283,"default_branch":"master","last_synced_at":"2025-05-07T07:39:39.846Z","etag":null,"topics":["jsx","linting-rules","octo-correct-managed","react","tslint","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/palantir.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-16T07:05:25.000Z","updated_at":"2025-05-04T13:23:11.000Z","dependencies_parsed_at":"2024-06-18T11:28:57.008Z","dependency_job_id":null,"html_url":"https://github.com/palantir/tslint-react","commit_stats":{"total_commits":154,"total_committers":40,"mean_commits":3.85,"dds":"0.48051948051948057","last_synced_commit":"b92fb075375394f84594853b928e670d729a1ed8"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palantir%2Ftslint-react","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palantir%2Ftslint-react/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palantir%2Ftslint-react/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palantir%2Ftslint-react/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/palantir","download_url":"https://codeload.github.com/palantir/tslint-react/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253059360,"owners_count":21847273,"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":["jsx","linting-rules","octo-correct-managed","react","tslint","typescript"],"created_at":"2024-08-02T00:00:53.462Z","updated_at":"2025-05-16T13:04:37.389Z","avatar_url":"https://github.com/palantir.png","language":"TypeScript","readme":"[![NPM version](https://badge.fury.io/js/tslint-react.svg)](https://www.npmjs.com/package/tslint-react)\n[![Downloads](http://img.shields.io/npm/dm/tslint-react.svg)](https://npmjs.org/package/tslint-react)\n[![Circle CI](https://circleci.com/gh/palantir/tslint-react.svg?style=svg)](https://circleci.com/gh/palantir/tslint-react)\n\ntslint-react\n------------\n\nLint rules related to React \u0026 JSX for [TSLint](https://github.com/palantir/tslint/).\n\n### Usage\n\ntslint-react has peer dependencies on TSLint and TypeScript.\n\nTo use these lint rules with the default preset, use configuration inheritance via the `extends` keyword.\nHere's a sample configuration where `tslint.json` lives adjacent to your `node_modules` folder:\n\n```js\n{\n  \"extends\": [\"tslint:latest\", \"tslint-react\"],\n  \"rules\": {\n    // override tslint-react rules here\n    \"jsx-wrap-multiline\": false\n  }\n}\n```\n\nTo lint your `.ts` **and** `.tsx` files you can simply run `tslint -c tslint.json 'src/**/*.{ts,tsx}'`.\n\n### Semantic versioning\n\nThe built-in configuration preset you get with `\"extends\": \"tslint-react\"` is semantically versioned in a manner similar to TSLint's built-in presets and the TypeScript language itself. As new rules are added to tslint-react across minor versions, stricter checks may be enabled here. Your code is not guaranteed to continue passing checks across these version bumps. If you wish to ensure that `npm upgrade` or `yarn upgrade` never breaks your build, declare a tilde dependency on this package (e.g. `\"~1.0.0\"`).\n\n### Rules\n\n- `jsx-alignment`\n  - Enforces a consistent style for multiline JSX elements which promotes ease of editing via line-wise manipulations\n  as well as maintainability via small diffs when changes are made.\n  ```ts\n  // Good:\n  const element = \u003cdiv\n      className=\"foo\"\n      tabIndex={1}\n  \u003e\n      {children}\n  \u003c/div\u003e;\n\n  // Also Good:\n  \u003cButton\n      appearance=\"pretty\"\n      disabled\n      label=\"Click Me\"\n      size={size}\n  /\u003e\n  ```\n- `jsx-ban-elements` (since v3.4.0)\n  - Allows blacklisting of JSX elements with an optional explanatory message in the reported failure.\n- `jsx-ban-props` (since v2.3.0)\n  - Allows blacklisting of props in JSX with an optional explanatory message in the reported failure.\n- `jsx-boolean-value` (since v2.5.0)\n  - When using a boolean attribute in JSX, you can set the attribute value to true or omit the value. This rule will enforce one or the other to keep consistency in your code.\n  - Rule options: `[\"always\", \"never\"]`\n  - Default is set to `always`.\n- `jsx-curly-spacing` (since v1.1.0)\n  - Requires _or_ bans spaces between curly brace characters in JSX.\n  - Rule options: `[\"always\", \"never\"]`\n  - _Includes automatic code fix_\n- `jsx-equals-spacing` (since v3.2.0)\n  - Requires _or_ bans spaces before and after the `=` token in JSX element attributes.\n  - Rule options: `[\"always\", \"never\"]`\n  - _Includes automatic code fix_\n- `jsx-key` (since v3.2.0)\n  - Warns for missing `key` props in JSX element array literals and inside return statements of `Array.prototype.map` callbacks.\n    - N.B. This rule only does a simple check for `.map(...)` syntax and does not inspect computed types of expressions. As such, it may produce false positives if you use APIs that look similar to `.map()`.\n  - Rule options: _none_\n- `jsx-no-bind` (since v2.6.0)\n  - Forbids function binding in JSX attributes. This has the same intent as `jsx-no-lambda` in helping you avoid excessive re-renders.\n  - Note that this currently only does a simple _syntactic_ check, not a _semantic_ one (it doesn't use the type checker). So it may have some\n    rare false positives if you define your own `.bind` function and supply `this` as a parameter.\n  - Rule options: _none_\n- `jsx-no-lambda`\n  - Creating new anonymous functions (with either the `function` syntax or ES2015 arrow syntax) inside the `render` call stack works against _pure component rendering_. When doing an equality check between two lambdas, React will always consider them unequal values and force the component to re-render more often than necessary.\n  - Rule options: _none_\n- `jsx-no-multiline-js`\n  - Disallows multiline JS expressions inside JSX blocks to promote readability\n  - Rule options: _none_\n- `jsx-no-string-ref`\n  - Passing strings to the `ref` prop of React elements is considered a legacy feature and will soon be deprecated.\n    Instead, [use a callback](https://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute).\n  - Rule options: _none_\n- `jsx-use-translation-function` (since v2.4.0)\n   - Enforces use of a translation function. Plain string literals are disallowed in JSX when enabled.\n   - Rule options: `[\"allow-punctuation\", \"allow-htmlentities\"]`\n   - Off by default\n- `jsx-self-close` (since v0.4.0)\n  - Enforces that JSX elements with no children are self-closing.\n  - _Includes automatic code fix_\n  ```ts\n  // bad\n  \u003cdiv className=\"foo\"\u003e\u003c/div\u003e\n  // good\n  \u003cdiv className=\"foo\" /\u003e\n  ```\n  - Rule options: _none_\n- `jsx-space-before-trailing-slash`\n  - Checks that self-closing JSX elements have a space before the '/\u003e' part.\n  - Rule options: _none_\n  - _Includes automatic code fix_\n- `jsx-wrap-multiline` (since v2.1)\n  - Enforces that multiline JSX expressions are wrapped with parentheses.\n  - Opening parenthesis must be followed by a newline.\n  - Closing parenthesis must be preceded by a newline.\n  ```ts\n  // bad\n  const button = \u003cbutton type=\"submit\"\u003e\n      Submit\n  \u003c/button\u003e;\n  // good\n  const button = (\n      \u003cbutton type=\"submit\"\u003e\n          Submit\n      \u003c/button\u003e\n  );\n  ```\n\n### Development\n\nWe track rule suggestions on Github issues -- [here's a useful link](https://github.com/palantir/tslint-react/issues?q=is%3Aissue+is%3Aopen+label%3A%22Type%3A+Rule+Suggestion%22)\nto view all the current suggestions. Tickets are roughly triaged by priority (P1, P2, P3).\n\nWe're happy to accept PRs for new rules, especially those marked as [Status: Accepting PRs](https://github.com/palantir/tslint-react/issues?q=is%3Aissue+is%3Aopen+label%3A%22Status%3A+Accepting+PRs%22).\nIf submitting a PR, try to follow the same style conventions as the [core TSLint project](https://github.com/palantir/tslint).\n\nQuick Start (requires Node v6+, yarn v0.22+):\n\n1. `yarn`\n1. `yarn verify`\n1. `yarn lint`\n\n### Changelog\n\nSee the Github [release history](https://github.com/palantir/tslint-react/releases).\n","funding_links":[],"categories":["Please find below the links to awesome cheat-sheet and resources:","TypeScript"],"sub_categories":["React/React-Native:"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalantir%2Ftslint-react","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpalantir%2Ftslint-react","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalantir%2Ftslint-react/lists"}