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

Added "g" flag to project path replacement #291

Merged
merged 5 commits into from
Nov 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/main.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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