Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit 4f8db7e

Browse files
committed
Fix absolute vs relative path issues
1 parent c667118 commit 4f8db7e

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/init.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// eslint-disable-next-line import/no-extraneous-dependencies, import/extensions
44
import { CompositeDisposable, Range } from 'atom';
55
import { find, generateRange, exec } from 'atom-linter';
6-
import { dirname, join, relative, sep } from 'path';
6+
import { dirname, join, relative, sep, isAbsolute } from 'path';
77
import { existsSync, readFileSync, readdirSync } from 'fs';
88

99
const tmp = require('tmp');
@@ -109,6 +109,13 @@ const findTextEditor = (filePath) => {
109109
return false;
110110
};
111111

112+
const ensureAbsolutePath = (projectPath, filePath) => {
113+
if (isAbsolute(filePath)) {
114+
return filePath;
115+
}
116+
return join(projectPath, filePath);
117+
};
118+
112119
const parseError = async (toParse, sourceFilePath) => {
113120
const messages = [];
114121
const re = regexp(
@@ -136,7 +143,7 @@ const parseError = async (toParse, sourceFilePath) => {
136143
let range;
137144
if (reResult[2] !== undefined) {
138145
excerpt = `(${reResult[1]}) ${reResult[2]}`;
139-
filePath = join(projectPath, reResult[3]);
146+
filePath = ensureAbsolutePath(projectPath, reResult[3]);
140147
const fileEditor = findTextEditor(filePath);
141148
if (fileEditor) {
142149
// If there is an open TextEditor instance for the file from the Error,
@@ -149,7 +156,7 @@ const parseError = async (toParse, sourceFilePath) => {
149156
}
150157
} else {
151158
excerpt = `(${reResult[1]}) ${reResult[7]}`;
152-
filePath = join(projectPath, reResult[5]);
159+
filePath = ensureAbsolutePath(projectPath, reResult[5]);
153160
const fileEditor = findTextEditor(filePath);
154161
if (fileEditor) {
155162
range = generateRange(fileEditor, reResult[6] - 1);
@@ -181,7 +188,7 @@ const parseWarning = async (toParse, sourceFilePath) => {
181188
let reResult = re.exec(toParse);
182189

183190
while (reResult != null) {
184-
const filePath = join(projectPath, reResult[2]);
191+
const filePath = ensureAbsolutePath(projectPath, reResult[2]);
185192
try {
186193
let range;
187194
const fileEditor = findTextEditor(filePath);
@@ -219,7 +226,7 @@ const parseLegacyWarning = async (toParse, sourceFilePath) => {
219226
const projectPath = await elixirProjectPath(sourceFilePath);
220227
let reResult = re.exec(toParse);
221228
while (reResult !== null) {
222-
const filePath = join(projectPath, reResult[1]);
229+
const filePath = ensureAbsolutePath(projectPath, reResult[1]);
223230
try {
224231
let range;
225232
const fileEditor = findTextEditor(filePath);

0 commit comments

Comments
 (0)