Skip to content

zanminkian/fenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Fenge(้ฃŽๆ ผ)

A CLI tool for JavaScript and TypeScript code quality.

๐Ÿ˜Ž = ๐Ÿ‡น + ๐Ÿ’ƒ + ๐Ÿ“

PRs Welcome


Philosophy

็ฎ€ไฝ“ไธญๆ–‡

ๆ ธๅฟƒ๏ผš็ฑปๅž‹ๅฎ‰ๅ…จใ€Formatting ๅ’Œ Linting

็ป่ฟ‡ๅคšๅนดๅฎž่ทต๏ผŒๆˆ‘ไปฌๅ‘็Žฐ๏ผŒๆœ€ๅฝฑๅ“็Žฐไปฃ JavaScript ๅทฅ็จ‹็š„ไปฃ็ ่ดจ้‡ๅ’Œๅผ€ๅ‘ไฝ“้ชŒ็š„ไธป่ฆๆœ‰ 3 ไธชๆ–น้ข๏ผš

  • ็ฑปๅž‹ๅฎ‰ๅ…จ๏ผš็”จไบŽๆๅ‰ๅ‘็Žฐ็ฑปๅž‹ใ€ๆ‹ผๅ†™้”™่ฏฏ๏ผŒไพ‹ๅฆ‚ๅฏน่ฑกๆ–นๆณ•ๆ˜ฏๅฆๆญฃ็กฎ่ฐƒ็”จใ€ๅ‡ฝๆ•ฐๅ‚ๆ•ฐไผ ้€’็š„็ฑปๅž‹ๆ˜ฏๅฆ็ฌฆๅˆๅ‡ฝๆ•ฐไฝ“็š„ๆœŸๆœ›็ญ‰ใ€‚
  • Formatting๏ผš็”จไบŽ็ปŸไธ€ๆ ผๅผ๏ผŒๆๅ‡ไปฃ็ ๅฏ่ฏปๆ€ง๏ผŒๅ‡ๅฐ‘ไปฃ็ ๅ†ฒ็ชใ€‚ไธป่ฆๅ…ณๆณจไพ‹ๅฆ‚็ผฉ่ฟ›ใ€ๆข่กŒใ€ๅ•/ๅŒๅผ•ๅทใ€ๅธฆ/ไธๅธฆๅˆ†ๅท็ญ‰้—ฎ้ข˜ใ€‚
  • Linting๏ผš็”จไบŽๆๅ‰ๅ‘็Žฐ้€ป่พ‘ๆผๆดžๅ’Œ็ณŸ็ฒ•็”จๆณ•๏ผŒๅ‡ๅฐ‘ Bug๏ผŒ้™ไฝŽ็ปดๆŠคๆˆๆœฌใ€‚ๅ…ถๅ…ณๆณจ็‚นๅฏไปฅๆ˜ฏ้™คไบ† Formatting ไน‹ๅค–็š„ไปปไฝ•ๅœฐๆ–น๏ผŒไพ‹ๅฆ‚้‡ๅคๅฎšไน‰ๅ˜้‡ใ€switch ไธๅธฆ breakใ€ๅœˆๅคๆ‚ๅบฆ็ญ‰ใ€‚

