Skip to main content
The lint command runs ESLint on your Native Desktop project to identify and fix code quality issues, enforce coding standards, and catch potential bugs before they reach production.

Prerequisites

Before running the lint command, ensure:
  • Your project has been created using native-desktop create
  • All dependencies are installed (npm install)
  • ESLint configuration exists (.eslintrc.json)

Basic Usage

To lint your project, open the terminal in the root directory of your Native Desktop project and run:
This command will:
  1. Load ESLint configuration from .eslintrc.json
  2. Scan all source files in your project
  3. Report any code quality issues, warnings, or errors
  4. Exit with an appropriate status code

What Gets Linted

By default, the lint command checks:
  • All TypeScript files (.ts, .tsx)
  • All JavaScript files (.js, .jsx)
  • Files in the src/ directory
  • Configuration files (if specified)
Files and directories specified in .eslintignore are automatically excluded from linting.

Output Examples

Successful Lint (No Issues)

With Warnings

With Errors

ESLint Configuration

The lint command uses the .eslintrc.json file generated by native-desktop create. Here’s an example configuration:

Common Linting Rules

The Native Desktop CLI configures ESLint with recommended rules:
  • no-unused-vars: Disallow unused variables
  • no-undef: Disallow undeclared variables
  • no-unreachable: Disallow unreachable code
  • no-constant-condition: Disallow constant conditions

Fixing Issues Automatically

While the lint command reports issues, you can fix many of them automatically using the format command:
The fmt command (Prettier) and lint command (ESLint) work together. Run both for comprehensive code quality.

Ignoring Files

Create or edit .eslintignore to exclude files from linting:

Integration with Development Workflow

Pre-Commit Hook

Add linting to your pre-commit hooks using tools like Husky:

CI/CD Pipeline

Include linting in your continuous integration:

npm Scripts

Add linting to your package.json scripts:

Exit Codes

The lint command uses standard exit codes for CI/CD integration:
  • 0: No linting errors (warnings are allowed)
  • 1: Linting errors found

Common Issues

Error: .eslintrc.json not foundSolution: Ensure the configuration file exists in your project root.
Error: Parsing error: Unexpected tokenSolution: Ensure your TypeScript parser is configured correctly.
Error: Failed to load plugin '@typescript-eslint'Solution: Install missing ESLint plugins.
Error: Overwhelmed by linting errorsSolution: Fix errors gradually or adjust rules.
Error: Expected rule to trigger but didn’tSolution: Verify rule configuration and ESLint version.

Customizing Rules

You can customize ESLint rules in .eslintrc.json:

Rule Severity Levels

  • “off” or 0: Disable the rule
  • “warn” or 1: Enable as warning (doesn’t fail build)
  • “error” or 2: Enable as error (fails build)

Linting Specific Files

While the CLI command lints the entire project, you can lint specific files using npx directly:

Best Practices

Lint Early, Lint Often

Run linting frequently during development to catch issues early.

Consistent Rules

Keep ESLint rules consistent across your team and projects.

Address Warnings

Don’t ignore warnings—they often indicate potential issues.

Automate Linting

Integrate linting into your CI/CD pipeline and pre-commit hooks.

IDE Integration

Most modern IDEs integrate with ESLint automatically:

Visual Studio Code

Install the ESLint extension:
  1. Open VS Code
  2. Go to Extensions (Cmd+Shift+X / Ctrl+Shift+X)
  3. Search for “ESLint”
  4. Install the official ESLint extension
Configure auto-fix on save:

WebStorm / IntelliJ IDEA

ESLint is built-in and enabled by default. Configure in: Settings → Languages & Frameworks → JavaScript → Code Quality Tools → ESLint

Quality Metrics

Track linting issues over time to improve code quality:

Command Comparison

Use all three commands together for comprehensive code quality assurance.

Development Workflow

Recommended workflow for maintaining code quality: