New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds jsx-no-ampersands #1
Conversation
Adds minimal setup for custom eslint rule. - Introduces a lint rule `jsx-no-ampersands` copied from on `jsx-embed-condition`: https://github.com/yannickcr/eslint-plugin-react/blob/ee232bbaef4fb04740413d5048877559abf06222/lib/rules/jsx-embed-condition.js - TODO: add tests for `jsx-no-ampersands` - To use this rule, add the following to `.eslintrc`: ```json { "plugins": [ "grailed" ], "rules": { "grailed/jsx-no-ampersands": "warn" } } ``` Co-authored-by: Bean <10777333+GeneTheBean@users.noreply.github.com>
280fc7f
to
a07ad38
Compare
/** | ||
* @fileoverview Prevents usage of && condition in JSX Embeds. | ||
* @author Anees Iqbal <i@steelbrain.me> | ||
* @see: https://github.com/yannickcr/eslint-plugin-react/blob/ee232bbaef4fb04740413d5048877559abf06222/lib/rules/jsx-embed-condition.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OOO cool, it looks like adding jsx-embed-condition to eslint-plugin-react
is a draft pull request, so we're making it happen earlier than they add it? Is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the discussion being had on their PR it doesn't seem like they are moving forward with it, so we're adding it ourselves for or own use case
I tried to test this through |
You have to clone this repo in another directory, and then from your grailed project you npm install referencing that directory |
Ah ofc ty! I'll do that in a bit :) |
This rule disallows use of && inside JSX Embeds to avoid conditional numbers from being rendered. | ||
|
||
## Why? | ||
Here is an [acrticle](https://kentcdodds.com/blog/use-ternaries-rather-than-and-and-in-jsx) explaining the problems that can happen when you use && to conditionally render content in JSX. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo!
Purpose
Adds lint rule check
JSXExpressionContainer
for ampersands and report a message.Testing locally
or add the following to your
package.json
and runnpm install
.eslintrc
Links
Demo
https://www.loom.com/share/66e0fa36825249df96be81f90ac734bb
NOTE In the demo we install our package locally, but when we decide to use this in our production code base we will reference the package to our Github repo directly.