่ฟ™ 3 ไธชๆ–น้ขไนŸๆ˜ฏๆ›ดๅ…ˆ่ฟ›็š„่ฟ่กŒๆ—ถ Deno ๆ‰€ๅ†…็ฝฎ็š„ๅŠŸ่ƒฝ๏ผŒNode ๅนถๆฒกๆœ‰ๅ†…็ฝฎๆ”ฏๆŒ๏ผŒๅ–่€Œไปฃไน‹็š„ๆ˜ฏ็คพๅŒบ้‡Œ็™พ่Šฑ้ฝๆ”พ็š„ๅทฅๅ…ท๏ผšTypeScriptใ€Flowใ€Biomeใ€ESLintใ€oxc-lintใ€Prettierใ€dprintใ€‚่ฟ™ไบ›ๅทฅๅ…ท็”จๅœจ Node ้กน็›ฎไธญๅญ˜ๅœจ 3 ไธช้žๅธธๅฝฑๅ“ๅผ€ๅ‘ไฝ“้ชŒ็š„้—ฎ้ข˜๏ผš

  • ๅทฅๅ…ท้€‰ๅž‹้—ฎ้ข˜๏ผšๆˆ‘ๅบ”่ฏฅ้€‰ๆ‹ฉๅ“ชไบ›ๅทฅๅ…ท้›†ๅˆๆฅไผ˜ๅŒ–ไธŠ่ฟฐ 3 ไธช้—ฎ้ข˜๏ผŸ้€‰ๆ‹ฉๅŽ๏ผŒไธ‹ไธ€ไธช Node ้กน็›ฎๅˆ้€‰ๆ‹ฉไธๅŒๅทฅๅ…ท้›†ๆ€ŽไนˆๅŠž๏ผŸ
  • ๅทฅๅ…ทไน‹้—ดๅ†ฒ็ช็ฃจๅˆ้—ฎ้ข˜๏ผš็กฎๅฎšไฝฟ็”จ็š„ๅทฅๅ…ทๅŽ๏ผŒ่ฟ™ไบ›ๅทฅๅ…ทไน‹้—ดๆ˜ฏๅฆๆœ‰ๅ†ฒ็ช๏ผŸไปฃ็ ๆไบคๆ—ถๆ˜ฏๅ…ˆ format ่ฟ˜ๆ˜ฏๅ…ˆ lint๏ผŸๅทฅๅ…ทไน‹้—ด้…ๅˆ็š„ๆœ€ไฝณๅฎž่ทตๆ˜ฏไป€ไนˆ๏ผŸ
  • ๅทฅๅ…ทไปฌ็š„ๅคๆ‚้…็ฝฎ้—ฎ้ข˜๏ผšๆฏไธชๅทฅๅ…ท้ƒฝๆœ‰ๅพˆๅคๆ‚้šพๆ‡‚็š„้…็ฝฎ๏ผŒๅœจ้กน็›ฎๆ น็›ฎๅฝ•๏ผˆๆˆ– package.json ้‡Œ๏ผ‰ๅˆฐๅค„ๆ‹‰ๅฑŽใ€‚ไธ€ๆฅไธ็พŽ่ง‚็ฎ€ๆด๏ผŒไบŒๆฅๅขžๅŠ ็†่งฃๆˆๆœฌใ€‚ๆฏไธช Node ้กน็›ฎๅฏ่ƒฝๅทฅๅ…ท็ปŸไธ€ไฝ†้…็ฝฎไธ็ปŸไธ€๏ผŒ่ฟ›ไธ€ๆญฅๅฏผ่‡ดๅผ€ๅ‘ไฝ“้ชŒไธไธ€่‡ดใ€‚

ไธบไบ†่งฃๅ†ณไธŠ่ฟฐ้—ฎ้ข˜๏ผŒ็Žฐๅœจๆœ‰้žๅธธๅคšๆ•™็จ‹ๆ–‡็ซ ่ฎฒ่งฃ TypeScript + Prettier + ESLint ็š„้…็ฝฎๅ’Œๅฎž่ทต๏ผŒ่ฟ™ไบ›ๆ–‡็ซ ๆ•™็จ‹่ƒฝ็ผ“่งฃไธ€้ƒจๅˆ†้—ฎ้ข˜๏ผŒไฝ†ไป็„ถๅฐ†ๆ‚ไนฑ็š„ๅทฅๅ…ท้“พๅ’Œ็น็็š„้…็ฝฎๆšด้œฒ็ป™็”จๆˆทใ€‚่ฟ™ไธๆ˜ฏๆˆ‘ไปฌ็š„็›ฎๆ ‡๏ผŒๆˆ‘ไปฌ็š„็›ฎๆ ‡ๆ˜ฏๆไพ›ไธ€ไธช็ปŸไธ€็š„ๅทฅๅ…ทๅฑ่”ฝ่ฟ™ไบ›ๅคๆ‚็š„ๅฎž่ทต็ป†่Š‚๏ผŒ็ป™็”จๆˆทๅธฆๆฅ็ฎ€ๅ•ไธ€่‡ดใ€ๅผ€็ฎฑๅณ็”จ็š„่‰ฏๅฅฝๅผ€ๅ‘ไฝ“้ชŒใ€‚

็ฑปๅž‹ๅฎ‰ๅ…จใ€Formatting ๅ’Œ Linting ็š„ๅ…ณ็ณป

ไธบไบ†้˜่ฟฐไธ‰่€…ไน‹้—ด็š„ๅ…ณ็ณป๏ผŒ่ฟ™้‡Œไปฅไธ‰่€…ๆœ€ๅ…ทไปฃ่กจๆ€ง็š„่งฃๅ†ณๆ–นๆกˆ TypeScriptใ€Prettier ๅ’Œ ESLint ไฝœไธบไพ‹ๅญใ€‚

