# Auto-lint Python with ruff Every time you save a `.py` file, ruff fixes what it safely can (unused imports, sorted imports, ...) and lists everything else in a panel. --- ## Steps 1. **Install Package Control**: `Ctrl+Shift+P` (`Cmd+Shift+P` on a Mac) → `Install Package Control` 2. **Install the LSP package**: `Ctrl+Shift+P` → `Package Control: Install Package` → `LSP` 3. **Install LSP-ruff**: `Ctrl+Shift+P` → `Package Control: Install Package` → `LSP-ruff` 4. *(Optional)* **Install LSP-pyright** the same way, for type checking and better autocomplete 5. **Open your User settings folder**: `Preferences` → `Browse Packages...` → open `User/` --- ## 6. LSP Settings - **Download my settings files** into that `User/` folder: - [LSP.sublime-settings](./LSP.sublime-settings) — runs ruff's fixes and import sorting on save - In **Sublime Text**: - `Preferences` → `Package Settings` → `LSP` → `Settings` - should open a side-by-side view of default settings - Copy-paste `LSP.sublime-settings` content into the right-hand side of your side-by-side view - Save and close your LSP.sublime-settings --- ## 7. `ruff` Settings - In **Sublime Text**: - `Preferences` → `Package Settings` → `LSP` → `Servers` → `ruff` - should open a side-by-side view of default settings - Copy-paste `LSP-ruff.sublime-settings` content into the right-hand side of your settings - Save and close your LSP-ruff.sublime-settings - Restart **Sublime Text** --- ## 8. Verify - In **Sublime Text**: - Open or create a `.py` file with syntax errors - Save the file and `ruff` should display warning/error markers in the left margin - Open your adventures midterm project - Add an unused import (`import math` or `import turtle`) - Ctrl-S to see if your `import` line gets deleted (because it's unused) --- ## 9. `ruff` CLI e.g. `ruff check` (optional) - *(Optional)* **Download [ruff.toml](./ruff.toml)** so `ruff` in the terminal agrees with Sublime: - Linux: `~/.config/ruff/ruff.toml` - macOS: `~/Library/Application Support/ruff/ruff.toml` - Windows: `%APPDATA%\ruff\ruff.toml` --- ## Mesa lab computers --- ## Download from the terminal (Git-Bash) Linux (on macOS use `~/Library/Application\ Support/Sublime\ Text/Packages/User`): ```bash cd ~/.config/sublime-text/Packages/User curl -O https://nlpia.org/fall26/wk10/LSP.sublime-settings curl -O https://nlpia.org/fall26/wk10/LSP-ruff.sublime-settings ``` --- ## Download from Windows (PowerShell): ```powershell cd "$env:APPDATA\Sublime Text\Packages\User" curl.exe -O https://nlpia.org/fall26/wk10/LSP.sublime-settings curl.exe -O https://nlpia.org/fall26/wk10/LSP-ruff.sublime-settings ``` --- ## Automatic install script Close all **Sublime Text** Windows then... #### In PowerShell run this [setup script](./setup-sublime-ruff.ps1) ```powershell irm https://nlpia.org/fall26/wk10/setup-sublime-ruff.ps1 | iex ``` Restart **Sublime Text**