This repository contains my custom eslint rules
Installations
npm install @hesamse/eslint-plugin-recommended
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
18.20.4
NPM Version
10.7.0
Score
67
Supply Chain
98.6
Quality
76.9
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (72.27%)
JavaScript (27.73%)
Developer
HesamSe
Download Statistics
Total Downloads
789
Last Day
6
Last Week
70
Last Month
587
Last Year
789
GitHub Statistics
1 Stars
9 Commits
1 Watching
1 Branches
1 Contributors
Package Meta Information
Latest Version
1.0.1
Package Id
@hesamse/eslint-plugin-recommended@1.0.1
Unpacked Size
4.85 kB
Size
2.16 kB
File Count
6
NPM Version
10.7.0
Node Version
18.20.4
Publised On
25 Oct 2024
Total Downloads
Cumulative downloads
Total Downloads
789
Last day
-14.3%
6
Compared to previous day
Last week
-26.3%
70
Compared to previous week
Last month
328.5%
587
Compared to previous month
Last year
0%
789
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
@hesamse/eslint-plugin-recommended
An ESLint plugin with custom rules for TypeScript projects, including a rule to enforce the presence of JSX elements in .tsx
files. Ideal for projects using React with TypeScript.
Features
no-tsx-without-jsx
: Enforces that.tsx
files contain JSX elements. If a.tsx
file does not include any JSX, this rule will report an error, encouraging you to use the correct file extensions (.ts
instead of.tsx
when JSX is not used).
Installation
First, install the plugin using npm:
1npm install --save-dev @hesamse/eslint-plugin-recommended
Or with yarn:
1yarn add --dev @hesamse/eslint-plugin-recommended
Usage
To use this plugin, include it in your ESLint configuration:
eslint.config.js
If you are using eslint.config.js
:
1import hesamseRecommended from '@hesamse/eslint-plugin-recommended'; 2 3export default { 4 parser: '@typescript-eslint/parser', 5 plugins: { 6 '@hesamse/recommended': hesamseRecommended, 7 }, 8 rules: { 9 '@hesamse/recommended/no-tsx-without-jsx': 'error', 10 }, 11 overrides: [ 12 { 13 files: ['**/*.tsx'], 14 rules: { 15 '@hesamse/recommended/no-tsx-without-jsx': 'error', 16 }, 17 }, 18 ], 19};
.eslintrc.json
(if you still prefer JSON configuration)
1{ 2 "parser": "@typescript-eslint/parser", 3 "plugins": ["@hesamse/recommended"], 4 "rules": { 5 "@hesamse/recommended/no-tsx-without-jsx": "error" 6 }, 7 "overrides": [ 8 { 9 "files": ["**/*.tsx"], 10 "rules": { 11 "@hesamse/recommended/no-tsx-without-jsx": "error" 12 } 13 } 14 ] 15}
Rule: no-tsx-without-jsx
What does it do?
The no-tsx-without-jsx
rule ensures that files with a .tsx
extension contain at least one JSX element. This helps maintain consistency in your project by enforcing the use of .tsx
files only when necessary. If no JSX is present, consider renaming the file to .ts
.
Example
✅ Valid
1// myComponent.tsx 2import React from 'react'; 3 4const MyComponent = () => <div>Hello, World!</div>; 5 6export default MyComponent;
❌ Invalid
1// myUtility.tsx 2export function myUtilityFunction() { 3 return 42; 4}
The above code would trigger an error, suggesting that the file should be renamed to .ts
since no JSX is present.
Contributing
Contributions are welcome! If you want to add new rules or improve existing ones, feel free to fork the repository and open a pull request.
License
MIT © hesamSe
No vulnerabilities found.
No security vulnerabilities found.