3
3
// eslint-disable-next-line import/no-extraneous-dependencies, import/extensions
4
4
import { CompositeDisposable , Range } from 'atom' ;
5
5
import { find , generateRange , exec } from 'atom-linter' ;
6
- import { dirname , join , relative , sep } from 'path' ;
6
+ import { dirname , join , relative , sep , isAbsolute } from 'path' ;
7
7
import { existsSync , readFileSync , readdirSync } from 'fs' ;
8
8
9
9
const tmp = require ( 'tmp' ) ;
@@ -111,6 +111,13 @@ const findTextEditor = (filePath) => {
111
111
return false ;
112
112
} ;
113
113
114
+ const ensureAbsolutePath = ( projectPath , filePath ) => {
115
+ if ( isAbsolute ( filePath ) ) {
116
+ return filePath ;
117
+ }
118
+ return join ( projectPath , filePath ) ;
119
+ } ;
120
+
114
121
const parseError = async ( toParse , sourceFilePath ) => {
115
122
const messages = [ ] ;
116
123
const re = regexp (
@@ -138,7 +145,7 @@ const parseError = async (toParse, sourceFilePath) => {
138
145
let range ;
139
146
if ( reResult [ 2 ] !== undefined ) {
140
147
excerpt = `(${ reResult [ 1 ] } ) ${ reResult [ 2 ] } ` ;
141
- filePath = join ( projectPath , reResult [ 3 ] ) ;
148
+ filePath = ensureAbsolutePath ( projectPath , reResult [ 3 ] ) ;
142
149
const fileEditor = findTextEditor ( filePath ) ;
143
150
if ( fileEditor ) {
144
151
// If there is an open TextEditor instance for the file from the Error,
@@ -151,7 +158,7 @@ const parseError = async (toParse, sourceFilePath) => {
151
158
}
152
159
} else {
153
160
excerpt = `(${ reResult [ 1 ] } ) ${ reResult [ 7 ] } ` ;
154
- filePath = join ( projectPath , reResult [ 5 ] ) ;
161
+ filePath = ensureAbsolutePath ( projectPath , reResult [ 5 ] ) ;
155
162
const fileEditor = findTextEditor ( filePath ) ;
156
163
if ( fileEditor ) {
157
164
range = generateRange ( fileEditor , reResult [ 6 ] - 1 ) ;
@@ -183,7 +190,7 @@ const parseWarning = async (toParse, sourceFilePath) => {
183
190
let reResult = re . exec ( toParse ) ;
184
191
185
192
while ( reResult != null ) {
186
- const filePath = join ( projectPath , reResult [ 2 ] ) ;
193
+ const filePath = ensureAbsolutePath ( projectPath , reResult [ 2 ] ) ;
187
194
try {
188
195
let range ;
189
196
const fileEditor = findTextEditor ( filePath ) ;
@@ -221,7 +228,7 @@ const parseLegacyWarning = async (toParse, sourceFilePath) => {
221
228
const projectPath = await elixirProjectPath ( sourceFilePath ) ;
222
229
let reResult = re . exec ( toParse ) ;
223
230
while ( reResult !== null ) {
224
- const filePath = join ( projectPath , reResult [ 1 ] ) ;
231
+ const filePath = ensureAbsolutePath ( projectPath , reResult [ 1 ] ) ;
225
232
try {
226
233
let range ;
227
234
const fileEditor = findTextEditor ( filePath ) ;
0 commit comments