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

Commit fd2d82c

Browse files
Merge pull request #92 from mauricerkelly/fix-absolute-relative-path-issues
Fix absolute vs relative path issues
2 parents f1b6212 + 4f8db7e commit fd2d82c

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');
@@ -111,6 +111,13 @@ const findTextEditor = (filePath) => {
111111
return false;
112112
};
113113

114+
const ensureAbsolutePath = (projectPath, filePath) => {
115+
if (isAbsolute(filePath)) {
116+
return filePath;
117+
}
118+
return join(projectPath, filePath);
119+
};
120+
114121
const parseError = async (toParse, sourceFilePath) => {
115122
const messages = [];
116123
const re = regexp(
@@ -138,7 +145,7 @@ const parseError = async (toParse, sourceFilePath) => {
138145
let range;
139146
if (reResult[2] !== undefined) {
140147
excerpt = `(${reResult[1]}) ${reResult[2]}`;
141-
filePath = join(projectPath, reResult[3]);
148+
filePath = ensureAbsolutePath(projectPath, reResult[3]);
142149
const fileEditor = findTextEditor(filePath);
143150
if (fileEditor) {
144151
// If there is an open TextEditor instance for the file from the Error,
@@ -151,7 +158,7 @@ const parseError = async (toParse, sourceFilePath) => {
151158
}
152159
} else {
153160
excerpt = `(${reResult[1]}) ${reResult[7]}`;
154-
filePath = join(projectPath, reResult[5]);
161+
filePath = ensureAbsolutePath(projectPath, reResult[5]);
155162
const fileEditor = findTextEditor(filePath);
156163
if (fileEditor) {
157164
range = generateRange(fileEditor, reResult[6] - 1);
@@ -183,7 +190,7 @@ const parseWarning = async (toParse, sourceFilePath) => {
183190
let reResult = re.exec(toParse);
184191

185192
while (reResult != null) {
186-
const filePath = join(projectPath, reResult[2]);
193+
const filePath = ensureAbsolutePath(projectPath, reResult[2]);
187194
try {
188195
let range;
189196
const fileEditor = findTextEditor(filePath);
@@ -221,7 +228,7 @@ const parseLegacyWarning = async (toParse, sourceFilePath) => {
221228
const projectPath = await elixirProjectPath(sourceFilePath);
222229
let reResult = re.exec(toParse);
223230
while (reResult !== null) {
224-
const filePath = join(projectPath, reResult[1]);
231+
const filePath = ensureAbsolutePath(projectPath, reResult[1]);
225232
try {
226233
let range;
227234
const fileEditor = findTextEditor(filePath);

0 commit comments

Comments
 (0)