This repository has been archived by the owner on Jun 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
… approach instead of the token jumper (#21) - algorithm which detects declarations even better due to the newly implemented node scanning logic - multiple node detections make the implementation of an autofixer possible
- Loading branch information
Showing
11 changed files
with
849 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* This file is part of the Sententiaregum project. | ||
* | ||
* (c) Maximilian Bosch <[email protected]> | ||
* (c) Ben Bieler <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
function bigger(a, b) { | ||
return a > b ? a : b; | ||
} | ||
|
||
module.exports = { | ||
computeAppropriateColumn: function (items, context, wrongColumnHandler) { | ||
var source = context.getSourceCode(); | ||
var result = items.reduce(function (prev, cur) { | ||
var curCol = cur.loc.start.column; | ||
if (Math.abs(source.getTokenBefore(cur).loc.end.column - curCol) > 1) { | ||
return prev; | ||
} | ||
return bigger(prev, curCol); | ||
}, null); | ||
|
||
if (null === result) { | ||
wrongColumnHandler(); | ||
return; | ||
} | ||
|
||
return result; | ||
}, | ||
computeActualColumn: function (items, source) { | ||
return items.reduce(function (prev, cur) { | ||
var col = source.getTokenBefore(cur).loc.end.column + 1; | ||
return bigger(prev, col); | ||
}, 0); | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* This file is part of the Sententiaregum project. | ||
* | ||
* (c) Maximilian Bosch <[email protected]> | ||
* (c) Ben Bieler <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var columnComputation = require('./columnComputation'); | ||
|
||
function repeat(val, times) { | ||
var buffer = ''; | ||
for (var i = 0; i < times; i++) { | ||
buffer += val; | ||
} | ||
|
||
return buffer; | ||
} | ||
|
||
function removeAlignmentRange(source, punctuator, fixer, column) { | ||
var before = source.getTokenBefore(punctuator); | ||
return fixer.removeRange([ | ||
before.range[1] + (column - before.loc.end.column), | ||
punctuator.range[0] | ||
]); | ||
} | ||
|
||
module.exports = { | ||
getWrongAlignmentFixer: function (column, cur, punctuator, source) { | ||
return function(fixer) { | ||
if (column > cur) { | ||
return fixer.insertTextBefore(punctuator, repeat(' ', column - cur)); | ||
} | ||
return removeAlignmentRange(source, punctuator, fixer, column); | ||
}; | ||
}, | ||
getWrongColumnHandler: function(items, source, context) { | ||
return function () { | ||
var actual = columnComputation.computeActualColumn(items, source); | ||
items.forEach(function (token) { | ||
context.report({ | ||
message: 'The punctuator column must be placed directly after the longest variable!', | ||
node: token, | ||
fix: function (fixer) { | ||
return removeAlignmentRange(context.getSourceCode(), token, fixer, actual); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.