File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ module.exports = {
2323 'eslint-plugin/report-message-format' : [ 'error' , '^[^a-z].*\\.$' ] ,
2424 'array-bracket-spacing' : 'off' ,
2525 'comma-dangle' : 'off' ,
26+ indent : 'off' ,
2627 'lines-around-directive' : 'off' ,
2728 'space-before-function-paren' : 'off'
2829 }
Original file line number Diff line number Diff line change 66
77const util = require ( 'util' ) ;
88const prettier = require ( 'prettier' ) ;
9- const astUtils = require ( 'eslint/lib/ast-utils' ) ;
109
1110// ------------------------------------------------------------------------------
1211// Rule Definition
@@ -16,6 +15,23 @@ module.exports = {
1615 create ( context ) {
1716 const sourceCode = context . getSourceCode ( ) ;
1817
18+ /**
19+ * Gets the location of a given index in the source code
20+ * @param {number } index An index in the source code
21+ * @returns {object } An object containing numberic `line` and `column` keys
22+ */
23+ function getLocation ( index ) {
24+ // If sourceCode.getLocFromIndex is available from eslint, use it.
25+ // Otherwise, use the private version from eslint/lib/ast-utils.
26+
27+ return sourceCode . getLocFromIndex
28+ ? sourceCode . getLocFromIndex ( index )
29+ : require ( 'eslint/lib/ast-utils' ) . getLocationFromRangeIndex (
30+ sourceCode ,
31+ index
32+ ) ;
33+ }
34+
1935 return {
2036 Program ( ) {
2137 // This isn't really very performant (prettier needs to reparse the text).
@@ -40,8 +56,7 @@ module.exports = {
4056 : sourceCode . text [ firstBadIndex ] ;
4157
4258 context . report ( {
43- loc : astUtils . getLocationFromRangeIndex (
44- sourceCode ,
59+ loc : getLocation (
4560 firstBadIndex === - 1 ? desiredText . length : firstBadIndex
4661 ) ,
4762 message : 'Follow `prettier` formatting (expected {{expectedChar}} but found {{foundChar}}).' ,
You can’t perform that action at this time.
0 commit comments