vscode-ansible icon indicating copy to clipboard operation
vscode-ansible copied to clipboard

RFE: Default ansible-lint params in settings to `--fix`

Open cidrblock opened this issue 2 years ago • 2 comments

This will enable fixing automatically for users.

We'll need to watch closely for feedback :)

cidrblock avatar Sep 28 '23 15:09 cidrblock

thinking about htis more, let's not do this.......

I think we need to support lint as a formatter e.g. python.formatting.provider

so the user can "File: Save without formatting"

cidrblock avatar Oct 10 '23 13:10 cidrblock

@cidrblock I was planning on creating an issue on a similar topic, but I think the overall challenge is better addressed as you mentioned, through a formatting provider. I encountered an issue trying to create this type of functionality, specifically when using the write_list: ["all"] configuration in ansible-lint, which is designed for auto-fixing. This configuration conflicts with VS Code's "files.autoSave": "afterDelay" setting it seems.

Here's the problem: if auto-save is triggered while you're still modifying a task (which is malformed in some way), the extension invokes ansible-lint and attempts to fix the file, sometimes it does this so quickly, that it is leading to a conflict in VS Code with the following error message:

Failed to save 'site.yml': The content of the file is newer. Please compare your version with the file contents or overwrite the content of the file with your changes.

I believe formatting providers can handle these scenarios more effectively, especially the formatting on save, in fact I saw you can even format only the parts of a file you modified now as well on save. Overall, I support this idea as it aligns with what I was trying to achieve. While you could use pre-commit hooks, you are likely to surprise new users, when the opinionated fixes take place, and force them to re-commit, for example. It would be much more transparent if they could see it while the file was open.

netopsengineer avatar May 30 '24 21:05 netopsengineer