Android Studio是否支持ESLint?求替代方案及自动保存格式化方法
Great question! Since Android Studio shares the same IntelliJ IDEA foundation as PHPStorm and WebStorm, it absolutely can work with ESLint—though it might need a quick setup if you’re not already working on web-related projects. Let’s break this down:
Does Android Studio support ESLint?
Yes, it does! Here’s how to get it up and running smoothly:
- First, ensure the JavaScript and TypeScript plugin is enabled (it’s usually pre-installed, but double-check in
Settings > Pluginsto be safe). - Make sure your project has ESLint installed locally (run
npm install eslint --save-devor the yarn equivalent) and an.eslintrcconfiguration file set up. - Head to
Settings > Languages & Frameworks > JavaScript > Code Quality Tools > ESLintand toggle on "Automatic ESLint configuration" (this will detect your local ESLint setup automatically). If that doesn’t pick it up, you can manually point to your ESLint package path.
Once configured, Android Studio will highlight ESLint issues in your code and let you run fixes just like in WebStorm.
Alternatives to ESLint in Android Studio
If for some reason you don’t want to use ESLint, there are a few built-in or easily integratable options:
- JSHint: A lightweight, straightforward linter for JavaScript. Android Studio has native support for it—just enable it in the same code quality tools settings menu and set up a
.jshintrcfile. - Prettier: While not a linter (it’s a dedicated code formatter), it’s a popular companion to linters. Android Studio integrates seamlessly with Prettier, and you can set it up to format your code on save (more on that below).
- TSLint: Note that TSLint is deprecated now, but if you’re maintaining an older TypeScript project that uses it, Android Studio still supports it. That said, migrating to ESLint is the recommended long-term path.
Auto-formatting on save with Android Studio’s built-in tools
Absolutely! You don’t need external tools to get auto-formatting working. Here’s how to set it up:
- Open
Settings > Tools > Actions on Save(for older Android Studio versions, look underSettings > Editor > General > Editor Tabs > Save Actions). - Check the box for Reformat code. You can click the gear icon next to it to choose which file types (like JavaScript, TypeScript, Java, etc.) you want this to apply to.
- If you’re using ESLint, you can also check Run eslint --fix in the same menu to auto-resolve fixable ESLint issues every time you save.
This will keep your code consistently formatted without any extra manual steps.
Content of the question originates from stack exchange, question author Aksenov Vladimir

