-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix: Allow multipart jsx node names, data-qa on new line for multiline jsx open tags. #2
fix: Allow multipart jsx node names, data-qa on new line for multiline jsx open tags. #2
Conversation
lib/rules/onClick.js
Outdated
|
||
const attributePrefix = isSingleLine | ||
? '' | ||
: new Array(node.loc.start.column + 2).fill(' ').join(''); |
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.
reading your description and realizing this 2 is a hardcoded soft tab indent. do we have visibility into the next line's indent? might be nice if we indented based on the existing indent convention if it's easy
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.
I could probably do that.
The other devil's advocate point (against me) is that the attribute indentation / newlining should be handled by a separate lint rule, in which case the test-selectors plugin should just butt out.
Honestly, that's probably the cleaner approach.
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.
If I routinely ran prettier after linting, this wouldn't have been an issue. 🤦
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.
I ultimately like the idea of adding the fix in the "right place" (e.g. next line, indented)- I know at least in our world, auto-formats are a separate, distinct step from ESLint corrections, so if it "just worked", that'd feel pretty slick. but I think it'd potentially be worse to indent wrong than to not try to indent at all
Because indentation mattered, I thought this gave better visibility into the relative indentation levels than doing
|
5f9ea9c
to
dfb5855
Compare
@dkordik I removed the multi-line special case. Consumers are expected to provide their own linting / prettier config so they're in full control of indentation and when to break lines. |
lgtm! fyi, we have an active PR from our |
dfb5855
to
7a64517
Compare
Before this commit, node names with dots in them caused an error in the rule.
A file containing the following was not lintable, and projects that relied on successful linting to build, commit, etc. would fail.
In this change, I'm switching to using
node.name.range
to get the position for inserting the attribute. That method works for both single and multi-identifier jsx elements.Also, as a convenience, I'm detecting if a jsx element is on 2 lines, and, if so, adding a newline and indentation. The indentation is simplistic: the same column as the tag opener plus 2 spaces.
Finally, when running
npm run lint
on the repo before committing, there were some lint errors around indentation for this project and preferring template strings over concatenating strings with+
, so I fixed those.