Detect imports in src layouts by default (#12848)

## Summary

Occasionally, we receive bug reports that imports in `src` directories
aren't correctly detected. The root of the problem is that we default to
`src = ["."]`, so users have to set `src = ["src"]` explicitly. This PR
extends the default to cover _both_ of them: `src = [".", "src"]`.

Closes https://github.com/astral-sh/ruff/issues/12454.

## Test Plan

I replicated the structure described in
https://github.com/astral-sh/ruff/issues/12453, and verified that the
imports were considered sorted, but that adding `src = ["."]` showed an
error.
This commit is contained in:
Charlie Marsh 2024-08-14 10:54:45 -04:00 committed by Micha Reiser
parent 33512a4249
commit 15aa5a6d57
8 changed files with 33 additions and 31 deletions

View file

@ -271,7 +271,6 @@ impl Configuration {
.chain(lint.extend_per_file_ignores)
.collect(),
)?,
fix_safety: FixSafetyTable::from_rule_selectors(
&lint.extend_safe_fixes,
&lint.extend_unsafe_fixes,
@ -280,8 +279,9 @@ impl Configuration {
require_explicit: false,
},
),
src: self.src.unwrap_or_else(|| vec![project_root.to_path_buf()]),
src: self
.src
.unwrap_or_else(|| vec![project_root.to_path_buf(), project_root.join("src")]),
explicit_preview_rules: lint.explicit_preview_rules.unwrap_or_default(),
task_tags: lint