- ็ฑปๅž‹ๅฎ‰ๅ…จ Formatting Linting
ไปฃ่กจ TypeScript Prettier ESLint
ๅ…ณๆณจ้€ป่พ‘ โœ… โŒ โœ…
Auto Fixing โŒ โœ… โœ…

็ป่ฟ‡ๅคšๅนดๆผ”่ฟ›๏ผŒไธ‰่€…ๅ…ณๆณจ็‚นๅญ˜ๅœจไธ€ๅฎš็š„ไบค้›†๏ผš

  1. ็ฑปๅž‹ๅฎ‰ๅ…จๅ’Œ Linting ๅ…ณๆณจ็‚น็š„ไบค้›†๏ผšไพ‹ๅฆ‚๏ผŒโ€œๅ‡ฝๆ•ฐๅ…ฅๅ‚ๆ•ฐ้‡ๅฏนไธไธŠโ€๏ผŒๆ—ขๅฏ่ƒฝ่ขซ TypeScript ๆฃ€ๆต‹ๅˆฐ๏ผŒไนŸๅฏ่ƒฝ่ขซ ESLintๆฃ€ๆต‹ๅ‡บๆฅใ€‚
  2. Formatting ๅ’Œ Linting ๅ…ณๆณจ็‚น็š„ไบค้›†๏ผšไพ‹ๅฆ‚๏ผŒโ€œๆ˜ฏๅฆไฝฟ็”จๅˆ†ๅท็ป“ๅฐพโ€ใ€โ€œไฝฟ็”จๅ•ๅผ•ๅท่ฟ˜ๆ˜ฏๅŒๅผ•ๅทโ€็ญ‰๏ผŒๆ—ขๅฏไปฅ่ขซ Prettier ๆฃ€ๆต‹ๅ‡บๆฅๅนถๆ‰ง่กŒๆ ผๅผๅŒ–๏ผŒไนŸๅฏไปฅ่ขซ ESLint ๆฃ€ๆต‹ๅ‡บๆฅๅนถๆ‰ง่กŒไฟฎๅคใ€‚

่™ฝ็„ถๅฝ“ไธ‹ๆƒ…ๅ†ตๆ˜ฏไธ‰่€…ๅญ˜ๅœจไธ€ๅฎš็š„ไบค้›†๏ผŒไฝ†่ฟ™ไธๆ˜ฏๆœ€็†ๆƒณ็š„ๆƒ…ๅ†ต๏ผŒๆœ€็†ๆƒณ็š„ๆƒ…ๅ†ตๆ˜ฏ๏ผš็ฑปๅž‹ๅฎ‰ๅ…จใ€Formatting ๅ’Œ Linting ๅ…ณๆณจไธๅŒ็š„้ข†ๅŸŸ๏ผŒไธๅญ˜ๅœจไบค้›†ใ€‚

ไธบไป€ไนˆๆŠŠ Formatting ๅ’Œ Linting ๅˆ†ๅผ€

