![]() Problems can be anything from potential runtime bugs, to not following best practices, to styling issues. It helps you find and fix problems in your JavaScript code. What is ESLint?ĮSLint is a configurable JavaScript linter. However, many people just use ESLint with an opinionated config (like airbnb) and find it good enough.Įither is fine IMO and I see both being used relatively equally.This page contains a high-level overview of some of the core concepts of ESLint. The official guidance from ESLint is to append eslint-config-prettier after your lint config to disable all rules that can conflict with prettier. IMO, the bikeshedding argument didn't really hold up because ESLint formatting can also be opinionated and Prettier also has configurations. Prettier was seen as an opinionated formatter that would cause fewer "bikeshedding" arguments. Honestly, it seems like the ESLint devs gave up/can't be bothered. This would be fine, but ESLint devs couldn't fix certain issues with some of their formatting rules Maintaining a formatter and linter in one tool is more difficult I guess. ESLint ended up performing some fixes that should probably be handled by a formatter. However, with JS some "formatting" rules could be parse errors in in some browsers. In other languages fmt and linting are handled by separate tools. I did quite a bit of research into this a few months ago and came to the following conclusions: But I think that's mainly from an ease-of-use perspective: there's nothing to configure with Prettier, and then with ESLint, I just configure it to not do any formatting (there's a convenient config pack for that), and then add and remove rules as I'm going along and noticing issues. Personally, I've found keeping the two separate makes the most sense to me, and tends to be a good solution. That said, I personally don't like it because it forces you to use ESLint's "auto fix" functionality, which I find works well for formatting, but IME less well for some of the other lints. I've worked at companies that have used this approach, and it makes setting up your editor/IDE very simple, because you've only got one tool to configure. ![]() The idea is that the developer only needs to run one tool (ESLint), but you add a plugin to ESLint that just calls prettier and converts the prettier error messages to ESLint error messages. I believe the Airbnb JS Styleguide has some formatting rules in, and I assume they'll also be present in their ESLint config plugin (although interestingly, if you google "Airbnb formatting", you get a lot of tutorials on how to integrate the Airbnb configuration and prettier - make of that what you will!)Īnother approach that you can also take is a sort of "prettier as an ESLint plugin" option, such with eslint-plugin-prettier. ESLint, on the other hand, not only requires each formatting rule to be configured individually, but also applies them generally individually, so it's easier to have cases where you can get inconsistent behaviour depending on the original formatting of the file. Related: Conceptually, Prettier formats holistically, which is to say, it takes a whole document and applies its formatting to every single syntax node - generally, this means that you get very close to having exactly one valid output, no matter how the input file is formatted.To ensure every detail is formatted the same way, you need to put a lot of effort into configuring ESLint, which most people don't really want to do. ESLint has some default formatting rules IIRC, but relatively minimal ones. ![]() Prettier is already preconfigured, so it's also usually quicker to get started with.So if you just need to format your code quickly in one chunk, Prettier is the way to go. ![]() Prettier is designed to format documents and that's it, which means it can be a lot simpler than ESLint, at least architecturally, especially as there's relatively little in the way of plugins. It's really fast, particularly in comparison to ESLint. ![]() Because Prettier generally does a better job of formatting than ESLint. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |