Skip to content

Exit with non-zero code when no files are found to lint/format#1358

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-1112
Draft

Exit with non-zero code when no files are found to lint/format#1358
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-1112

Conversation

Copy link

Copilot AI commented Jul 30, 2025

Previously, djLint would print "No files to check! 😢" but exit with code 0 (success) when no files were found to process. This allowed CI systems to silently miss configuration issues where djLint wasn't processing any files, potentially hiding problems for months.

Now djLint exits with code 1 when no files are found, making it easier to catch configuration issues in CI/CD pipelines.

Use Cases

# These now exit with code 1 when no HTML files are found
djlint --check jinja_templates/
djlint --lint jinja_templates/ 
djlint --reformat empty_directory/

Implementation

The change is minimal and surgical - only one line modified in src/djlint/__init__.py:

  • Changed return to sys.exit(1) when the file list is empty
  • Preserves existing user-friendly message "No files to check! 😢"
  • Works consistently across all djLint modes (--lint, --check, --reformat)

Edge Cases Handled

  • Stdin input: Still works normally (exit code 0) since it creates a temporary file
  • Nonexistent paths: Handled by Click's path validation before our code runs
  • Directories with files: Normal operation unchanged (exit code 0 when files found)

Fixes #1112.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@netlify
Copy link

netlify bot commented Jul 30, 2025

Deploy Preview for djlint failed.

Name Link
🔨 Latest commit 44a762e
🔍 Latest deploy log https://app.netlify.com/projects/djlint/deploys/688a6b5cd4e861000841be18

Copilot AI and others added 2 commits July 30, 2025 18:52
Co-authored-by: monosans <76561516+monosans@users.noreply.github.com>
Co-authored-by: monosans <76561516+monosans@users.noreply.github.com>
Copilot AI changed the title [WIP] [FEATURE] Exit with non-zero code if no files formatted/linted Exit with non-zero code when no files are found to lint/format Jul 30, 2025
Copilot AI requested a review from monosans July 30, 2025 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Exit with non-zero code if no files formatted/linted

2 participants