Skip to content

Commit

Permalink
Add to doc and clean
Browse files Browse the repository at this point in the history
  • Loading branch information
j-svensmark committed Jun 9, 2024
1 parent 14224e5 commit 1b16003
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
9 changes: 6 additions & 3 deletions docs/source/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,14 @@ steps overriding those from earlier:
above in the main :ref:`config` section. If multiple are present, they will
*patch*/*override* each other in the order above.
2. It will look for the same files in the user's home directory (~).
3. It will look for the same files in the current working directory.
4. *[if parsing a file in a subdirectory of the current working directory]*
3. It will look for the same files in all directories between the user's home
directory (~), and the current working directory (this does nothing if the
current working directory is not a sub directory of the home directory).
4. It will look for the same files in the current working directory.
5. *[if parsing a file in a subdirectory of the current working directory]*
It will look for the same files in every subdirectory between the
current working dir and the file directory.
5. It will look for the same files in the directory containing the file
6. It will look for the same files in the directory containing the file
being linted.

This whole structure leads to efficient configuration, in particular
Expand Down
48 changes: 27 additions & 21 deletions src/sqlfluff/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,27 +685,33 @@ def load_config_up_to_path(
self.load_user_appdir_config() if not ignore_local_config else {}
)
user_config = self.load_user_config() if not ignore_local_config else {}
parent_config_paths = (
iter_intermediate_paths(Path(path).absolute(), Path(os.path.expanduser("~")))
if not ignore_local_config
else {}
)
parent_config_stack = (
[self.load_config_at_path(p) for p in reversed(list(parent_config_paths))]
if not ignore_local_config
else []
)
parent_config_stack = [config for config in parent_config_stack if config][:1]
config_paths = (
iter_intermediate_paths(Path(path).absolute(), Path.cwd())
if not ignore_local_config
else {}
)
config_stack = (
[self.load_config_at_path(p) for p in config_paths]
if not ignore_local_config
else []
)
parent_config_stack = []
config_stack = []
if not ignore_local_config:
# Finding all paths between here and the home
# directory. We could start at the root of the filesystem,
# but depending on the user's setup, this might result in
# permissions errors.
parent_config_paths = list(
iter_intermediate_paths(Path(path).absolute(),
Path(os.path.expanduser("~")))
)
# Stripping off the home directory and the current working
# directory, since they are both covered by other code
# here
parent_config_paths = parent_config_paths[1:-1]
parent_config_stack = (
[self.load_config_at_path(p) for p in reversed(list(parent_config_paths))]
)
# Taking the first non-empty config (of the reversed list)
parent_config_stack = [config for config in parent_config_stack if config][:1]

config_paths = (
iter_intermediate_paths(Path(path).absolute(), Path.cwd())
)
config_stack = (
[self.load_config_at_path(p) for p in config_paths]
)
extra_config = (
self.load_extra_config(extra_config_path) if extra_config_path else {}
)
Expand Down

0 comments on commit 1b16003

Please sign in to comment.