-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Syntax highlighting doesn't work well on files with .tsx
extension
#7039
Comments
This will be because the linguist/lib/linguist/heuristics.yml Lines 781 to 786 in f0aebbe
If the file doesn't match that or the XML heuristic, things fall through to the classifier which uses the samples we have to guess and all but one of the samples have React in them. There are two solutions:
The former is more reliable but likely to be harder. If you know of a reliable regex that can be used, please feel free to submit a PR to improve the heuristic. |
@lildude Oh, I see! I understand that this requires importing React for proper detection. However, I have two questions:
On the other hand, I wonder what makes this file have proper syntax highlighting without importing React. However, if I remove most of the HTML or the class names, it turns into a plain text file. The file extension is The same thing happens with this other |
If the file contains XML 😉 From the comments in #2761 and #3464 these appear to be tileset map files.
It won't make a difference as both heuristics are quite precise with neither being a fallback "default" option. The reason we're getting the misclassification is the files aren't matching either regex so it's falling through to the classifier.
I can't determine the source of your files so I can't test it and be precise, but I suspect the content contains tags in common with those in the samples which are used to train the classifier and the classifier has got it right this time. |
Could we make it assume that it is a .tsx file if it doesn't match any heuristics, perhaps using a
If it is of any use, I leave below the complete code that the classifier does classify correctly without the need to use a React import. Exampleimport Image from 'next/image'
import styles from './page.module.css'
export default function Home() {
return (
<main className={styles.main}>
<div className={styles.description}>
<p>
Get started by editing
<code className={styles.code}>src/app/page.tsx</code>
</p>
<div>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
By{' '}
<Image
src="/vercel.svg"
alt="Vercel Logo"
className={styles.vercelLogo}
width={100}
height={24}
priority
/>
</a>
</div>
</div>
<div className={styles.center}>
<Image
className={styles.logo}
src="/next.svg"
alt="Next.js Logo"
width={180}
height={37}
priority
/>
</div>
<div className={styles.grid}>
<a
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className={styles.card}
target="_blank"
rel="noopener noreferrer"
>
<h2>
Docs <span>-></span>
</h2>
<p>Find in-depth information about Next.js features and API.</p>
</a>
<a
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className={styles.card}
target="_blank"
rel="noopener noreferrer"
>
<h2>
Learn <span>-></span>
</h2>
<p>Learn about Next.js in an interactive course with quizzes!</p>
</a>
<a
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className={styles.card}
target="_blank"
rel="noopener noreferrer"
>
<h2>
Templates <span>-></span>
</h2>
<p>Explore starter templates for Next.js.</p>
</a>
<a
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className={styles.card}
target="_blank"
rel="noopener noreferrer"
>
<h2>
Deploy <span>-></span>
</h2>
<p>
Instantly deploy your Next.js site to a shareable URL with Vercel.
</p>
</a>
</div>
</main>
)
} For now what I did to avoid the syntax problem was to make an overrides using the # Reclassifying `.tsx` files as `tsx` to fix GitHub syntax highlighting issues.
# Current Linguist heuristics do not correctly recognize `.tsx` files without `import React`.
# https://github.com/github-linguist/linguist/issues/7039
*.tsx linguist-language=tsx |
It already is a
No. |
Describe the bug
When opening a pull request or when the code is merged into the main branch, the syntax highlighting for
.tsx
TypeScript React files doesn't work properly, leaving part of the file in plain text.Expected behaviour
The expected behavior should be to always display the syntax highlighting that corresponds to the
.tsx
extension.Additional notes
As additional information, I have managed to correct this by importing React at the beginning of each file.
But this should not be necessary today, since it is not an obligation to have to import React.
The text was updated successfully, but these errors were encountered: