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:
native-desktop lint
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)

$ native-desktop lint

 No linting errors found
All files passed ESLint checks

With Warnings

$ native-desktop lint

 Warning: 3 warnings found

src/components/Button.ts
  12:5  warning  'handleClick' is defined but never used  @typescript-eslint/no-unused-vars

src/utils/helpers.ts
  8:10  warning  'formatDate' is defined but never used  @typescript-eslint/no-unused-vars
  15:3  warning  Unexpected console statement  no-console

With Errors

$ native-desktop lint

 Error: 2 errors found

src/index.ts
  23:15  error  'myVariable' is not defined  no-undef
  45:8   error  Missing semicolon  semi

 2 errors, 0 warnings

ESLint Configuration

The lint command uses the .eslintrc.json file generated by native-desktop create. Here’s an example configuration:
{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": 2022,
    "sourceType": "module"
  },
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended"
  ],
  "rules": {
    "no-console": "warn",
    "no-unused-vars": "error",
    "semi": ["error", "always"],
    "quotes": ["error", "single"]
  }
}

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:
# Check for issues
native-desktop lint

# Fix formatting issues
native-desktop fmt

# Check again
native-desktop lint
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:
# .eslintignore
node_modules/
bin/
dist/
*.config.js
coverage/

Integration with Development Workflow

Pre-Commit Hook

Add linting to your pre-commit hooks using tools like Husky:
{
  "husky": {
    "hooks": {
      "pre-commit": "native-desktop lint"
    }
  }
}

CI/CD Pipeline

Include linting in your continuous integration:
# GitHub Actions example
- name: Lint Code
  run: native-desktop lint

npm Scripts

Add linting to your package.json scripts:
{
  "scripts": {
    "lint": "native-desktop lint",
    "test": "native-desktop lint && npm run test:unit"
  }
}

Exit Codes

The lint command uses standard exit codes for CI/CD integration:
  • 0: No linting errors (warnings are allowed)
  • 1: Linting errors found
native-desktop lint
echo $?  # Check exit code

Common Issues

Error: .eslintrc.json not foundSolution: Ensure the configuration file exists in your project root.
# Check if file exists
ls -la .eslintrc.json

# If missing, recreate project or add configuration
Error: Parsing error: Unexpected tokenSolution: Ensure your TypeScript parser is configured correctly.
{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": 2022,
    "sourceType": "module",
    "project": "./tsconfig.json"
  }
}
Error: Failed to load plugin '@typescript-eslint'Solution: Install missing ESLint plugins.
npm install --save-dev @typescript-eslint/parser @typescript-eslint/eslint-plugin
Error: Overwhelmed by linting errorsSolution: Fix errors gradually or adjust rules.
{
  "rules": {
    "no-console": "warn",  // Change from "error" to "warn"
    "no-unused-vars": "warn"
  }
}
Error: Expected rule to trigger but didn’tSolution: Verify rule configuration and ESLint version.
# Check ESLint version
npx eslint --version

# Verify rule exists
npx eslint --print-config src/index.ts

Customizing Rules

You can customize ESLint rules in .eslintrc.json:
{
  "rules": {
    // Disable a rule
    "no-console": "off",
    
    // Set to warning
    "@typescript-eslint/no-explicit-any": "warn",
    
    // Set to error with options
    "quotes": ["error", "single", { "avoidEscape": true }],
    
    // Custom severity
    "semi": ["error", "always"]
  }
}

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:
# Lint specific file
npx eslint src/index.ts

# Lint specific directory
npx eslint src/components/

# Lint with fix
npx eslint src/ --fix

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:
{
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  "eslint.validate": [
    "javascript",
    "typescript"
  ]
}

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:
# Run lint and save output
native-desktop lint > lint-report.txt

# Count errors and warnings
grep -c "error" lint-report.txt
grep -c "warning" lint-report.txt

Command Comparison

CommandPurposeAuto-FixFocus
native-desktop lintCheck code quality❌ NoLogic, patterns, bugs
native-desktop fmtFormat code style✅ YesFormatting, style
native-desktop typesCheck types❌ NoType safety
Use all three commands together for comprehensive code quality assurance.

Development Workflow

Recommended workflow for maintaining code quality: