Skip to content

Commit 87c51fd

Browse files
committed
feature: add ansible-lint auto-fix on save capability (#2151)
1 parent 22cf872 commit 87c51fd

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,13 @@
331331
"scope": "resource",
332332
"type": "string"
333333
},
334+
"ansible.validation.lint.autoFixOnSave": {
335+
"default": false,
336+
"markdownDescription": "Specifies whether `ansible-lint --fix` should run automatically when you save a file. [Learn more](https://ansible.readthedocs.io/projects/lint/autofix/)",
337+
"order": 4,
338+
"scope": "resource",
339+
"type": "boolean"
340+
},
334341
"ansible.validation.lint.enabled": {
335342
"default": true,
336343
"markdownDescription": "Enables `ansible-lint`. If disabled only `ansible-playbook --syntax-check` will run. Requires `#ansible.validation.enabled#` to be enabled.",

packages/ansible-language-server/src/interfaces/extensionSettings.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ export interface ExtensionSettings extends ExtensionSettingsType {
4444
};
4545
validation: {
4646
enabled: boolean;
47-
lint: { enabled: boolean; path: string; arguments: string };
47+
lint: {
48+
enabled: boolean;
49+
path: string;
50+
arguments: string;
51+
autoFixOnSave: boolean;
52+
};
4853
};
4954
executionEnvironment: {
5055
enabled: boolean;
@@ -156,5 +161,9 @@ interface ValidationSettingsWithDescription extends SettingsEntry {
156161
default: string;
157162
description: string;
158163
};
164+
autoFixOnSave: {
165+
default: boolean;
166+
description: string;
167+
};
159168
};
160169
}

packages/ansible-language-server/src/services/ansibleLint.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ export class AnsibleLint {
7373
this._ansibleLintConfigFilePath = ansibleLintConfigPath;
7474
linterArguments = `${linterArguments} --offline --nocolor -f codeclimate`;
7575

76+
if (settings.validation.lint.autoFixOnSave) {
77+
linterArguments = `${linterArguments} --fix`;
78+
}
79+
7680
const docPath = URI.parse(textDocument.uri).path;
7781
mountPaths.add(path.dirname(docPath));
7882

packages/ansible-language-server/src/services/settingsManager.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ export class SettingsManager {
110110
description:
111111
"Optional command line arguments to be appended to ansible-lint invocation",
112112
},
113+
autoFixOnSave: {
114+
default: false,
115+
description:
116+
"Specifies whether `ansible-lint --fix` should run automatically when you save a file.",
117+
},
113118
},
114119
},
115120
};

0 commit comments

Comments
 (0)