惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Full Disclosure
WordPress大学
WordPress大学
小众软件
小众软件
Cloudbric
Cloudbric
AWS News Blog
AWS News Blog
腾讯CDC
量子位
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
Scott Helme
Scott Helme
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Hacker News
The Hacker News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
Jina AI
Jina AI
Attack and Defense Labs
Attack and Defense Labs
S
SegmentFault 最新的问题
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
Google Online Security Blog
Google Online Security Blog
美团技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
罗磊的独立博客
L
LINUX DO - 最新话题
博客园 - Franky
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
The Last Watchdog
The Last Watchdog
J
Java Code Geeks
AI
AI
C
Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cyber Attacks, Cyber Crime and Cyber Security
Cisco Talos Blog
Cisco Talos Blog
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
Help Net Security
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
I
Intezer
S
Securelist

JonahDevs

Building in Public: The ‘Back to It’ VS Code Extension – Part 1 Time, the Silent Exploit: The Unseen Enemy in Every Codebase The Mindful Coder’s Workweek: 5 Themes to Enhance Your Craft and Satisfaction From Dirty Dishes to Clean Code: How Household Chores Mirror Programming Team Dynamics You’re Closer Than You Think: The Only 6 DNS Concepts You Really Need The Wasabi Method: Shocking Your Way Out of Anxiety Attacks Free Software: The New Nicotine? Big Tech’s Playbook Straight Out of Big Tobacco Your Gut is Smarter Than Your Spreadsheet: The Art of Software Estimation The Subtract Day: Why Less Code Can Lead to More Success
ESLint
Jonah · 2024-06-28 · via JonahDevs

Why Do We Even Bother with Linters?

Linting is always something I think I rush through as quickly as possible in a new project. If I’m lucky, someone else has already done it by the time I join the codebase, and my biggest problem is simply making sure I get rid of all the lil red underlines. Sometimes the IDE can even do this part for you, with auto-suggested fixes.

For reference, my stack normally consists of TypeScript, NextJS, and Vercel. But regardless of your tech stack, linters play a crucial role in development. So, why do we even bother with them? Let’s break it down.

1. How Do Linters Catch Bugs Before They Bite?

Linters are like your code’s personal proofreader. They scan your JavaScript or TypeScript files, looking for potential issues before they become actual problems. ESLint, for instance, can spot things like:

  • Unused variables (bye-bye, memory leaks)
  • Inconsistent naming conventions (no more myVar, my_var, and MyVar in the same file)
  • Missing semicolons (if you’re into that sort of thing)

By catching these issues early, you’re saving yourself from hours of head-scratching debug sessions later.

2. Can Linters Really Make Your Code More Readable?

Absolutely. Linters enforce consistent coding styles across your entire project. This means:

  • Consistent indentation (no more mixing tabs and spaces)
  • Standardized quote usage (single or double, pick your poison)
  • Enforced spacing rules (say goodbye to function(a,b,c){return a+b+c})

The result? Code that’s easier to read, understand, and maintain. Your future self (and your teammates) will thank you.

3. How Do Linters Boost Your Productivity?

This might seem counterintuitive at first. After all, isn’t linting just another step in your workflow? But hear me out:

  • Automated error catching means less time debugging
  • Consistent code style means less time in code reviews arguing about formatting
  • IDE integration means real-time feedback as you code

In the long run, linters save you time by catching issues early and promoting best practices.

The Bottom Line: Are Linters Worth the Hassle?

Look, I get it. Setting up ESLint (or any linter) can feel like a chore. But trust me, it’s worth it. Think of it as an investment in your code’s future. You’re not just writing code for today; you’re writing it for the poor soul who has to maintain it six months from now (spoiler alert: that poor soul is probably you).

So next time you’re starting a new project, don’t rush through the linting setup. Embrace it. Your code (and your sanity) will thank you.

Remember, good code isn’t just about making things work. It’s about making things work well, consistently, and maintainably. And that’s exactly what linters help us achieve.

Bonus: Where Does ESLint Stop and Prettier Begin?

Ah, the age-old question (well, as “age-old” as anything can be in the fast-paced world of web development). Let’s break down the difference between linters and formatters, using our friends ESLint and Prettier as examples.

Linters: The Code Quality Police

ESLint, our trusty linter, is like the code quality police. It’s concerned with:

  • Identifying potential bugs
  • Enforcing best practices
  • Spotting suspicious constructs

For example, ESLint might warn you about using == instead of ===, or alert you to unused variables.

Formatters: The Code Style Beauticians

Prettier, on the other hand, is your code’s personal stylist. It focuses on:

  • Consistent formatting
  • Managing line length
  • Standardizing indentation and spacing

Prettier doesn’t care if your code might throw an error; it just wants it to look pretty.

The Gray Area: When Linters Format

Here’s where it gets a bit fuzzy. ESLint can also enforce some formatting rules, like:

  • Indentation
  • Semicolon usage
  • Quote style

So why use both? Because they excel at different things.

The Power Couple: ESLint + Prettier

Using ESLint and Prettier together gives you the best of both worlds:

  1. ESLint catches potential bugs and enforces best practices
  2. Prettier handles all the nitty-gritty formatting details

This combo lets you focus on writing good code, not arguing about whether to use tabs or spaces (it’s spaces, by the way… fight me).

The Bottom-Bottom Line

Think of it this way:

  • ESLint is about the substance of your code
  • Prettier is about the style

Together, they ensure your code is not just correct, but also consistently formatted and easy on the eyes. It’s like having a spell-checker and a grammar-checker for your code – why settle for just one when you can have both?

So next time you’re setting up a project, remember: ESLint for quality, Prettier for style. Your code (and your team) will thank you.