Closure Compiler vs ESLint

Need advice about which tool to choose?Ask the StackShare community!

Closure Compiler

189
61
+ 1
5
ESLint

28.6K
13.3K
+ 1
28
Add tool

Closure Compiler vs ESLint: What are the differences?

Introduction

This markdown provides a comparison between Closure Compiler and ESLint, highlighting their key differences in a concise manner.

  1. Compilation vs Linting: Closure Compiler is primarily a JavaScript compiler that performs static analysis, type checking, and code optimization, ultimately producing optimized and smaller code. On the other hand, ESLint is a linter that focuses on identifying and reporting code style and best practice violations, helping developers enforce consistent coding conventions.

  2. Type Checking: Closure Compiler includes a robust type system that checks and enforces type annotations within JavaScript code. It can help catch type-related errors during compilation and optimize the code based on static typing information. ESLint, on the other hand, doesn't have built-in type checking capabilities and relies on code patterns and rules defined by the developer.

  3. Code Optimization: Closure Compiler performs advanced code optimization techniques, such as dead code elimination, function inlining, and property renaming, to reduce the final code size and improve performance. ESLint does not perform code optimization and focuses solely on style and rule enforcement.

  4. Supported Platforms: Closure Compiler is primarily designed for optimizing and compiling JavaScript code for web applications. It aims to improve page load times and runtime efficiency. ESLint is capable of analyzing JavaScript code for almost any environment or platform, including web applications, Node.js applications, and even browser extensions.

  5. Configurability: Closure Compiler offers a rich set of configuration options that allow developers to customize the level of code optimization and type checking according to their specific needs. ESLint, being a linter, provides extensive configuration options to define coding rules and styles to enforce, ensuring consistency and maintainability across the codebase.

  6. Integration: Closure Compiler is often used in build pipelines or integrated into development workflows to automatically optimize and transpile JavaScript code during the build process. ESLint integrates with code editors and IDEs, providing real-time code linting and highlighting of issues while the developer is writing code, helping catch mistakes early on.

In summary, Closure Compiler is primarily focused on optimizing and compiling JavaScript code, while ESLint is geared towards enforcing coding conventions, detecting style violations, and ensuring code quality.

Advice on Closure Compiler and ESLint
Needs advice
on
ESLintESLintSass Lint Sass Lint
and
StylelintStylelint

Scenario: I want to integrate Prettier in our code base which is currently using ESLint (for .js and .scss both). The project is using gulp.

It doesn't feel quite right to me to use ESLint, I wonder if it would be better to use Stylelint or Sass Lint instead.

I completed integrating ESLint + Prettier, Planning to do the same with [ Stylelint || Sasslint || EsLint] + Prettier.

And have gulp 'fix' on file save (Watcher).

Any recommendation is appreciated.

See more
Replies (3)
Amaro Mariño
Senior Frontend Developer at Landbot.io · | 6 upvotes · 150.1K views
Recommends
on
ESLintESLint

In the case of .js files I would recommend using both Eslint and Prettier.

You can set up Prettier as an Eslint rule using the following plugin:

https://github.com/prettier/eslint-plugin-prettier

And in order to avoid conflicts between Prettier and Eslint, you can use this config:

https://github.com/prettier/eslint-config-prettier

Which turns off all Eslint rules that are unnecessary or might conflict with Prettier.

See more
Alexis Villegas Torres
Software Engineer at SpeedUrWeb · | 5 upvotes · 149.8K views
Recommends
on
StylelintStylelint

Pura vida! Well, I had a similar issue and at the end I decided to use Stylelint + Prettier for that job, in our case, we wanted that our linting process includes the SCSS files and not only the JS file, base on that we concluded that using only ESLint to do both things wasn't the best option, so, we integrated prettier with Stylelint, and for that we used a neat plugin that allowed us to use Prettier inside Stylelint here is the link, https://github.com/prettier/stylelint-prettier#recommended-configuration, I hope that this can help you, hasta pronto!, :)

See more
Alex Spieslechner

you don't actually have to choose between these tools as they have vastly different purposes. i think its more a matter of understanding how to use them.

while eslint and stylelint are used to notify you about code quality issues, to guide you to write better code, prettier automatically handles code formatting (without notifying me). nothing else.

prettier and eslint both officially discourage using the eslint-plugin-prettier way, as these tools actually do very different things. autofixing with linters on watch isnt a great idea either. auto-fixing should only be done intentionally. you're not alone though, as a lot of devs set this up wrong.

i encourage you to think about what problem you're trying to solve and configure accordingly.

for my teams i set it up like this: - eslint, stylelint, prettier locally installed for cli use and ide support - eslint config prettier (code formatting rules are not eslints business, so dont warn me about it) - vscode workspace config: format on save - separate npm scripts for linting, and formatting - precommit hooks (husky)

so you can easily integrate with gulp. its just js after all ;)

See more
Get Advice from developers at your company using StackShare Enterprise. Sign up for StackShare Enterprise.
Learn More
Pros of Closure Compiler
Pros of ESLint
  • 1
    The best performing output
  • 1
    Small output size
  • 1
    Dead code elimination
  • 1
    ES6 support
  • 1
    Bundle support for CommonJS, ES6, .
  • 0
    Ease
  • 8
    Consistent javascript - opinions don't matter anymore
  • 6
    Free
  • 6
    IDE Integration
  • 4
    Customizable
  • 2
    Focuses code review on quality not style
  • 2
    Broad ecosystem of support & users

Sign up to add or upvote prosMake informed product decisions

What is Closure Compiler?

The Closure Compiler is a tool for making JavaScript download and run faster. It is a true compiler for JavaScript. Instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls.

What is ESLint?

A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.

Need advice about which tool to choose?Ask the StackShare community!

What companies use Closure Compiler?
What companies use ESLint?
See which teams inside your own company are using Closure Compiler or ESLint.
Sign up for StackShare EnterpriseLearn More

Sign up to get full access to all the companiesMake informed product decisions

What tools integrate with Closure Compiler?
What tools integrate with ESLint?

Sign up to get full access to all the tool integrationsMake informed product decisions

Blog Posts

What are some alternatives to Closure Compiler and ESLint?
Webpack
A bundler for javascript and friends. Packs many modules into a few bundled assets. Code Splitting allows to load parts for the application on demand. Through "loaders" modules can be CommonJs, AMD, ES6 modules, CSS, Images, JSON, Coffeescript, LESS, ... and your custom stuff.
Babel
Babel will turn your ES6+ code into ES5 friendly code, so you can start using it right now without waiting for browser support.
UglifyJS
This package implements a general-purpose JavaScript parser/compressor/beautifier toolkit. It is developed on NodeJS, but it should work on any JavaScript platform supporting the CommonJS module system (and if your platform of choice doesn’t support CommonJS, you can easily implement it, or discard the exports.* lines from UglifyJS sources).
TypeScript
TypeScript is a language for application-scale JavaScript development. It's a typed superset of JavaScript that compiles to plain JavaScript.
See all alternatives