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

Commit

Permalink
Added "g" flag to project path replacement (#291)
Browse files Browse the repository at this point in the history
* Added "g"

* Added test
  • Loading branch information
hiroaki-yamamoto authored and Arcanemagus committed Nov 30, 2016
1 parent 2a4c05a commit d9644fb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/main.js
Expand Up @@ -65,8 +65,8 @@ const extractRange = ({ code, message, lineNumber, colNumber, textEditor }) => {
const applySubstitutions = (givenExecPath, projDir) => {
let execPath = givenExecPath;
const projectName = path.basename(projDir);
execPath = execPath.replace(/\$PROJECT_NAME/i, projectName);
execPath = execPath.replace(/\$PROJECT/i, projDir);
execPath = execPath.replace(/\$PROJECT_NAME/ig, projectName);
execPath = execPath.replace(/\$PROJECT/ig, projDir);
const paths = execPath.split(';');
for (let i = 0; i < paths.length; i += 1) {
if (fs.existsSync(paths[i])) {
Expand Down
36 changes: 36 additions & 0 deletions spec/linter-flake8-spec.js
Expand Up @@ -200,6 +200,21 @@ describe('The flake8 provider for Linter', () => {
);
});

it('finds executable relative to projects', () => {
const paths = [
path.join('$project', 'null'),
path.join('$pRoJeCt', 'flake1'),
path.join('$PrOjEcT', 'flake2'),
path.join('$PROJECT', 'flake8'),
].join(';');
atom.config.set('linter-flake8.executablePath', paths);
waitsForPromise(() =>
lint(editor).then(() =>
expect(execParams.pop()[0]).toBe(path.join(fixturePath, 'flake8')),
),
);
});

it('finds executable using project name', () => {
atom.config.set('linter-flake8.executablePath',
path.join('$PROJECT_NAME', 'flake8'),
Expand All @@ -211,6 +226,27 @@ describe('The flake8 provider for Linter', () => {
);
});

it('finds executable using project names', () => {
const paths = [
path.join('$project_name', 'null'),
path.join('$pRoJeCt_NaMe', 'flake1'),
path.join('$PrOjEcT_nAmE', 'flake2'),
path.join('$PROJECT_NAME', 'flake8'),
].join(';');
const correct = [
path.join('fixtures', 'null'),
path.join('fixtures', 'flake1'),
path.join('fixtures', 'flake2'),
path.join('fixtures', 'flake8'),
].join(';');
atom.config.set('linter-flake8.executablePath', paths);
waitsForPromise(() =>
lint(editor).then(() =>
expect(execParams.pop()[0]).toBe(correct),
),
);
});

it('normalizes executable path', () => {
atom.config.set('linter-flake8.executablePath',
path.join(fixturePath, '..', 'fixtures', 'flake8'),
Expand Down

0 comments on commit d9644fb

Please sign in to comment.