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

Commit d9644fb

Browse files
hiroaki-yamamotoArcanemagus
authored andcommitted
Added "g" flag to project path replacement (#291)
* Added "g" * Added test
1 parent 2a4c05a commit d9644fb

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

lib/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ const extractRange = ({ code, message, lineNumber, colNumber, textEditor }) => {
6565
const applySubstitutions = (givenExecPath, projDir) => {
6666
let execPath = givenExecPath;
6767
const projectName = path.basename(projDir);
68-
execPath = execPath.replace(/\$PROJECT_NAME/i, projectName);
69-
execPath = execPath.replace(/\$PROJECT/i, projDir);
68+
execPath = execPath.replace(/\$PROJECT_NAME/ig, projectName);
69+
execPath = execPath.replace(/\$PROJECT/ig, projDir);
7070
const paths = execPath.split(';');
7171
for (let i = 0; i < paths.length; i += 1) {
7272
if (fs.existsSync(paths[i])) {

spec/linter-flake8-spec.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,21 @@ describe('The flake8 provider for Linter', () => {
200200
);
201201
});
202202

203+
it('finds executable relative to projects', () => {
204+
const paths = [
205+
path.join('$project', 'null'),
206+
path.join('$pRoJeCt', 'flake1'),
207+
path.join('$PrOjEcT', 'flake2'),
208+
path.join('$PROJECT', 'flake8'),
209+
].join(';');
210+
atom.config.set('linter-flake8.executablePath', paths);
211+
waitsForPromise(() =>
212+
lint(editor).then(() =>
213+
expect(execParams.pop()[0]).toBe(path.join(fixturePath, 'flake8')),
214+
),
215+
);
216+
});
217+
203218
it('finds executable using project name', () => {
204219
atom.config.set('linter-flake8.executablePath',
205220
path.join('$PROJECT_NAME', 'flake8'),
@@ -211,6 +226,27 @@ describe('The flake8 provider for Linter', () => {
211226
);
212227
});
213228

229+
it('finds executable using project names', () => {
230+
const paths = [
231+
path.join('$project_name', 'null'),
232+
path.join('$pRoJeCt_NaMe', 'flake1'),
233+
path.join('$PrOjEcT_nAmE', 'flake2'),
234+
path.join('$PROJECT_NAME', 'flake8'),
235+
].join(';');
236+
const correct = [
237+
path.join('fixtures', 'null'),
238+
path.join('fixtures', 'flake1'),
239+
path.join('fixtures', 'flake2'),
240+
path.join('fixtures', 'flake8'),
241+
].join(';');
242+
atom.config.set('linter-flake8.executablePath', paths);
243+
waitsForPromise(() =>
244+
lint(editor).then(() =>
245+
expect(execParams.pop()[0]).toBe(correct),
246+
),
247+
);
248+
});
249+
214250
it('normalizes executable path', () => {
215251
atom.config.set('linter-flake8.executablePath',
216252
path.join(fixturePath, '..', 'fixtures', 'flake8'),

0 commit comments

Comments
 (0)