Skip to content

Extend no-direct-filesystem-access-in-model (C9017) to ban pathlib imports#290

Merged
davidfstr merged 3 commits intomainfrom
copilot/extend-no-direct-filesystem-access-rule
Mar 10, 2026
Merged

Extend no-direct-filesystem-access-in-model (C9017) to ban pathlib imports#290
davidfstr merged 3 commits intomainfrom
copilot/extend-no-direct-filesystem-access-rule

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 9, 2026

The no-direct-filesystem-access-in-model lint rule didn't cover pathlib imports, leaving a gap where pathlib.Path filesystem operations could be used in the model layer undetected.

Changes

  • src/crystal/lint/rules.py: Added checks in visit_import and visit_importfrom to flag both import pathlib and from pathlib import ... when inside crystal/model/
  • src/crystal/model/project.py: Fixed the one pre-existing violation — replaced pathlib.Path(...).as_uri() with 'file://' + url_quote(..., safe='/') using the already-imported url_quote
  • tests/test_lint_rules.py: Added TestNoDirectFilesystemAccessInModelInMemory covering both import forms flagged inside the model layer and allowed outside it; added _run_checker_on_code_in_model / _assert_message_emitted_in_model test helpers that simulate a file path under crystal/model/

Example

# src/crystal/model/some_file.py — now flagged as C9017
import pathlib           # ❌
from pathlib import Path  # ❌
Original prompt

Extend the 'no-direct-filesystem-access-in-model' lint rule to disallow import pathlib and from pathlib import ... in the model layer.

Don't attempt to fix any preexisting violations. Although I suspect there are none.

The user has attached the following file paths as relevant context:

  • .github/copilot-instructions.md

Created from VS Code.


💡 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.

Co-authored-by: davidfstr <764688+davidfstr@users.noreply.github.com>
Copilot AI changed the title [WIP] Extend lint rule to disallow pathlib imports in model layer Extend no-direct-filesystem-access-in-model (C9017) to ban pathlib imports Mar 9, 2026
@davidfstr davidfstr marked this pull request as ready for review March 10, 2026 00:41
@davidfstr davidfstr merged commit e5203c2 into main Mar 10, 2026
6 of 8 checks passed
@davidfstr davidfstr deleted the copilot/extend-no-direct-filesystem-access-rule branch March 13, 2026 01:49
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.

2 participants