djlint / djLint

✨ HTML Template Linter and Formatter. Django - Jinja - Nunjucks - Handlebars - GoLang
https://djLint.com
GNU General Public License v3.0
686 stars 84 forks source link

[BUG] supplied configuration in CLI overridden by default file #803

Open willemo opened 9 months ago

willemo commented 9 months ago

System Info

Issue

When you have a "default" config file in your project's root folder (e.g. a pyproject.toml file) and you provide a different config file in your CLI command (e.g. --configuration .djlintrc), the former will always override the latter. According to the docs this should not be the case:

Command line args will always override any settings in pyproject.toml.

I've found a possible cause of this: in the load_project_settings function there isn't a return after the provided config path has been loaded, causing the default paths to be checked, which will override the provided config.

How To Reproduce

Create two config files (pyproject.toml and .djlintrc) with different configuration (e.g. only add extend_exclude to the .djlintrc file) and run the following command:

djlint --configuration .djlintrc

The command will ignore the extend_exclude settings from .djlintrc.

Contents of .djlintrc/pyproject.toml [tool.djlint]

pyproject.toml

[tool.djlint]
profile = "jinja"

.djlintrc

{
    "profile": "jinja",
    "extend_exclude": "path/to/file.html"
}