File tree 2 files changed +19
-3
lines changed 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ module.exports = {
23
23
'eslint-plugin/report-message-format' : [ 'error' , '^[^a-z].*\\.$' ] ,
24
24
'array-bracket-spacing' : 'off' ,
25
25
'comma-dangle' : 'off' ,
26
+ indent : 'off' ,
26
27
'lines-around-directive' : 'off' ,
27
28
'space-before-function-paren' : 'off'
28
29
}
Original file line number Diff line number Diff line change 6
6
7
7
const util = require ( 'util' ) ;
8
8
const prettier = require ( 'prettier' ) ;
9
- const astUtils = require ( 'eslint/lib/ast-utils' ) ;
10
9
11
10
// ------------------------------------------------------------------------------
12
11
// Rule Definition
@@ -16,6 +15,23 @@ module.exports = {
16
15
create ( context ) {
17
16
const sourceCode = context . getSourceCode ( ) ;
18
17
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
+
19
35
return {
20
36
Program ( ) {
21
37
// This isn't really very performant (prettier needs to reparse the text).
@@ -40,8 +56,7 @@ module.exports = {
40
56
: sourceCode . text [ firstBadIndex ] ;
41
57
42
58
context . report ( {
43
- loc : astUtils . getLocationFromRangeIndex (
44
- sourceCode ,
59
+ loc : getLocation (
45
60
firstBadIndex === - 1 ? desiredText . length : firstBadIndex
46
61
) ,
47
62
message : 'Follow `prettier` formatting (expected {{expectedChar}} but found {{foundChar}}).' ,
You can’t perform that action at this time.
0 commit comments