@@ -9,16 +9,6 @@ const MAX_AUTOFIX_PASSES = 10;
99const WARNING_SEVERITY = 1 ;
1010const ERROR_SEVERITY = 2 ;
1111
12- /**
13- * @param {Object } options
14- * @param {string } options.source - The source code to fix.
15- * @param {Object[] } messages - The lint messages.
16- * @returns {string } output - The fixed source.
17- */
18- function applyFixes ( options /* messages */ ) {
19- return options . source ;
20- }
21-
2212function buildErrorMessage ( filePath , moduleId , error ) {
2313 let message = {
2414 fatal : true ,
@@ -225,7 +215,7 @@ class Linter {
225215 shouldVerify = false ;
226216
227217 if ( iterations < MAX_AUTOFIX_PASSES ) {
228- const output = applyFixes ( options , messages ) ;
218+ const output = this . _applyFixes ( options , messages ) ;
229219
230220 // let's lint one more time if source was modified
231221 shouldVerify = output !== currentSource ;
@@ -241,6 +231,43 @@ class Linter {
241231 } ;
242232 }
243233
234+ /**
235+ * @param {Object } options
236+ * @param {string } options.source - The source code to verify.
237+ * @param {string } options.filePath
238+ * @param {string } options.moduleId
239+ * @param {Object[] } results - The lint messages.
240+ *
241+ * @returns {string } output - The fixed source.
242+ */
243+ _applyFixes ( options , results ) {
244+ let fixableIssues = results . filter ( r => r . isFixable ) ;
245+
246+ // nothing to do, bail out
247+ if ( fixableIssues . length === 0 ) {
248+ return options . source ;
249+ }
250+
251+ let currentSource = options . source ;
252+
253+ let pending = this . statusForModule ( 'pending' , options . moduleId ) ;
254+ let ruleNames = new Set ( fixableIssues . map ( r => r . rule ) ) ;
255+ for ( let ruleName of ruleNames ) {
256+ let rule = this . _buildRule ( ruleName , {
257+ pending,
258+ shouldFix : true ,
259+ filePath : options . filePath ,
260+ rawSource : currentSource ,
261+ fileConfig : getConfigForFile ( this . config , options . filePath ) ,
262+ } ) ;
263+
264+ let { code } = transform ( currentSource , ( ) => rule . getVisitor ( ) ) ;
265+ currentSource = code ;
266+ }
267+
268+ return currentSource ;
269+ }
270+
244271 /**
245272 * The main function for the Linter class. It takes the source code to lint
246273 * and returns the results.
0 commit comments