> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nativedesktop.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Lint Project

> Run ESLint to check code quality and style in your Native Desktop project

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:

```shellscript theme={null}
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)

```shellscript theme={null}
$ native-desktop lint

✓ No linting errors found
All files passed ESLint checks
```

### With Warnings

```shellscript theme={null}
$ 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

```shellscript theme={null}
$ 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:

```json theme={null}
{
  "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:

<Tabs>
  <Tab title="Code Quality">
    * **no-unused-vars**: Disallow unused variables
    * **no-undef**: Disallow undeclared variables
    * **no-unreachable**: Disallow unreachable code
    * **no-constant-condition**: Disallow constant conditions
  </Tab>

  <Tab title="Best Practices">
    * **eqeqeq**: Require `===` and `!==`
    * **no-eval**: Disallow `eval()`
    * **no-implied-eval**: Disallow implied `eval()`
    * **no-with**: Disallow `with` statements
  </Tab>

  <Tab title="TypeScript">
    * **@typescript-eslint/no-explicit-any**: Warn on `any` type usage
    * **@typescript-eslint/no-unused-vars**: Disallow unused TypeScript variables
    * **@typescript-eslint/explicit-function-return-type**: Require explicit return types
  </Tab>

  <Tab title="Style">
    * **semi**: Require semicolons
    * **quotes**: Enforce quote style
    * **indent**: Enforce consistent indentation
    * **comma-dangle**: Require trailing commas
  </Tab>
</Tabs>

## Fixing Issues Automatically

While the `lint` command reports issues, you can fix many of them automatically using the format command:

```shellscript theme={null}
# Check for issues
native-desktop lint

# Fix formatting issues
native-desktop fmt

# Check again
native-desktop lint
```

<Tip>
  The `fmt` command (Prettier) and `lint` command (ESLint) work together. Run both for comprehensive code quality.
</Tip>

## 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:

```json theme={null}
{
  "husky": {
    "hooks": {
      "pre-commit": "native-desktop lint"
    }
  }
}
```

### CI/CD Pipeline

Include linting in your continuous integration:

```yaml theme={null}
# GitHub Actions example
- name: Lint Code
  run: native-desktop lint
```

### npm Scripts

Add linting to your package.json scripts:

```json theme={null}
{
  "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

```shellscript theme={null}
native-desktop lint
echo $?  # Check exit code
```

## Common Issues

<AccordionGroup>
  <Accordion title="ESLint Configuration Not Found">
    **Error**: `.eslintrc.json not found`

    **Solution**: Ensure the configuration file exists in your project root.

    ```shellscript theme={null}
    # Check if file exists
    ls -la .eslintrc.json

    # If missing, recreate project or add configuration
    ```
  </Accordion>

  <Accordion title="Parsing Error">
    **Error**: `Parsing error: Unexpected token`

    **Solution**: Ensure your TypeScript parser is configured correctly.

    ```json theme={null}
    {
      "parser": "@typescript-eslint/parser",
      "parserOptions": {
        "ecmaVersion": 2022,
        "sourceType": "module",
        "project": "./tsconfig.json"
      }
    }
    ```
  </Accordion>

  <Accordion title="Plugin Not Found">
    **Error**: `Failed to load plugin '@typescript-eslint'`

    **Solution**: Install missing ESLint plugins.

    ```shellscript theme={null}
    npm install --save-dev @typescript-eslint/parser @typescript-eslint/eslint-plugin
    ```
  </Accordion>

  <Accordion title="Too Many Errors">
    **Error**: Overwhelmed by linting errors

    **Solution**: Fix errors gradually or adjust rules.

    ```json theme={null}
    {
      "rules": {
        "no-console": "warn",  // Change from "error" to "warn"
        "no-unused-vars": "warn"
      }
    }
    ```
  </Accordion>

  <Accordion title="Rule Not Working">
    **Error**: Expected rule to trigger but didn't

    **Solution**: Verify rule configuration and ESLint version.

    ```shellscript theme={null}
    # Check ESLint version
    npx eslint --version

    # Verify rule exists
    npx eslint --print-config src/index.ts
    ```
  </Accordion>
</AccordionGroup>

## Customizing Rules

You can customize ESLint rules in `.eslintrc.json`:

```json theme={null}
{
  "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:

```shellscript theme={null}
# Lint specific file
npx eslint src/index.ts

# Lint specific directory
npx eslint src/components/

# Lint with fix
npx eslint src/ --fix
```

## Best Practices

<CardGroup cols={2}>
  <Card title="Lint Early, Lint Often" icon="clock">
    Run linting frequently during development to catch issues early.
  </Card>

  <Card title="Consistent Rules" icon="scale-balanced">
    Keep ESLint rules consistent across your team and projects.
  </Card>

  <Card title="Address Warnings" icon="triangle-exclamation">
    Don't ignore warnings—they often indicate potential issues.
  </Card>

  <Card title="Automate Linting" icon="robot">
    Integrate linting into your CI/CD pipeline and pre-commit hooks.
  </Card>
</CardGroup>

## 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:

```json theme={null}
{
  "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:

```shellscript theme={null}
# 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

| Command                | Purpose            | Auto-Fix | Focus                 |
| ---------------------- | ------------------ | -------- | --------------------- |
| `native-desktop lint`  | Check code quality | ❌ No     | Logic, patterns, bugs |
| `native-desktop fmt`   | Format code style  | ✅ Yes    | Formatting, style     |
| `native-desktop types` | Check types        | ❌ No     | Type safety           |

<Info>
  Use all three commands together for comprehensive code quality assurance.
</Info>

## Development Workflow

Recommended workflow for maintaining code quality:

```mermaid theme={null}
graph LR
    A[Write Code] --> B[native-desktop lint]
    B --> C{Issues Found?}
    C -->|Yes| D[Fix Issues]
    C -->|No| E[native-desktop fmt]
    D --> B
    E --> F[native-desktop types]
    F --> G{Type Errors?}
    G -->|Yes| H[Fix Types]
    G -->|No| I[Commit Code]
    H --> F
```