่™ฝ็„ถ็ฑปๅž‹ๅฎ‰ๅ…จไนŸๅฏ่ƒฝๅ’Œ Linting ็š„ๅ…ณๆณจ็‚น้‡ๅˆ๏ผŒไฝ†ๆ˜ฏ็คพๅŒบไธปๆตๅšๆณ•ไนŸไธไผšๅฐ† TypeScript ๅ’Œ ESLint ๆททไธบไธ€่ฐˆ๏ผŒๆ‰€ไปฅ่ฟ™้‡Œไธ่ฟ‡ๅคš่ต˜่ฟฐใ€‚็„ถ่€Œ๏ผŒ็คพๅŒบๅ†…ไธๅฐ‘ไบบๅฐ† Formatting ๅ’Œ Linting ๅˆๅนถ่ตทๆฅไธ€ๅนถๅค„็†๏ผŒไพ‹ๅฆ‚ @antfu/eslint-configใ€‚ๆˆ‘ไปฌๅผบ็ƒˆไธๅปบ่ฎฎ่ฟ™ๆ ทๅš๏ผŒไธป่ฆๆœ‰ไปฅไธ‹ๅŽŸๅ› ๏ผš

  1. ้ฆ–ๅ…ˆๆ˜ฏๅ› ไธบๅฎƒไปฌ็›ฎ็š„ไธไธ€ๆ ท๏ผŒไธ“ไธš็š„ไบ‹ๆƒ…ๅบ”่ฏฅไบค็ป™ไธ“ไธš็š„ๅทฅๅ…ทใ€‚
  2. Formatting ๅ’Œ Linting ๅฎƒไปฌ้€ ๆˆ็š„ๅฟƒๆ™บ่ดŸๆ‹…ไธๅŒ๏ผŒReview ไปฃ็ ๆ—ถ๏ผŒๆˆ‘ไปฌๅพ€ๅพ€ไธ้œ€่ฆๅ…ณๆณจ Formatting ็š„ๆ”นๅŠจ๏ผŒไฝ†ๆ˜ฏๆˆ‘ไปฌๅฟ…้กป่ฆไป”็ป†ๆฃ€ๆŸฅ็กฎ่ฎค Linting ็š„ๆ”นๅŠจ๏ผŒๅ› ไธบ Formatting ็š„ๆ”นๅŠจไธ€่ˆฌๆ˜ฏๅฎ‰ๅ…จ็š„๏ผŒไฝ†ๆ˜ฏ Linting ็š„ๆ”นๅŠจๅฏ่ƒฝๅญ˜ๅœจ้”™่ฏฏ็š„ไฟฎๅคใ€‚
  3. ๅ› ไธบ Linting ็š„ๆ”นๅŠจๅฏ่ƒฝๅญ˜ๅœจ้”™่ฏฏ็š„ไฟฎๅค๏ผŒ้…ๅˆ Git Hooks ๆ—ถ๏ผŒๅฆ‚ๆžœ Linting ็š„ไฟฎๅคๅ’Œ Formatting ็š„ไฟฎๅคๆททๅˆๅœจไธ€่ตท๏ผŒไปฃ็ ๆไบคๆ—ถๅฎนๆ˜“่ฎฉ้”™่ฏฏ็š„ไฟฎๅค็›ดๆŽฅ่ฟ›ๅ…ฅ Git Commit๏ผŒๅฏผ่‡ด bug ๆ›ด้šพ่ขซๅ‘็Žฐใ€‚
  4. ็คพๅŒบไธปๆต่ถ‹ๅŠฟๆ˜ฏๅฐ† Formatter ๅ’Œ Linter ๅˆ†ๅผ€ใ€‚ไพ‹ๅฆ‚๏ผšๆ—ฉๆœŸ ESLint ไนŸ่ขซ็”จไบŽๆ ผๅผๅŒ–๏ผŒไฝ†ๆ˜ฏไปŽ v8.53.0 ๅผ€ๅง‹๏ผŒ ESLint ๅบŸๅผƒ Formatting Rulesใ€‚Deno ๅ’Œ Biome ไนŸๅ‡ๆŠŠ Linter ๅ’Œ Formatter ๅˆ†ๅผ€ใ€‚

ๅฐ็ป“

ๆ€ป่€Œ่จ€ไน‹๏ผŒ็ฑปๅž‹ๅฎ‰ๅ…จใ€Formatting ๅ’Œ Linting ๆ˜ฏๆœชๆฅ JavaScript ๅ’Œ TypeScript ไปฃ็ ็”Ÿๆ€็ป•ไธ่ฟ‡ๅŽป็š„ไธ‰ไธชๆ–น้ขใ€‚่ฟ™ไธ‰ๆฟๆ–งๅœจ Node ๅฎ˜ๆ–นๆไพ›่งฃๅ†ณๆ–นๆกˆไน‹ๅ‰๏ผŒ้ƒฝๆ˜ฏๅ‰ฒ่ฃ‚ใ€้šพ็”จใ€ๅฝฑๅ“ไปฃ็ ่ดจ้‡็š„ๆ–น้ขใ€‚ๆˆ‘ไปฌ็ญ‰ไธๆ€ฅ Node ๅฎ˜ๆ–นๆไพ›็›ธๅ…ณๆ–นๆกˆ๏ผŒๆ‰€ไปฅๅˆ›ๅปบไบ† Fenge๏ผŒๅฐฝๅฏ่ƒฝๅฑ่”ฝๅคๆ‚๏ผŒๆšด้œฒ็ฎ€ๅ•๏ผŒ่ฎฉๅผ€ๅ‘่€…ไธ“ๆณจไบŽไธšๅŠกไปฃ็ ใ€‚

English

Core: Type Safety, Formatting, and Linting

After years of practice, we have found that the three main aspects affecting modern JavaScript project code quality and development experience are:

  • Type Safety: Used to detect type and spelling errors in advance, such as whether object methods are called correctly, whether function parameters match the expected types within the function body, etc.
  • Formatting: Used to unify code style, improve readability, and reduce conflicts. It mainly focuses on issues like indentation, line breaks, single/double quotes, with/without semicolons, etc.
  • Linting: Used to identify logical flaws and poor practices early, reducing bugs and maintenance costs. Its focus can be anywhere except for Formatting, such as redefining variables, switch statements without break, cyclomatic complexity, etc.

These three aspects are also built-in features in more advanced runtimes like Deno, which Node does not natively support. Instead, the community offers a variety of tools: TypeScript, Flow, Biome, ESLint, oxc-lint, Prettier, dprint. Using these tools in Node projects brings three major issues impacting development experience:

  • Tool Selection Problem: Which set of tools should I choose to optimize the above three problems? If I choose different toolsets for the next Node project, how do I handle it?
  • Tool Conflict and Integration Problem: After determining the tools to use, do these tools conflict with each other? Should formatting or linting come first when committing code? What is the best practice for integrating these tools?
  • Complex Configuration Problem: Each tool has complex and difficult-to-understand configurations scattered across the project root directory (or package.json). This not only looks messy but also increases the learning curve. Even if the tools are consistent across Node projects, the configurations may vary, leading to inconsistent development experiences.

To address these issues, there are now many tutorials explaining the configuration and practices of TypeScript + Prettier + ESLint, which can alleviate some problems but still expose users to a cluttered toolchain and cumbersome configurations. Our goal is not this; our goal is to provide a unified tool that abstracts away these complex details, offering a simple, consistent, and ready-to-use development experience.

Relationship between Type Safety, Formatting, and Linting

To illustrate the relationship among these three, let's take the most representative solutions TypeScript, Prettier, and ESLint as examples.

- Type Safety Formatting Linting
Representative TypeScript Prettier ESLint
Focus on Logic โœ… โŒ โœ…
Auto Fixing โŒ โœ… โœ…

Over time, these three areas have developed certain intersections:

  1. Intersection between Type Safety and Linting: For example, "mismatched function parameter count" can be detected by both TypeScript and ESLint.
  2. Intersection between Formatting and Linting: For example, "whether to end with a semicolon" or "use single or double quotes" can be detected and fixed by both Prettier and ESLint.

Although there are overlaps among them today, the ideal situation is that Type Safety, Formatting, and Linting focus on different domains without overlap.

Why Separate Formatting from Linting

While Type Safety might also overlap with Linting, the community generally does not confuse TypeScript with ESLint, so this aspect is not elaborated here. However, many people in the community combine Formatting and Linting together, such as @antfu/eslint-config. We strongly do not recommend doing this for several reasons:

  1. They serve different purposes; specialized tasks should be handled by specialized tools.
  2. Formatting and Linting impose different cognitive loads. When reviewing code, we often don't need to pay attention to Formatting changes, but we must carefully check Linting changes because Formatting changes are generally safe, while Linting changes may contain incorrect fixes.
  3. Since Linting changes may contain incorrect fixes, when used with Git Hooks, mixing Linting and Formatting fixes can lead to erroneous fixes entering Git Commits directly, making bugs harder to detect.
  4. The community trend is to separate Formatters and Linters. For example, early versions of ESLint were also used for formatting, but starting from v8.53.0, ESLint deprecated Formatting Rules. Deno and Biome also separate Linter and Formatter.

Summary

In summary, Type Safety, Formatting, and Linting are three indispensable aspects of the future JavaScript and TypeScript code ecosystem. Before Node provides official solutions, these three areas have been fragmented, difficult to use, and negatively impacted code quality. We couldn't wait for Node to provide related solutions, so we created Fenge to shield developers from complexity, simplify their workflow, and allow them to focus on business logic.

Features

Based on the philosophy outlined above, this tool offers the following features:

  • ๐Ÿ’ช Enhanced Type Safety: This tool provides the strictest tsconfig settings to bolster the type safety of TypeScript projects. It is also compatible with pure JavaScript projects.
  • ๐Ÿ’ƒ Formatting: This tool ensures code consistency across your codebase and minimizes merge conflicts by automatically formatting code. It additionally supports the sorting of imports and package.json files.
  • ๐Ÿ“ Linting: This tool comes equipped with a comprehensive set of rules for static code analysis, which helps catch errors and prevent poor coding practices in JavaScript.
  • ๐Ÿช Git Hooks: After installation, committing code via Git triggers automatic formatting and linting checks. No additional package installations are required.

