Skip to content

Commit 6bb18b4

Browse files
committed
Added autocorrectArg config option so that users can run RuboCop with --auto-correct-all (-A)
1 parent c660296 commit 6bb18b4

5 files changed

Lines changed: 19 additions & 2 deletions

File tree

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,13 @@ Specify configuration (via navigating to `File > Preferences > Workspace Setting
6666
// "ruby.rubocop.executePath": "/Users/you/.rvm/gems/ruby-2.3.2/bin/"
6767
// "ruby.rubocop.executePath": "D:/bin/Ruby22-x64/bin/"
6868

69+
// Set to "--auto-correct-all" to enable "unsafe" auto-corrections
70+
"ruby.rubocop.autocorrectArg": "--auto-correct",
71+
6972
// If not specified, it assumes a null value by default.
7073
"ruby.rubocop.configFilePath": "/path/to/config/.rubocop.yml",
7174

72-
// default true
75+
// default: true
7376
"ruby.rubocop.onSave": true
7477
}
7578
```

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@
7171
"default": "",
7272
"description": "execution path of rubocop."
7373
},
74+
"ruby.rubocop.autocorrectArg": {
75+
"type": "string",
76+
"default": "--auto-correct",
77+
"description": "RuboCop argument for autocorrect. Use --auto-correct-all to include unsafe autocorrections."
78+
},
7479
"ruby.rubocop.configFilePath": {
7580
"type": "string",
7681
"default": "",

src/configuration.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Rubocop } from './rubocop';
66

77
export interface RubocopConfig {
88
command: string;
9+
autocorrectArg: string;
910
onSave: boolean;
1011
configFilePath: string;
1112
useBundler: boolean;
@@ -70,6 +71,7 @@ export const getConfig: () => RubocopConfig = () => {
7071

7172
return {
7273
command,
74+
autocorrectArg: conf.get('autocorrectArg', '--auto-correct'),
7375
configFilePath: conf.get('configFilePath', ''),
7476
onSave: conf.get('onSave', true),
7577
useBundler,

src/rubocop.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class RubocopAutocorrectProvider
1717
try {
1818
const args = [
1919
...getCommandArguments(document.fileName),
20-
'--auto-correct',
20+
config.autocorrectArg, // Default: --auto-correct
2121
];
2222
const options = {
2323
cwd: getCurrentPath(document.uri),

test/configuration.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ vsStub.workspace.getConfiguration = (
1818
const defaultConfig = {
1919
configfilePath: '',
2020
executePath: '',
21+
autocorrectArg: '--auto-correct',
2122
onSave: true,
2223
useBundler: false,
2324
suppressRubocopWarnings: false,
@@ -135,6 +136,12 @@ describe('RubocopConfig', () => {
135136
expect(getConfig()).to.have.property('onSave');
136137
});
137138
});
139+
140+
describe('.autocorrectArg', () => {
141+
it('is set', () => {
142+
expect(getConfig().autocorrectArg).to.eq('--auto-correct');
143+
});
144+
});
138145
});
139146
});
140147
});

0 commit comments

Comments
 (0)