fix(consistent-data-testid): avoid crash for filename with square brackets #643
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checks
npm run generate:rules-list
)npm run generate:configs
)Changes
In the discussion of the issue #509 there hasn't been a consensus how to fix the issue, and this is my suggestion.
It seems that the crash in 509 is caused by several repos using static site generators and their dynamic routing.
gatsbyjs/gatsby
uses Gatsby.jsvickev/howdypix
uses Next.jsBoth Gatsby.js and Next.js support square brackets and three periods in filename. However, since the three periods is optional, it makes sense to catch this edge case by looking only at the presence of square brackets.
This PR:
consistent-data-testid
rule replace{fileName}
placeholder with an empty string if the filename gotten from path contains square bracketsContext
Closes #509.
Comments and thoughts about this PR are welcome.