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' ) ;
@@ -109,6 +109,13 @@ const findTextEditor = (filePath) => {
109
109
return false ;
110
110
} ;
111
111
112
+ const ensureAbsolutePath = ( projectPath , filePath ) => {
113
+ if ( isAbsolute ( filePath ) ) {
114
+ return filePath ;
115
+ }
116
+ return join ( projectPath , filePath ) ;
117
+ } ;
118
+
112
119
const parseError = async ( toParse , sourceFilePath ) => {
113
120
const messages = [ ] ;
114
121
const re = regexp (
@@ -136,7 +143,7 @@ const parseError = async (toParse, sourceFilePath) => {
136
143
let range ;
137
144
if ( reResult [ 2 ] !== undefined ) {
138
145
excerpt = `(${ reResult [ 1 ] } ) ${ reResult [ 2 ] } ` ;
139
- filePath = join ( projectPath , reResult [ 3 ] ) ;
146
+ filePath = ensureAbsolutePath ( projectPath , reResult [ 3 ] ) ;
140
147
const fileEditor = findTextEditor ( filePath ) ;
141
148
if ( fileEditor ) {
142
149
// If there is an open TextEditor instance for the file from the Error,
@@ -149,7 +156,7 @@ const parseError = async (toParse, sourceFilePath) => {
149
156
}
150
157
} else {
151
158
excerpt = `(${ reResult [ 1 ] } ) ${ reResult [ 7 ] } ` ;
152
- filePath = join ( projectPath , reResult [ 5 ] ) ;
159
+ filePath = ensureAbsolutePath ( projectPath , reResult [ 5 ] ) ;
153
160
const fileEditor = findTextEditor ( filePath ) ;
154
161
if ( fileEditor ) {
155
162
range = generateRange ( fileEditor , reResult [ 6 ] - 1 ) ;
@@ -181,7 +188,7 @@ const parseWarning = async (toParse, sourceFilePath) => {
181
188
let reResult = re . exec ( toParse ) ;
182
189
183
190
while ( reResult != null ) {
184
- const filePath = join ( projectPath , reResult [ 2 ] ) ;
191
+ const filePath = ensureAbsolutePath ( projectPath , reResult [ 2 ] ) ;
185
192
try {
186
193
let range ;
187
194
const fileEditor = findTextEditor ( filePath ) ;
@@ -219,7 +226,7 @@ const parseLegacyWarning = async (toParse, sourceFilePath) => {
219
226
const projectPath = await elixirProjectPath ( sourceFilePath ) ;
220
227
let reResult = re . exec ( toParse ) ;
221
228
while ( reResult !== null ) {
222
- const filePath = join ( projectPath , reResult [ 1 ] ) ;
229
+ const filePath = ensureAbsolutePath ( projectPath , reResult [ 1 ] ) ;
223
230
try {
224
231
let range ;
225
232
const fileEditor = findTextEditor ( filePath ) ;
0 commit comments