Highlights

We place a high value on Development Experience (DX).

  • ๐Ÿ“ฆ All-In-One: You don't need to install prettier, eslint, lint-staged or husky.
  • โš™๏ธ Zero Configs: Comes with sensible default configurations for type safety, formatting, and linting, so you don't need to set up any configurations.
  • ๐Ÿ˜‰ Highly Customizable: Every thing is optional. Every thing can be customized.

Quick Start

To quick start, run command below to check formatting and linting style in your project.

npx fenge

Install

We recommend installing it as one of devDependencies in your project.

npm i -D fenge

Usages

Each of the following usages is optional. You can choose the ones that best fit your needs.

Type Safe

Config the strictest tsconfig.json

Config tsconfig.json file in your project root.

{
  "extends": "fenge/tsconfig"
}

Config tsconfig.build.json file in your project root.

For Node.js app:

{
  "extends": ["./tsconfig.json", "fenge/tsconfig/node"],
  "include": ["src"],
  "exclude": ["**/*.test.ts"]
}

For Web app:

{
  "extends": ["./tsconfig.json", "fenge/tsconfig/web"],
  "include": ["src"],
  "exclude": ["**/*.test.ts"]
}

Build your project by executing:

tsc -p ./tsconfig.build.json

Type-check your project by executing:

tsc -p ./tsconfig.build.json --noEmit

For more beat practices, please refer to @fenge/tsconfig.

Formatting & Linting

Here are some main commands to format or lint code.

# Check project's formatting problems only
$ fenge format

# Check project's formatting problems and apply updates
$ fenge format -u

# Check project's linting problems only
$ fenge lint

# Check project's linting problems and apply updates
$ fenge lint -u

# Check both formatting and linting problems
$ fenge

# Check both formatting and linting problems and apply updates
$ fenge -u

This tool does not require a configuration file. However, you can add a fenge.config.js file to customize formatting and linting rules. This file should export an object with two properties:

Tips: These two functions can be async or sync. So you can add async or not in font of the function.

export default {
  format: async () => ({
    semi: false,
    singleQuote: true,
  }),
  lint: async () => [
    {
      files: ["**/*.{js,cjs,mjs,jsx}", "**/*.{ts,cts,mts,tsx}"],
      rules: {
        "no-unused-vars": "error",
      },
    },
  ],
};

Usually, we recommend reusing the built-in configurations rather than writing them from scratch. The built-in configurations re-export from @fenge/prettier-config and @fenge/eslint-config.

// @ts-check
export default {
  format: async () => {
    // See https://www.npmjs.com/package/@fenge/prettier-config for prettier-config detail usage
    const prettierConfig = (await import("fenge/prettier-config")).default;
    return {
      ...prettierConfig,
      // add config below to override the default behavior
      semi: false,
    };
  },
  lint: async () => {
    // See https://www.npmjs.com/package/@fenge/eslint-config for eslint-config detail usage
    const { Builder } = await import("fenge/eslint-config");
    return (
      new Builder()
        .enablePackageJson({
          pick: ["packagejson/top-types"], // only these rules will work for package.json files
        })
        .enableJavaScript({
          omit: ["no-var"], // these rules will not work for js files
        })
        .enableTypeScript()
        // apply additional rules or override the built-in rules for ts files
        .append({
          name: "strictest",
          files: ["**/*.{ts,cts,mts,tsx}"],
          rules: {
            "@typescript-eslint/no-explicit-any": "error",
            "@typescript-eslint/consistent-type-assertions": [
              "error",
              { assertionStyle: "never" },
            ],
            "@typescript-eslint/no-non-null-assertion": "error",
          },
        })
        .toConfig()
    );
  },
};

Tips: You can even install and use other third-party eslint-config, like @sxzz/eslint-config.

Set up Git hooks

Executing fenge install in the project root will write a pre-commit file to the ${PROJECT_ROOT}/.git/hooks folder. After editing package.json -> scripts -> prepare script and executing it once, each commit (via Git) will trigger a code style check for the committed files.

{
  "scripts": {
    "prepare": "fenge install"
  }
}
npm run prepare

Contributing

  • Clone this repository.
  • Enable Corepack using corepack enable or globally install @rnm/pm.
  • Install dependencies using pnpm install.
  • Run pnpm style:update to develop.
  • Start coding and submit your PR.

Show your support

Give a โญ๏ธ if this project helped you!

License

MIT

About

A CLI tool for JavaScript and TypeScript code quality.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •